You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by gl...@apache.org on 2001/02/04 02:05:02 UTC

cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler JspCompiler.java

glenn       01/02/03 17:05:02

  Modified:    jasper/src/share/org/apache/jasper/compiler JspCompiler.java
  Log:
  - Implemented Java SecurityManager
  - Switched to using URLClassLoader
  
  Jasper now creates a URLClassLoader for each JSP page and defers any other
  class loading to the web app context class loader.  Using a single class
  loader per JSP allowed me to remove all the code that increments the
  class version number, i.e. the work directory no longer has multiple
  *.java and *.class files for the same JSP page.  These changes also made
  it easy for me to put the java source and class files in the same directory
  tree as found in the web app context.  When Jasper is run in a servlet
  container it no longer puts the class files in a package, they are now
  in the default package.
  
  Revision  Changes    Path
  1.3       +6 -150    jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspCompiler.java
  
  Index: JspCompiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspCompiler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JspCompiler.java	2001/01/05 22:33:02	1.2
  +++ JspCompiler.java	2001/02/04 01:05:02	1.3
  @@ -78,7 +78,7 @@
    */
   public class JspCompiler extends Compiler implements Mangler {
       
  -    String pkgName, javaFileName, classFileName;
  +    String javaFileName, classFileName;
       String realClassName;
   
       File jsp;
  @@ -86,7 +86,6 @@
   
       //    ClassFileData cfd;
       boolean outDated;
  -    static final int JSP_TOKEN_LEN= Constants.JSP_TOKEN.length();
   
       Logger.Helper loghelper = new Logger.Helper("JASPER_LOG", "JspCompiler");
       
  @@ -97,71 +96,12 @@
           this.outputDir = ctxt.getOutputDir();
           this.outDated = false;
           setMangler(this);
  -
  -	// If the .class file exists and is outdated, compute a new
  -	// class name
  -	if( isOutDated() ) {
  -	    generateNewClassName();
  -	}
       }
   
  -    private void generateNewClassName() {
  -	File classFile = new File(getClassFileName());
  -	if (! classFile.exists()) {
  -	     String prefix = getPrefix(jsp.getPath());
  -	     realClassName= prefix + getBaseClassName() +
  -		 Constants.JSP_TOKEN + "0";
  -	    return;
  -	} 
  -
  -	String cn=getRealClassName();
  -	String baseClassName = cn.
  -	    substring(0, cn.lastIndexOf(Constants.JSP_TOKEN));
  -	int jspTokenIdx=cn.lastIndexOf(Constants.JSP_TOKEN);
  -	String versionS=cn.substring(jspTokenIdx + JSP_TOKEN_LEN,
  -				     cn.length());
  -	int number= Integer.valueOf(versionS).intValue();
  -	number++;
  -	realClassName = baseClassName + Constants.JSP_TOKEN + number;
  -    }
  -    
  -    /** Return the real class name for the JSP, including package and
  -     *   version.
  -     *
  -     *  This method is called when the server is started and a .class file
  -     *  is found from a previous compile or when the .class file is older,
  -     *  to find next version.
  -     */
  -    public final String getRealClassName() {
  -	if( realClassName!=null ) return realClassName;
  -
  -	// 	loghelper.log("JspCompiler: extract class name and version ",
  -	//                    null, Logger.DEBUG);
  -        try {
  -            realClassName = ClassName.getClassName( getClassFileName() );
  -        } catch( JasperException ex) {
  -            // ops, getClassName should throw something
  -	    loghelper.log("Exception in getRealClassName", ex);
  -	    return null;
  -        }
  -	return realClassName;
  -
  -    }
  -    
       public final String getClassName() {
  -        // CFD gives you the whole class name
  -        // This method returns just the class name sans the package
  -
  -	String cn=getRealClassName();
  -        int lastDot = cn.lastIndexOf('.');
  -	String className=null;
  -        if (lastDot != -1) 
  -            className = cn.substring(lastDot+1,
  -                                     cn.length());
  -        else // no package name case
  -            className = cn;
  -
  -        return className;
  +	if( realClassName == null )
  +	    realClassName = getBaseClassName();
  +        return realClassName;
       }
   
       public final String getJavaFileName() {
  @@ -175,81 +115,12 @@
       public final String getClassFileName() {
           if( classFileName!=null) return classFileName;
   
  -	//        computeClassFileName();
  -        String prefix = getPrefix(jsp.getPath());
  -        classFileName = prefix + getBaseClassName() + ".class";
  +        classFileName = getClassName() + ".class";
   	if (outputDir != null && !outputDir.equals(""))
   	    classFileName = outputDir + File.separatorChar + classFileName;
   	return classFileName;
       }
   
  -    
  -    public static String [] keywords = { 
  -        "abstract", "boolean", "break", "byte",
  -        "case", "catch", "char", "class",
  -        "const", "continue", "default", "do",
  -        "double", "else", "extends", "final",
  -        "finally", "float", "for", "goto",
  -        "if", "implements", "import",
  -        "instanceof", "int", "interface",
  -        "long", "native", "new", "package",
  -        "private", "protected", "public",
  -        "return", "short", "static", "super",
  -        "switch", "synchronized", "this",
  -        "throw", "throws", "transient", 
  -        "try", "void", "volatile", "while" 
  -    };
  -
  -    public final String getPackageName() {
  -        if( pkgName!=null) return pkgName;
  -
  -	// compute package name 
  -	String pathName = jsp.getPath();
  -	StringBuffer modifiedpkgName = new StringBuffer ();
  -        int indexOfSepChar = pathName.lastIndexOf(File.separatorChar);
  -        
  -	if (indexOfSepChar == -1 || indexOfSepChar == 0)
  -	    pkgName = null;
  -	else {
  -	    for (int i = 0; i < keywords.length; i++) {
  -		char fs = File.separatorChar;
  -		int index1 = pathName.indexOf(fs + keywords[i]);
  -		int index2 = pathName.indexOf(keywords[i]);
  -		if (index1 == -1 && index2 == -1) continue;
  -		int index = (index2 == -1) ? index1 : index2;
  -		while (index != -1) {
  -		    String tmpathName = pathName.substring (0,index+1) + '%';
  -		    pathName = tmpathName + pathName.substring (index+2);
  -		    index = pathName.indexOf(fs + keywords[i]);
  -		}
  -	    }
  -	    
  -	    // XXX fix for paths containing '.'.
  -	    // Need to be more elegant here.
  -            pathName = pathName.replace('.','_');
  -	    
  -	    pkgName = pathName.substring(0, pathName.lastIndexOf(
  -	    		File.separatorChar)).replace(File.separatorChar, '.');
  -	    for (int i=0; i<pkgName.length(); i++) 
  -		if (Character.isLetter(pkgName.charAt(i)) == true ||
  -		    pkgName.charAt(i) == '.') {
  -		    modifiedpkgName.append(pkgName.substring(i,i+1));
  -		}
  -		else
  -		    modifiedpkgName.append(mangleChar(pkgName.charAt(i)));
  -
  -	    if (modifiedpkgName.charAt(0) == '.') {
  -                String modifiedpkgNameString = modifiedpkgName.toString();
  -                pkgName = modifiedpkgNameString.
  -		    substring(1, 
  -			      modifiedpkgName.length ());
  -            }
  -	    else 
  -	        pkgName = modifiedpkgName.toString();
  -	}
  -	return pkgName;
  -    }
  -
       private final String getBaseClassName() {
   	String className;
           
  @@ -267,23 +138,8 @@
   	    else
   		modifiedClassName.append(mangleChar(className.charAt(i)));
   	}
  -	
  +	modifiedClassName.append("_jsp");
   	return modifiedClassName.toString();
  -    }
  -
  -    private final String getPrefix(String pathName) {
  -	if (pathName != null) {
  -	    StringBuffer modifiedName = new StringBuffer();
  -	    for (int i = 0; i < pathName.length(); i++) {
  -		if (Character.isLetter(pathName.charAt(i)) == true)
  -		    modifiedName.append(pathName.substring(i,i+1));
  -		else
  -		    modifiedName.append(mangleChar(pathName.charAt(i)));
  - 	    }
  -	    return modifiedName.toString();
  -	}
  -	else 
  -            return "";
       }
   
       private static final String mangleChar(char ch) {