You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pi...@locus.apache.org on 2000/09/19 21:27:27 UTC

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

pierred     00/09/19 12:27:27

  Modified:    jasper/src/share/org/apache/jasper/compiler JspReader.java
  Log:
  Support for XML syntax:
    - new constructor (now JspReader is created by ParserController)
    - supports 'single file' mode (to easily reuse the reader
      when figuring out the content of a file)
    - changed the logic of 'pushFile()/popFile()' since the input documents
      may now be of various syntax, and handled by different parsers.
    - logic of resolving filename has been moved to parser controller
      so it can be shared among all parsers
  
  Revision  Changes    Path
  1.2       +70 -0     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspReader.java
  
  Index: JspReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspReader.java	2000/08/12 00:52:08	1.1
  +++ JspReader.java	2000/09/19 19:27:27	1.2
  @@ -93,6 +93,12 @@
       
       private JspCompilationContext context;
   
  +    /*
  +    * Set to true when using the JspReader on a single file where we read up to the
  +    * end and reset to the beginning many times. (as in ParserCtl.figureOutJspDocument().
  +    */
  +    boolean singleFile = false;
  +
       Logger.Helper loghelper = new Logger.Helper("JASPER_LOG", "JspReader");
       
       public String getFile(int fileid) {
  @@ -134,6 +140,7 @@
        * @param name The name of the file.
        * @param encoding The optional encoding for the file.
        */
  +    /* NOT COMPILED -- kept temporarily for reference 
       public void pushFile(String name, String encoding) 
   	throws ParseException, FileNotFoundException
       {
  @@ -149,12 +156,14 @@
   	    pushFile(new File(master), encoding);
   	}
       }
  +    */
   
       /**
        * Push a new file to be parsed onto the stack.
        * @param inputFile The fully qualified path of the file.
        * @param encoding Optional encoding to read the file.
        */
  +    /* NOT COMPILED -- kept temporarily for reference 
       private void pushFile(File file, String encoding) 
   	throws ParseException, FileNotFoundException 
       {
  @@ -225,7 +234,51 @@
   	    }
   	}
       }
  +    */
   
  +    private void pushFile2(File file, String encoding, 
  +			   InputStreamReader reader) 
  +	throws ParseException, FileNotFoundException 
  +    {
  +	// Register the file
  +	String longName = (context == null)
  +	    ? file.getAbsolutePath()
  +	    : context.getRealPath(file.toString());
  +
  +	int fileid = registerSourceFile(longName);
  +
  +        if (fileid == -1)
  +            throw new ParseException(
  +                Constants.getString("jsp.error.file.already.registered",
  +				    new Object[] {file}));
  +	currFileId = fileid;
  +
  +	try {
  +	    CharArrayWriter caw   = new CharArrayWriter();
  +	    char            buf[] = new char[1024];
  +	    for (int i = 0 ; (i = reader.read(buf)) != -1 ; )
  +		caw.write(buf, 0, i);
  +	    caw.close();
  +	    if (current == null) {
  +		current = new Mark(this, caw.toCharArray(), fileid, 
  +				   getFile(fileid), master, encoding );
  +	    } else {
  +		current.pushStream( caw.toCharArray(), fileid, getFile(fileid),
  +				    longName, encoding );
  +	    }
  +	} catch (Throwable ex) {
  +	    loghelper.log("Exception parsing file ", ex);
  +	    // Pop state being constructed:
  +	    popFile();
  +	    throw new ParseException(Constants.getString("jsp.error.file.cannot.read",
  +							new Object[] { new String("ze file") }));
  +	} finally {
  +	    if ( reader != null ) {
  +		try { reader.close(); } catch (Exception any) {}
  +	    }
  +	}
  +    }
  +
       public boolean popFile() throws ParseException {
   	// Is stack created ? (will happen if the Jsp file we'r looking at is
   	// missing.
  @@ -247,6 +300,16 @@
   	return (result);
       }
   	
  +    protected JspReader(JspCompilationContext ctx,
  +			File file,
  +			String encoding, InputStreamReader reader) 
  +	throws ParseException, FileNotFoundException
  +    {
  +        this.context = ctx;
  +	pushFile2(file, encoding, reader);
  +    }
  +
  +    /* NOT COMPILED -- kept temporarily for reference 
       protected JspReader(String file, JspCompilationContext ctx, String encoding) 
   	throws ParseException, FileNotFoundException
       {
  @@ -259,9 +322,11 @@
       {
   	return new JspReader(file, ctx, encoding);
       }
  +    */
   
       public boolean hasMoreInput() throws ParseException {
   	if (current.cursor >= current.stream.length) {
  +            if (singleFile) return false; 
   	    while (popFile()) {
   		if (current.cursor < current.stream.length) return true;
   	    }
  @@ -717,5 +782,10 @@
   	    return true;
   	}
       }
  +
  +    public void setSingleFile(boolean val) {
  +        singleFile = val;
  +    }
  +
   }