Author: remy.maucherat(a)jboss.com
Date: 2010-03-24 22:48:03 -0400 (Wed, 24 Mar 2010)
New Revision: 1419
Modified:
trunk/java/org/apache/jasper/compiler/Generator.java
trunk/java/org/apache/jasper/compiler/Node.java
trunk/java/org/apache/jasper/compiler/ScriptingVariabler.java
trunk/webapps/docs/changelog.xml
Log:
- Port Jasper patch for scripting variables sync.
Modified: trunk/java/org/apache/jasper/compiler/Generator.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Generator.java 2010-03-25 02:46:36 UTC (rev
1418)
+++ trunk/java/org/apache/jasper/compiler/Generator.java 2010-03-25 02:48:03 UTC (rev
1419)
@@ -167,25 +167,6 @@
return b.toString();
}
- /**
- * Finds the <jsp:body> subelement of the given parent node. If not
- * found, null is returned.
- */
- protected static Node.JspBody findJspBody(Node parent) {
- Node.JspBody result = null;
-
- Node.Nodes subelements = parent.getBody();
- for (int i = 0; (subelements != null) && (i < subelements.size());
i++) {
- Node n = subelements.getNode(i);
- if (n instanceof Node.JspBody) {
- result = (Node.JspBody) n;
- break;
- }
- }
-
- return result;
- }
-
private String createJspId() throws JasperException {
if (this.jspIdPrefix == null) {
StringBuilder sb = new StringBuilder(32);
@@ -352,6 +333,9 @@
}
public void visit(Node.CustomTag n) throws JasperException {
+ // XXX - Actually there is no need to declare those
+ // "_jspx_" + varName + "_" + nestingLevel variables
when we are
+ // inside a JspFragment.
if (n.getCustomNestingLevel() > 0) {
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
@@ -997,6 +981,25 @@
}
}
+ /**
+ * Finds the <jsp:body> subelement of the given parent node. If
not
+ * found, null is returned.
+ */
+ private Node.JspBody findJspBody(Node parent) {
+ Node.JspBody result = null;
+
+ Node.Nodes subelements = parent.getBody();
+ for (int i = 0; (subelements != null) && (i < subelements.size());
i++) {
+ Node n = subelements.getNode(i);
+ if (n instanceof Node.JspBody) {
+ result = (Node.JspBody) n;
+ break;
+ }
+ }
+
+ return result;
+ }
+
public void visit(Node.ForwardAction n) throws JasperException {
Node.JspAttribute page = n.getPage();
@@ -2510,11 +2513,16 @@
}
private void declareScriptingVars(Node.CustomTag n, int scope) {
+ if (isFragment) {
+ // No need to declare Java variables, if we inside a
+ // JspFragment, because a fragment is always scriptless.
+ return;
+ }
- Vector vec = n.getScriptingVars(scope);
+ List<Object> vec = n.getScriptingVars(scope);
if (vec != null) {
for (int i = 0; i < vec.size(); i++) {
- Object elem = vec.elementAt(i);
+ Object elem = vec.get(i);
if (elem instanceof VariableInfo) {
VariableInfo varInfo = (VariableInfo) elem;
if (varInfo.getDeclare()) {
@@ -2557,6 +2565,14 @@
if (n.getCustomNestingLevel() == 0) {
return;
}
+ if (isFragment) {
+ // No need to declare Java variables, if we inside a
+ // JspFragment, because a fragment is always scriptless.
+ // Thus, there is no need to save/ restore/ sync them.
+ // Note, that JspContextWrapper.syncFoo() methods will take
+ // care of saving/ restoring/ sync'ing of JspContext attributes.
+ return;
+ }
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
VariableInfo[] varInfos = n.getVariableInfos();
@@ -2564,13 +2580,15 @@
return;
}
+ List<Object> declaredVariables = n.getScriptingVars(scope);
+
if (varInfos.length > 0) {
for (int i = 0; i < varInfos.length; i++) {
if (varInfos[i].getScope() != scope)
continue;
// If the scripting variable has been declared, skip codes
// for saving and restoring it.
- if (n.getScriptingVars(scope).contains(varInfos[i]))
+ if (declaredVariables.contains(varInfos[i]))
continue;
String varName = varInfos[i].getVarName();
String tmpVarName = "_jspx_" + varName + "_"
@@ -2586,7 +2604,7 @@
continue;
// If the scripting variable has been declared, skip codes
// for saving and restoring it.
- if (n.getScriptingVars(scope).contains(tagVarInfos[i]))
+ if (declaredVariables.contains(tagVarInfos[i]))
continue;
String varName = tagVarInfos[i].getNameGiven();
if (varName == null) {
@@ -2617,6 +2635,14 @@
if (n.getCustomNestingLevel() == 0) {
return;
}
+ if (isFragment) {
+ // No need to declare Java variables, if we inside a
+ // JspFragment, because a fragment is always scriptless.
+ // Thus, there is no need to save/ restore/ sync them.
+ // Note, that JspContextWrapper.syncFoo() methods will take
+ // care of saving/ restoring/ sync'ing of JspContext attributes.
+ return;
+ }
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
VariableInfo[] varInfos = n.getVariableInfos();
@@ -2624,13 +2650,15 @@
return;
}
+ List<Object> declaredVariables = n.getScriptingVars(scope);
+
if (varInfos.length > 0) {
for (int i = 0; i < varInfos.length; i++) {
if (varInfos[i].getScope() != scope)
continue;
// If the scripting variable has been declared, skip codes
// for saving and restoring it.
- if (n.getScriptingVars(scope).contains(varInfos[i]))
+ if (declaredVariables.contains(varInfos[i]))
continue;
String varName = varInfos[i].getVarName();
String tmpVarName = "_jspx_" + varName + "_"
@@ -2646,7 +2674,7 @@
continue;
// If the scripting variable has been declared, skip codes
// for saving and restoring it.
- if (n.getScriptingVars(scope).contains(tagVarInfos[i]))
+ if (declaredVariables.contains(tagVarInfos[i]))
continue;
String varName = tagVarInfos[i].getNameGiven();
if (varName == null) {
@@ -2671,6 +2699,15 @@
* given scope.
*/
private void syncScriptingVars(Node.CustomTag n, int scope) {
+ if (isFragment) {
+ // No need to declare Java variables, if we inside a
+ // JspFragment, because a fragment is always scriptless.
+ // Thus, there is no need to save/ restore/ sync them.
+ // Note, that JspContextWrapper.syncFoo() methods will take
+ // care of saving/ restoring/ sync'ing of JspContext attributes.
+ return;
+ }
+
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
VariableInfo[] varInfos = n.getVariableInfos();
Modified: trunk/java/org/apache/jasper/compiler/Node.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Node.java 2010-03-25 02:46:36 UTC (rev 1418)
+++ trunk/java/org/apache/jasper/compiler/Node.java 2010-03-25 02:48:03 UTC (rev 1419)
@@ -1425,11 +1425,11 @@
private boolean implementsDynamicAttributes;
- private Vector atBeginScriptingVars;
+ private List<Object> atBeginScriptingVars;
- private Vector atEndScriptingVars;
+ private List<Object> atEndScriptingVars;
- private Vector nestedScriptingVars;
+ private List<Object> nestedScriptingVars;
private Node.CustomTag customTagParent;
@@ -1661,7 +1661,7 @@
return this.numCount;
}
- public void setScriptingVars(Vector vec, int scope) {
+ public void setScriptingVars(List<Object> vec, int scope) {
switch (scope) {
case VariableInfo.AT_BEGIN:
this.atBeginScriptingVars = vec;
@@ -1679,8 +1679,8 @@
* Gets the scripting variables for the given scope that need to be
* declared.
*/
- public Vector getScriptingVars(int scope) {
- Vector vec = null;
+ public List<Object> getScriptingVars(int scope) {
+ List<Object> vec = null;
switch (scope) {
case VariableInfo.AT_BEGIN:
Modified: trunk/java/org/apache/jasper/compiler/ScriptingVariabler.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/ScriptingVariabler.java 2010-03-25 02:46:36 UTC
(rev 1418)
+++ trunk/java/org/apache/jasper/compiler/ScriptingVariabler.java 2010-03-25 02:48:03 UTC
(rev 1419)
@@ -58,11 +58,11 @@
static class ScriptingVariableVisitor extends Node.Visitor {
private ErrorDispatcher err;
- private Hashtable scriptVars;
+ private Map<String, Integer> scriptVars;
public ScriptingVariableVisitor(ErrorDispatcher err) {
this.err = err;
- scriptVars = new Hashtable();
+ scriptVars = new HashMap<String,Integer>();
}
public void visit(Node.CustomTag n) throws JasperException {
@@ -81,7 +81,7 @@
return;
}
- Vector vec = new Vector();
+ List<Object> vec = new ArrayList<Object>();
Node.CustomTag parent = n.getCustomTagParent();
Integer ownRange = null;
@@ -105,11 +105,8 @@
String varName = varInfos[i].getVarName();
Integer currentRange = (Integer) scriptVars.get(varName);
- // If a fragment helper has been used for the parent tag
- // the scripting variables always need to be declared
if (currentRange == null ||
- ownRange.compareTo(currentRange) > 0 ||
- parent != null && isImplementedAsFragment(parent)) {
+ ownRange.compareTo(currentRange) > 0) {
scriptVars.put(varName, ownRange);
vec.add(varInfos[i]);
}
@@ -131,11 +128,8 @@
}
Integer currentRange = (Integer) scriptVars.get(varName);
- // If a fragment helper has been used for the parent tag
- // the scripting variables always need to be declared
if (currentRange == null ||
- ownRange.compareTo(currentRange) > 0 ||
- parent != null && isImplementedAsFragment(parent)) {
+ ownRange.compareTo(currentRange) > 0) {
scriptVars.put(varName, ownRange);
vec.add(tagVarInfos[i]);
}
@@ -146,21 +140,6 @@
}
}
- private static boolean isImplementedAsFragment(Node.CustomTag n) {
- // Replicates logic from Generator to determine if a fragment
- // helper will be used
- if (n.implementsSimpleTag()) {
- if (Generator.findJspBody(n) == null) {
- if (!n.hasEmptyBody()) {
- return true;
- }
- return false;
- }
- return true;
- }
- return false;
- }
-
public static void set(Node.Nodes page, ErrorDispatcher err)
throws JasperException {
page.visit(new CustomTagCounter());
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2010-03-25 02:46:36 UTC (rev 1418)
+++ trunk/webapps/docs/changelog.xml 2010-03-25 02:48:03 UTC (rev 1419)
@@ -16,6 +16,24 @@
<body>
+<section name="JBoss Web 3.0.0.Beta4 (remm)">
+ <subsection name="Catalina">
+ <changelog>
+ </changelog>
+ </subsection>
+ <subsection name="Coyote">
+ <changelog>
+ </changelog>
+ </subsection>
+ <subsection name="Jasper">
+ <changelog>
+ <fix>
+ <bug>48616</bug>: Additional variable declaration fixes. (kkolinko)
+ </fix>
+ </changelog>
+ </subsection>
+</section>
+
<section name="JBoss Web 3.0.0.Beta3 (remm)">
<subsection name="Catalina">
<changelog>