FileDocCategorySizeDatePackage
JspNameMangler.javaAPI DocApache Ant 1.705194Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.jsp

JspNameMangler

public class JspNameMangler extends Object implements JspMangler
This is a class derived from the Jasper code (org.apache.jasper.compiler.CommandLineCompiler) to map from a JSP filename to a valid Java classname.

Fields Summary
public static final String[]
keywords
this is the list of keywords which can not be used as classnames
Constructors Summary
Methods Summary
private static java.lang.StringmangleChar(char ch)
definition of the char escaping algorithm

param
ch char to mangle
return
mangled string; 5 digit hex value


        if (ch == File.separatorChar) {
            ch = '/";
        }
        String s = Integer.toHexString(ch);
        int nzeros = 5 - s.length();
        char[] result = new char[6];
        result[0] = '_";
        for (int i = 1; i <= nzeros; ++i) {
            result[i] = '0";
        }
        int resultIndex = 0;
        for (int i = nzeros + 1; i < 6; ++i) {
            result[i] = s.charAt(resultIndex++);
        }
        return new String(result);
    
private java.lang.StringmapJspToBaseName(java.io.File jspFile)
map from a jsp file to a base name; does not deal with extensions

param
jspFile jspFile file
return
exensionless potentially remapped name

        String className;
        className = stripExtension(jspFile);

        // since we don't mangle extensions like the servlet does,
        // we need to check for keywords as class names
        for (int i = 0; i < keywords.length; ++i) {
            if (className.equals(keywords[i])) {
                className += "%";
                break;
            }
        }

        // Fix for invalid characters. If you think of more add to the list.
        StringBuffer modifiedClassName = new StringBuffer(className.length());
        // first char is more restrictive than the rest
        char firstChar = className.charAt(0);
        if (Character.isJavaIdentifierStart(firstChar)) {
            modifiedClassName.append(firstChar);
        } else {
            modifiedClassName.append(mangleChar(firstChar));
        }
        // this is the rest
        for (int i = 1; i < className.length(); i++) {
            char subChar = className.charAt(i);
            if (Character.isJavaIdentifierPart(subChar)) {
                modifiedClassName.append(subChar);
            } else {
                modifiedClassName.append(mangleChar(subChar));
            }
        }
        return modifiedClassName.toString();
    
public java.lang.StringmapJspToJavaName(java.io.File jspFile)
map from a jsp file to a java filename; does not do packages

param
jspFile file
return
java filename


    // CheckStyle:ConstantNameCheck ON

                            
        
        return mapJspToBaseName(jspFile) + ".java";
    
public java.lang.StringmapPath(java.lang.String path)
taking in the substring representing the path relative to the source dir return a new string representing the destination path not supported, as jasper in tomcat4.0 doesnt either

param
path not used
return
null always.

        return null;
    
private java.lang.StringstripExtension(java.io.File jspFile)
get short filename from file

param
jspFile file in
return
file without any jsp extension

        String className;
        String filename = jspFile.getName();
        if (filename.endsWith(".jsp")) {
            className = filename.substring(0, filename.length() - 4);
        } else {
            className = filename;
        }
        return className;