tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler JspDocumentParser.java Node.java SmapUtil.java
Date Tue, 22 Oct 2002 03:00:20 GMT
luehe       2002/10/21 20:00:20

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        JspDocumentParser.java Node.java SmapUtil.java
  Log:
  Added support for prelude and coda to JSP documents
  
  Revision  Changes    Path
  1.20      +79 -31    jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
  
  Index: JspDocumentParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- JspDocumentParser.java	17 Oct 2002 20:43:06 -0000	1.19
  +++ JspDocumentParser.java	22 Oct 2002 03:00:20 -0000	1.20
  @@ -61,7 +61,7 @@
   package org.apache.jasper.compiler;
   
   import java.io.*;
  -import java.util.Hashtable;
  +import java.util.*;
   import javax.servlet.jsp.tagext.*;
   import javax.xml.parsers.SAXParserFactory;
   import javax.xml.parsers.ParserConfigurationException;
  @@ -92,19 +92,26 @@
   
       private ParserController parserController;
       private JspCompilationContext ctxt;    
  +    private PageInfo pageInfo;
  +
       // XML document source
       private InputSource inputSource;
  +
       private String path;
  +
       // Node representing the XML element currently being parsed
       private Node current;
  +
       // Document locator
       private Locator locator;
  +
       private Hashtable taglibs;
  +
       // Flag indicating whether we are inside DTD declarations
       private boolean inDTD;
  +
       private ErrorDispatcher err;
       private boolean isTagFile;
  -    private boolean rootSeen;
   
       /*
        * Constructor
  @@ -115,7 +122,8 @@
   			     boolean isTagFile) {
   	this.parserController = pc;
   	this.ctxt = pc.getJspCompilationContext();
  -	this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries();
  +	this.pageInfo = pc.getCompiler().getPageInfo();
  +	this.taglibs = this.pageInfo.getTagLibraries();
   	this.err = pc.getCompiler().getErrorDispatcher();
   	this.path = path;
   	this.inputSource = new InputSource(reader);
  @@ -125,19 +133,32 @@
       /*
        * Parses a JSP document by responding to SAX events.
        *
  -     * @throws JasperException XXX
  +     * @throws JasperException
        */
       public static Node.Nodes parse(ParserController pc,
   				   String path,
   				   InputStreamReader reader,
   				   Node parent,
   				   boolean isTagFile) throws JasperException {
  +
   	JspDocumentParser handler = new JspDocumentParser(pc, path, reader,
   							  isTagFile);
  -	handler.current = parent;
   	Node.Nodes pageNodes = null;
  +	Node.JspRoot jspRoot = null;
   
   	try {
  +	    if (parent == null) {
  +		// create dummy <jsp:root> element
  +		AttributesImpl rootAttrs = new AttributesImpl();
  +		rootAttrs.addAttribute("", "", "version", "CDATA", "2.0");
  +		jspRoot = new Node.JspRoot(rootAttrs, null, null);
  +		handler.current = jspRoot;
  +		handler.addInclude(jspRoot,
  +				   handler.pageInfo.getIncludePrelude());
  +	    } else {
  +		handler.current = parent;
  +	    }
  +
   	    // Use the default (non-validating) parser
   	    SAXParserFactory factory = SAXParserFactory.newInstance();
   
  @@ -151,8 +172,9 @@
   	    saxParser.parse(handler.inputSource, handler);
   
   	    if (parent == null) {
  -		// Add the jsp:root element to the parse result
  -		pageNodes = new Node.Nodes((Node.JspRoot) handler.current);
  +		handler.addInclude(jspRoot, handler.pageInfo.getIncludeCoda());
  +		// Create Node.Nodes from dummy (top-level) <jsp:root>
  +		pageNodes = new Node.Nodes(jspRoot);
   	    } else {
   		pageNodes = parent.getBody();
   	    }
  @@ -179,15 +201,6 @@
   
   	Node node = null;
   
  -	if (!qName.equals(JSP_ROOT) && !rootSeen) {
  -	    // create dummy <jsp:root> element
  -	    AttributesImpl rootAttrs = new AttributesImpl();
  -	    rootAttrs.addAttribute("", "", "version", "CDATA", "2.0");
  -	    node = new Node.JspRoot(rootAttrs, null, current, true);
  -	    current = node;
  -            rootSeen = true;
  -	}
  -
           // XXX - As of JSP 2.0, xmlns: can appear in any node (not just
           // <jsp:root>).  The spec still needs clarification here.
           // What we implement is that it can appear in any node and
  @@ -205,8 +218,7 @@
               // give the <jsp:root> element the original attributes set
               // (attrs) instead of the copy without the xmlns: elements 
               // (attrsCopy)
  -	    node = new Node.JspRoot(new AttributesImpl( attrs ), start, 
  -                current, false);
  +	    node = new Node.JspRoot(new AttributesImpl(attrs), start, current);
   	} else if (qName.equals(JSP_PAGE_DIRECTIVE)) {
   	    if (isTagFile) {
   		throw new SAXParseException(
  @@ -221,16 +233,7 @@
   	    }
   	} else if (qName.equals(JSP_INCLUDE_DIRECTIVE)) {
   	    node = new Node.IncludeDirective(attrsCopy, start, current);
  -	    String file = attrsCopy.getValue("file");
  -	    try {
  -		parserController.parse(file, node);
  -	    } catch (FileNotFoundException fnfe) {
  -		throw new SAXParseException(
  -                    err.getString("jsp.error.file.not.found", file),
  -		    locator, fnfe);
  -	    } catch (Exception e) {
  -		throw new SAXException(e);
  -	    }
  +	    processIncludeDirective(attrsCopy.getValue("file"), node);
   	} else if (qName.equals(JSP_DECLARATION)) {
   	    node = new Node.Declaration(start, current);
   	} else if (qName.equals(JSP_SCRIPTLET)) {
  @@ -589,6 +592,51 @@
   		    throw new SAXException(msg);
   		}
   	    }
  +	}
  +    }
  +
  +    /*
  +     * Processes the given list of included files.
  +     *
  +     * This is used to implement the include-prelude and include-coda
  +     * subelements of the jsp-config element in web.xml
  +     */
  +    private void addInclude(Node parent, List files) throws SAXException {
  +        if (files != null) {
  +            Iterator iter = files.iterator();
  +            while (iter.hasNext()) {
  +                String file = (String) iter.next();
  +                AttributesImpl attrs = new AttributesImpl();
  +                attrs.addAttribute("", "file", "file", "CDATA", file);
  +
  +                // Create a dummy Include directive node
  +                Node includeDir = new Node.IncludeDirective(attrs, 
  +							    null, // XXX
  +							    parent);
  +                processIncludeDirective(file, includeDir);
  +            }
  +        }
  +    }
  +
  +    /*
  +     * Parses the given file that is being specified in the given include
  +     * directive.
  +     */
  +    private void processIncludeDirective(String fname, Node includeDir) 
  +		throws SAXException {
  +
  +	if (fname == null) {
  +	    return;
  +	}
  +
  +	try {
  +	    parserController.parse(fname, includeDir);
  +	} catch (FileNotFoundException fnfe) {
  +	    throw new SAXParseException(err.getString(
  +                                            "jsp.error.file.not.found", fname),
  +					locator, fnfe);
  +	} catch (Exception e) {
  +	    throw new SAXException(e);
   	}
       }
   }
  
  
  
  1.36      +13 -12    jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Node.java	17 Oct 2002 21:38:56 -0000	1.35
  +++ Node.java	22 Oct 2002 03:00:20 -0000	1.36
  @@ -87,6 +87,8 @@
       protected Node parent;
       protected Nodes namedAttributeNodes; // cached for performance
   
  +    private boolean isDummy;
  +
       /**
        * Constructor.
        * @param start The location of the jsp page
  @@ -94,6 +96,7 @@
        */
       public Node(Mark start, Node parent) {
   	this.startMark = start;
  +	this.isDummy = (start == null);
   	addToParent(parent);
       }
   
  @@ -106,6 +109,7 @@
       public Node(Attributes attrs, Mark start, Node parent) {
   	this.attrs = attrs;
   	this.startMark = start;
  +	this.isDummy = (start == null);
   	addToParent(parent);
       }
   
  @@ -118,6 +122,7 @@
       public Node(char[] text, Mark start, Node parent) {
   	this.text = text;
   	this.startMark = start;
  +	this.isDummy = (start == null);
   	addToParent(parent);
       }
   
  @@ -268,6 +273,10 @@
   	endJavaLine = end;
       }
   
  +    public boolean isDummy() {
  +	return isDummy;
  +    }
  +
       /**
        * @return true if the current page is in xml syntax, false otherwise.
        */
  @@ -352,12 +361,8 @@
        */
       public static class JspRoot extends Root {
   
  -	private boolean isDummy;
  -
  -	public JspRoot(Attributes attrs, Mark start, Node parent,
  -		       boolean isDummy) {
  +	public JspRoot(Attributes attrs, Mark start, Node parent) {
   	    super(attrs, start, parent);
  -	    this.isDummy = isDummy;
   	}
   
   	public void accept(Visitor v) throws JasperException {
  @@ -366,10 +371,6 @@
   
   	public boolean isXmlSyntax() {
   	    return true;
  -	}
  -
  -	public boolean isDummy() {
  -	    return isDummy;
   	}
       }
   
  
  
  
  1.6       +1 -2      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java
  
  Index: SmapUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SmapUtil.java	22 Aug 2002 23:41:37 -0000	1.5
  +++ SmapUtil.java	22 Oct 2002 03:00:20 -0000	1.6
  @@ -471,8 +471,7 @@
               int numChildNodes = nodes.size();
               for( int i = 0; i < numChildNodes; i++ ) {
                   Node n = nodes.getNode( i );
  -		if (!(n instanceof Node.JspRoot)
  -		        || !((Node.JspRoot) n).isDummy()) {
  +		if (!n.isDummy()) {
   		    Mark mark = n.getStart();
   
   		    if (verbose) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message