tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler ParserController.java
Date Fri, 13 Oct 2000 19:57:17 GMT
pierred     00/10/13 12:57:16

  Modified:    jasper/src/share/org/apache/jasper/compiler
                        ParserController.java
  Log:
  Fix for bug report #258.
  Relative paths in include directives were not handled properly.
  (tomcat3.2 does *not* have that bug)
  
  Revision  Changes    Path
  1.6       +28 -30    jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserController.java
  
  Index: ParserController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserController.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParserController.java	2000/10/12 23:34:12	1.5
  +++ ParserController.java	2000/10/13 19:57:16	1.6
  @@ -89,12 +89,10 @@
       private JspCompilationContext ctxt;
   
       /*
  -     * The filename and path of the file being currently parsed.
  -     * This is used to define the path to a file that may
  -     * be included by that 'parent' file.
  +     * A stack to keep track of the 'current base directory'
  +     * for include directives that refer to relative paths.
        */
  -    private String currentFilePath = null;
  -    private String currentFileName = null;
  +    private Stack baseDirStack = new Stack();
   
       /*
        * The parse 'event handler', shared by both
  @@ -173,7 +171,7 @@
   	throws FileNotFoundException, JasperException
       {
           //p("parse(" + inFileName + ", " + encoding + ")");
  -        resolveFileName(inFileName);
  +        String absFileName = resolveFileName(inFileName);
   
           if (encoding == null) {
               encoding = "8859_1"; // default per JSP spec
  @@ -185,16 +183,16 @@
   	// @@@ need to do a pass at JSP doc to find encoding as specified
   	// @@@ in page directive (see JspParseEventListener)
   
  -        File file = new File(currentFileName);
  -	currentFilePath = (ctxt == null) 
  +        File file = new File(absFileName);
  +	String filePath = (ctxt == null) 
   	    ? file.getAbsolutePath()
   	    : ctxt.getRealPath(file.toString());
  -	//p("currentFilePath: " + currentFilePath);
  +	//p("filePath: " + filePath);
   
           InputStreamReader reader = null;
           try {
               // Figure out what type of JSP document we are dealing with
  -            reader = getReader(file, encoding);
  +            reader = getReader(file, encoding, absFileName);
               figureOutJspDocument(file, encoding, reader);
               //p("isXml = " + isXml + "   hasTaglib = " + hasTaglib);
   
  @@ -202,12 +200,13 @@
   	    try {
   		reader.close();
   	    } catch (IOException ex) {}
  -            reader = getReader(file, encoding);
  +            reader = getReader(file, encoding, absFileName);
               if (isXml) {
  -                (new ParserXJspSax(currentFilePath, reader, jspHandler)).parse();
  +                (new ParserXJspSax(filePath, reader, jspHandler)).parse();
               } else {
                   (new Parser(ctxt, file, encoding, reader, jspHandler)).parse();
               }
  +	    baseDirStack.pop();
           } finally {
               if (reader != null) {
                   try {
  @@ -374,27 +373,26 @@
       // Utility methods
   
       /*
  -     * Resolve the name of the file and update global
  -     * 'parentFileName' so we can properly include
  -     * other jsp pages that are relative to this one.
  +     * Resolve the name of the file and update
  +     * baseDirStack() to keep track ot the current
  +     * base directory for each included file.
  +     * The 'root' file is always an 'absolute' path,
  +     * so no need to put an initial value in the
  +     * baseDirStack.
        */
  -    private void resolveFileName(String inFileName) {
  -        String baseDir = (currentFileName == null)
  -	    ? null
  -	    : currentFileName.substring(
  -        0, currentFileName.lastIndexOf("/") + 1);
  -        //@@@ if no '/', would fail???
  +    private String resolveFileName(String inFileName) {
           boolean isAbsolute = inFileName.startsWith("/");
  -
  -        if (baseDir == null || isAbsolute) {
  -            currentFileName = inFileName;
  -        } else {
  -            currentFileName = baseDir + inFileName;
  -        }
  -	//p("resolveFileName() currentFileName: " + currentFileName);
  +	String fileName = 
  +	    isAbsolute ?
  +	    inFileName : (String)baseDirStack.peek() + inFileName;
  +	String baseDir = 
  +	    inFileName.substring(0, inFileName.lastIndexOf("/") + 1);
  +	baseDirStack.push(baseDir);
  +	return fileName;
       }
   
  -    private InputStreamReader getReader(File file, String encoding)
  +    private InputStreamReader getReader(File file, String encoding,
  +					String absFileName)
   	throws FileNotFoundException, JasperException
       {
           InputStream in;
  @@ -408,7 +406,7 @@
   		//String fileName = ctxt.getRealPath(file.toString());
   		in = ctxt.getResourceAsStream(file.toString());
   		if (in == null) {
  -		    throw new FileNotFoundException(currentFileName);
  +		    throw new FileNotFoundException(absFileName);
   		}
   		reader = new InputStreamReader(in, encoding);
   	    }
  
  
  

Mime
View raw message