kinman      2002/09/06 14:16:23

  Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
                        Parser.java ParserController.java
  Log:
  - Add parseTagFileDirectives that parses a tag file for its directives only,
    and skips over other constructs.  The benfit is not just parser speedup,
    but that it avoid parsing other tag files used by the current one.  This
    paves the way for handling circular tag file dependencies.
  
  Revision  Changes    Path
  1.92      +3 -5      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- Generator.java    6 Sep 2002 00:15:32 -0000       1.91
  +++ Generator.java    6 Sep 2002 21:16:23 -0000       1.92
  @@ -1479,8 +1479,6 @@
            String tagEvalVar = "_jspx_eval_" + baseVar;
            String tagHandlerVar = "_jspx_th_" + baseVar;
   
  -         Class tagHandlerClass = n.getTagHandlerClass();
  -
            // If the tag contains no scripting element, generate its codes
            // to a method.
            ServletWriter outSave = null;
  
  
  
  1.30      +52 -18    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- Parser.java       4 Sep 2002 22:54:54 -0000       1.29
  +++ Parser.java       6 Sep 2002 21:16:23 -0000       1.30
  @@ -97,6 +97,7 @@
       private ErrorDispatcher err;
       private int scriptlessCount;
       private boolean isTagFile;
  +    private boolean directivesOnly;
       
       // Virtual body content types, to make parsing a little easier.
       // These are not accessible from outside the parser.
  @@ -110,7 +111,8 @@
       /**
        * The constructor
        */
  -    private Parser(ParserController pc, JspReader reader, boolean isTagFile) {
  +    private Parser(ParserController pc, JspReader reader, boolean isTagFile,
  +                boolean directivesOnly) {
        this.parserController = pc;
        this.ctxt = pc.getJspCompilationContext();
        this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries();
  @@ -119,6 +121,7 @@
        this.currentFile = reader.mark().getFile();
           this.scriptlessCount = 0;
        this.isTagFile = isTagFile;
  +     this.directivesOnly = directivesOnly;
           start = reader.mark();
       }
   
  @@ -134,11 +137,19 @@
       public static Node.Nodes parse(ParserController pc,
                                   JspReader reader,
                                   Node parent,
  -                                boolean isTagFile) throws JasperException {
  -     Parser parser = new Parser(pc, reader, isTagFile);
  +                                boolean isTagFile,
  +                                boolean directivesOnly)
  +             throws JasperException {
  +
  +     Parser parser = new Parser(pc, reader, isTagFile, directivesOnly);
   
        Node.Root root = new Node.Root(null, reader.mark(), parent);
   
  +     if (directivesOnly) {
  +         parser.parseTagFileDirectives(root);
  +         return new Node.Nodes(root);
  +     }
  +
        // For the Top level page, add inlcude-prelude and include-coda
        PageInfo pageInfo = pc.getCompiler().getPageInfo();
        if (parent == null) {
  @@ -174,7 +185,7 @@
       public static Attributes parseAttributes(ParserController pc,
                                             JspReader reader)
                throws JasperException {
  -     Parser tmpParser = new Parser(pc, reader, false);
  +     Parser tmpParser = new Parser(pc, reader, false, false);
        return tmpParser.parseAttributes();
       }
   
  @@ -394,6 +405,7 @@
        *   Directive ::= ( S Attribute)*
        */
       private void parseTaglibDirective(Node parent) throws JasperException {
  +
        Attributes attrs = parseAttributes();
        String uri = attrs.getValue("uri");
        String prefix = attrs.getValue("prefix");
  @@ -452,6 +464,11 @@
            directive = "<%@ include";
            parseIncludeDirective(parent);
        } else if (reader.matches("taglib")) {
  +         if (directivesOnly) {
  +             // No need to get the tagLibInfo objects.  This alos suppresses
  +             // parsing of any tag files used in this tag file.
  +             return;
  +         }
            directive = "<%@ taglib";
            parseTaglibDirective(parent);
        } else if (reader.matches("tag")) {
  @@ -1356,14 +1373,14 @@
        *                 | ( '<jsp:declaration'  XMLDeclarationBody )
        *                 | ( '<%='               ExpressionBody     )
        *                 | ( '<jsp:expression'   XMLExpressionBody  )
  -     *                  | ( '${'                ELExpressionBody   )
  +     *                 | ( '${'                ELExpressionBody   )
        *                 | ( '<%'                ScriptletBody      )
        *                 | ( '<jsp:scriptlet'    XMLScriptletBody   )
  -     *                  | ( '<jsp:text'         XMLTemplateText    )
  +     *                 | ( '<jsp:text'         XMLTemplateText    )
        *                 | ( '<jsp:'             StandardAction     )
        *                 | ( '<'                 CustomAction
  -     *                                          CustomActionBody   )
  -     *                       | TemplateText
  +     *                                         CustomActionBody   )
  +     *                      | TemplateText
        */
       private void parseElements(Node parent) 
           throws JasperException 
  @@ -1407,21 +1424,21 @@
       }
   
       /*
  -     * ScriptlessBody ::=   ( '<%--'              JSPCommentBody      )
  +     * ScriptlessBody ::=  ( '<%--'              JSPCommentBody      )
        *                   | ( '<%@'               DirectiveBody       )
  -     *                    | ( '<jsp:directive.'   XMLDirectiveBody    )
  +     *                   | ( '<jsp:directive.'   XMLDirectiveBody    )
        *                   | ( '<%!'               <TRANSLATION_ERROR> )
  -     *                    | ( '<jsp:declaration'  <TRANSLATION_ERROR> )
  +     *                   | ( '<jsp:declaration'  <TRANSLATION_ERROR> )
        *                   | ( '<%='               <TRANSLATION_ERROR> )
        *                   | ( '<jsp:expression'   <TRANSLATION_ERROR> )
        *                   | ( '<%'                <TRANSLATION_ERROR> )
        *                   | ( '<jsp:scriptlet'    <TRANSLATION_ERROR> )
  -     *                    | ( '<jsp:text'         XMLTemplateText     )
  -     *                    | ( '${'                ELExpressionBody    )
  +     *                   | ( '<jsp:text'         XMLTemplateText     )
  +     *                   | ( '${'                ELExpressionBody    )
        *                   | ( '<jsp:'             StandardAction      )
        *                   | ( '<'                 CustomAction
  -     *                                            CustomActionBody    )
  -     *                         | TemplateText
  +     *                                           CustomActionBody    )
  +     *                   | TemplateText
        */
       private void parseElementsScriptless(Node parent) 
           throws JasperException 
  @@ -1724,6 +1741,23 @@
        }
   
        return JAVAX_BODY_CONTENT_TEMPLATE_TEXT;
  +    }
  +
  +    private void parseTagFileDirectives(Node parent)
  +        throws JasperException
  +    {
  +     reader.setSingleFile(true);
  +     reader.skipUntil("<");
  +        while (reader.hasMoreInput()) {
  +            if (reader.matches("%--")) {
  +                parseComment(parent);
  +            } else if (reader.matches("%@")) {
  +                parseDirective(parent);
  +            } else if (reader.matches("jsp:directive.")) {
  +                parseXMLDirective(parent);
  +            }
  +         reader.skipUntil("<");
  +     }
       }
   }
   
  
  
  
  1.19      +14 -2     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java
  
  Index: ParserController.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ParserController.java     29 Aug 2002 23:27:36 -0000      1.18
  +++ ParserController.java     6 Sep 2002 21:16:23 -0000       1.19
  @@ -114,11 +114,18 @@
       /*
        * Tells if the file to be parsed is a regular jsp page or tag file.
        * Usually we get the info from the compilation context, but it can
  -     * be temporarily overrideen with a parameter to the parse method
  +     * be temporarily overridden with a parameter to the parse method,
  +     * when parsing a tag file for its tagFileInfo content.
        */
       private boolean isTagFile = false;
   
       /*
  +     * True if the file to be parsed is a tag file and only we are only
  +     * interested for the directives needed for constructing a TagFileInfo.
  +     */ 
  +    private boolean directivesOnly = false;
  +
  +    /*
        * The encoding of the "top" file. This encoding is used
        * for included files by default.
        * Defaults to "ISO-8859-1" per JSP spec.
  @@ -158,6 +165,7 @@
       public Node.Nodes parse(String inFileName)
                throws FileNotFoundException, JasperException, IOException {
        isTagFile = ctxt.isTagFile();
  +     directivesOnly = false;
        return parseFile(inFileName, null);
       }
   
  @@ -182,6 +190,7 @@
                throws FileNotFoundException, JasperException, IOException {
        isTagFile = true;
        isTopFile = true;
  +     directivesOnly = true;
        return parseFile(inFileName, null);
       }
   
  @@ -190,6 +199,8 @@
        * This is invoked recursively to handle 'include' directives.
        *
        * @param inFileName The name of the jsp file to be parsed.
  +     * @param parent The parent node for the parser, and is non-null when
  +     *               parsing an included file
        */
       private Node.Nodes parseFile(String inFileName, Node parent)
                throws FileNotFoundException, JasperException, IOException {
  @@ -231,7 +242,8 @@
                JspReader r = new JspReader(ctxt, absFileName, encoding,
                                            reader,
                                            compiler.getErrorDispatcher());
  -                parsedPage = Parser.parse(this, r, parent, isTagFile);
  +                parsedPage = Parser.parse(this, r, parent, isTagFile,
  +                                       directivesOnly);
               }
            baseDirStack.pop();
           } finally {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to