Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.jasper.compiler;
 
Collect info about the page and nodes, and make them availabe through the PageInfo object.

Author(s):
Kin-man Chung
Mark Roth
 
 
 class Collector {

    
A visitor for collecting information on the page and the body of the custom tags.
 
     static class CollectVisitor extends Node.Visitor {
 
         private boolean scriptingElementSeen = false;
         private boolean usebeanSeen = false;
         private boolean includeActionSeen = false;
         private boolean paramActionSeen = false;
         private boolean setPropertySeen = false;
         private boolean hasScriptingVars = false;
 
         public void visit(Node.ParamAction nthrows JasperException {
             if (n.getValue().isExpression()) {
                  = true;
             }
              = true;
         }
 
         public void visit(Node.IncludeAction nthrows JasperException {
             if (n.getPage().isExpression()) {
                  = true;
             }
              = true;
             visitBody(n);
         }
 
         public void visit(Node.ForwardAction nthrows JasperException {
             if (n.getPage().isExpression()) {
                  = true;
             }
             visitBody(n);
         }
 
         public void visit(Node.SetProperty nthrows JasperException {
             if (n.getValue() != null && n.getValue().isExpression()) {
                  = true;
             }
              = true;
         }
 
         public void visit(Node.UseBean nthrows JasperException {
             if (n.getBeanName() != null && n.getBeanName().isExpression()) {
                  = true;
             }
              = true;
                 visitBody(n);
         }
 
         public void visit(Node.PlugIn nthrows JasperException {
             if (n.getHeight() != null && n.getHeight().isExpression()) {
                  = true;
             }
             if (n.getWidth() != null && n.getWidth().isExpression()) {
                  = true;
             }
             visitBody(n);
         }
 
         public void visit(Node.CustomTag nthrows JasperException {
             // Check to see what kinds of element we see as child elements
             checkSeenn.getChildInfo(), n );
         }

        
Check all child nodes for various elements and update the given ChildInfo object accordingly. Visits body in the process.
        private void checkSeenNode.ChildInfo ciNode n )
            throws JasperException
        {
            // save values collected so far
            boolean scriptingElementSeenSave = ;
             = false;
            boolean usebeanSeenSave = ;
             = false;
            boolean includeActionSeenSave = ;
             = false;
            boolean paramActionSeenSave = ;
             = false;
            boolean setPropertySeenSave = ;
             = false;
            boolean hasScriptingVarsSave = ;
             = false;
            // Scan attribute list for expressions
            ifn instanceof Node.CustomTag ) {
                Node.CustomTag ct = (Node.CustomTag)n;
                Node.JspAttribute[] attrs = ct.getJspAttributes();
                for (int i = 0; attrs != null && i < attrs.lengthi++) {
                    if (attrs[i].isExpression()) {
                         = true;
                        break;
                    }
                }
            }
            visitBody(n);
            if( (n instanceof Node.CustomTag) && !) {
                Node.CustomTag ct = (Node.CustomTag)n;
                 = ct.getVariableInfos().length > 0 ||
                    ct.getTagVariableInfos().length > 0;
            }
            // Record if the tag element and its body contains any scriptlet.
            ci.setScriptless(! );
            ci.setHasUseBean();
            ci.setHasIncludeAction();
            ci.setHasParamAction();
            ci.setHasSetProperty();
            ci.setHasScriptingVars();
            // Propagate value of scriptingElementSeen up.
             =  || scriptingElementSeenSave;
             =  || usebeanSeenSave;
             =  || setPropertySeenSave;
             =  || includeActionSeenSave;
             =  || paramActionSeenSave;
             =  || hasScriptingVarsSave;
        }
        public void visit(Node.JspElement nthrows JasperException {
            if (n.getNameAttribute().isExpression())
                 = true;
            Node.JspAttribute[] attrs = n.getJspAttributes();
            for (int i = 0; i < attrs.lengthi++) {
                if (attrs[i].isExpression()) {
                     = true;
                    break;
                }
            }
            visitBody(n);
        }
        public void visit(Node.JspBody nthrows JasperException {
            checkSeenn.getChildInfo(), n );
        }
        public void visit(Node.NamedAttribute nthrows JasperException {
            checkSeenn.getChildInfo(), n );
        }
        public void visit(Node.Declaration nthrows JasperException {
             = true;
        }
        public void visit(Node.Expression nthrows JasperException {
             = true;
        }
        public void visit(Node.Scriptlet nthrows JasperException {
             = true;
        }
        public void updatePageInfo(PageInfo pageInfo) {
            pageInfo.setScriptless(! );
        }
    }
    public static void collect(Compiler compilerNode.Nodes page)
        throws JasperException {
    CollectVisitor collectVisitor = new CollectVisitor();
        page.visit(collectVisitor);
        collectVisitor.updatePageInfo(compiler.getPageInfo());
    }
New to GrepCode? Check out our FAQ X