1 17 18 package org.apache.jasper.compiler; 19 20 import org.apache.jasper.JasperException; 21 22 29 30 class Collector { 31 32 36 static class CollectVisitor extends Node.Visitor { 37 38 private boolean scriptingElementSeen = false; 39 private boolean usebeanSeen = false; 40 private boolean includeActionSeen = false; 41 private boolean paramActionSeen = false; 42 private boolean setPropertySeen = false; 43 private boolean hasScriptingVars = false; 44 45 public void visit(Node.ParamAction n) throws JasperException { 46 if (n.getValue().isExpression()) { 47 scriptingElementSeen = true; 48 } 49 paramActionSeen = true; 50 } 51 52 public void visit(Node.IncludeAction n) throws JasperException { 53 if (n.getPage().isExpression()) { 54 scriptingElementSeen = true; 55 } 56 includeActionSeen = true; 57 visitBody(n); 58 } 59 60 public void visit(Node.ForwardAction n) throws JasperException { 61 if (n.getPage().isExpression()) { 62 scriptingElementSeen = true; 63 } 64 visitBody(n); 65 } 66 67 public void visit(Node.SetProperty n) throws JasperException { 68 if (n.getValue() != null && n.getValue().isExpression()) { 69 scriptingElementSeen = true; 70 } 71 setPropertySeen = true; 72 } 73 74 public void visit(Node.UseBean n) throws JasperException { 75 if (n.getBeanName() != null && n.getBeanName().isExpression()) { 76 scriptingElementSeen = true; 77 } 78 usebeanSeen = true; 79 visitBody(n); 80 } 81 82 public void visit(Node.PlugIn n) throws JasperException { 83 if (n.getHeight() != null && n.getHeight().isExpression()) { 84 scriptingElementSeen = true; 85 } 86 if (n.getWidth() != null && n.getWidth().isExpression()) { 87 scriptingElementSeen = true; 88 } 89 visitBody(n); 90 } 91 92 public void visit(Node.CustomTag n) throws JasperException { 93 checkSeen( n.getChildInfo(), n ); 95 } 96 97 101 private void checkSeen( Node.ChildInfo ci, Node n ) 102 throws JasperException 103 { 104 boolean scriptingElementSeenSave = scriptingElementSeen; 106 scriptingElementSeen = false; 107 boolean usebeanSeenSave = usebeanSeen; 108 usebeanSeen = false; 109 boolean includeActionSeenSave = includeActionSeen; 110 includeActionSeen = false; 111 boolean paramActionSeenSave = paramActionSeen; 112 paramActionSeen = false; 113 boolean setPropertySeenSave = setPropertySeen; 114 setPropertySeen = false; 115 boolean hasScriptingVarsSave = hasScriptingVars; 116 hasScriptingVars = false; 117 118 if( n instanceof Node.CustomTag ) { 120 Node.CustomTag ct = (Node.CustomTag)n; 121 Node.JspAttribute[] attrs = ct.getJspAttributes(); 122 for (int i = 0; attrs != null && i < attrs.length; i++) { 123 if (attrs[i].isExpression()) { 124 scriptingElementSeen = true; 125 break; 126 } 127 } 128 } 129 130 visitBody(n); 131 132 if( (n instanceof Node.CustomTag) && !hasScriptingVars) { 133 Node.CustomTag ct = (Node.CustomTag)n; 134 hasScriptingVars = ct.getVariableInfos().length > 0 || 135 ct.getTagVariableInfos().length > 0; 136 } 137 138 ci.setScriptless(! scriptingElementSeen); 140 ci.setHasUseBean(usebeanSeen); 141 ci.setHasIncludeAction(includeActionSeen); 142 ci.setHasParamAction(paramActionSeen); 143 ci.setHasSetProperty(setPropertySeen); 144 ci.setHasScriptingVars(hasScriptingVars); 145 146 scriptingElementSeen = scriptingElementSeen || scriptingElementSeenSave; 148 usebeanSeen = usebeanSeen || usebeanSeenSave; 149 setPropertySeen = setPropertySeen || setPropertySeenSave; 150 includeActionSeen = includeActionSeen || includeActionSeenSave; 151 paramActionSeen = paramActionSeen || paramActionSeenSave; 152 hasScriptingVars = hasScriptingVars || hasScriptingVarsSave; 153 } 154 155 public void visit(Node.JspElement n) throws JasperException { 156 if (n.getNameAttribute().isExpression()) 157 scriptingElementSeen = true; 158 159 Node.JspAttribute[] attrs = n.getJspAttributes(); 160 for (int i = 0; i < attrs.length; i++) { 161 if (attrs[i].isExpression()) { 162 scriptingElementSeen = true; 163 break; 164 } 165 } 166 visitBody(n); 167 } 168 169 public void visit(Node.JspBody n) throws JasperException { 170 checkSeen( n.getChildInfo(), n ); 171 } 172 173 public void visit(Node.NamedAttribute n) throws JasperException { 174 checkSeen( n.getChildInfo(), n ); 175 } 176 177 public void visit(Node.Declaration n) throws JasperException { 178 scriptingElementSeen = true; 179 } 180 181 public void visit(Node.Expression n) throws JasperException { 182 scriptingElementSeen = true; 183 } 184 185 public void visit(Node.Scriptlet n) throws JasperException { 186 scriptingElementSeen = true; 187 } 188 189 public void updatePageInfo(PageInfo pageInfo) { 190 pageInfo.setScriptless(! scriptingElementSeen); 191 } 192 } 193 194 195 public static void collect(Compiler compiler, Node.Nodes page) 196 throws JasperException { 197 198 CollectVisitor collectVisitor = new CollectVisitor(); 199 page.visit(collectVisitor); 200 collectVisitor.updatePageInfo(compiler.getPageInfo()); 201 202 } 203 } 204 205 | Popular Tags |