luehe 2002/10/28 10:16:21 Modified: jasper2/src/share/org/apache/jasper JspCompilationContext.java jasper2/src/share/org/apache/jasper/compiler Generator.java Parser.java ScriptingVariabler.java TagFileProcessor.java TagLibraryInfoImpl.java Validator.java jasper2/src/share/org/apache/jasper/runtime JspContextWrapper.java JspFragmentHelper.java jasper2/src/share/org/apache/jasper/servlet JspServletWrapper.java jasper2/src/share/org/apache/jasper/resources messages.properties messages_es.properties messages_ja.properties Log: - Removed support for fragment-scoped variables. - Implemented new fragment invocation protocol: * Variables appear as page-scoped attributes local to the tag file, and are synchronized with the calling page context at various points. * Fragment invocations can no longer be parameterized. Revision Changes Path 1.24 +3 -10 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java Index: JspCompilationContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JspCompilationContext.java 21 Oct 2002 18:44:00 -0000 1.23 +++ JspCompilationContext.java 28 Oct 2002 18:16:19 -0000 1.24 @@ -122,7 +122,6 @@ private boolean isTagFile; private boolean protoTypeMode; private TagInfo tagInfo; - private TagData tagData; // jspURI _must_ be relative to the context public JspCompilationContext(String jspUri, @@ -159,7 +158,6 @@ public JspCompilationContext(String tagfile, TagInfo tagInfo, - TagData tagData, Options options, ServletContext context, JspServletWrapper jsw, @@ -169,7 +167,6 @@ this(tagfile, false, options, context, jsw, rctxt); this.isTagFile = true; this.tagInfo = tagInfo; - this.tagData = tagData; this.tagFileJars = tagFileJars; if (tagFileJars != null && tagFileJars.get(tagfile) != null) { isPackagedTagFile = true; @@ -378,10 +375,6 @@ public void setPrototypeMode(boolean pm) { protoTypeMode = pm; - } - - public TagData getTagData() { - return tagData; } /** 1.112 +64 -197 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.111 retrieving revision 1.112 diff -u -r1.111 -r1.112 --- Generator.java 17 Oct 2002 21:38:56 -0000 1.111 +++ Generator.java 28 Oct 2002 18:16:19 -0000 1.112 @@ -1832,85 +1832,28 @@ public void visit(Node.InvokeAction n) throws JasperException { - /** - * A visitor to handle <jsp:param> in a <jsp:invoke> - */ - class ParamVisitor extends Node.Visitor { + // Copy virtual page scope of tag file to page scope of invoking + // page + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.NESTED);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.AT_BEGIN);"); - // The name of the fragment to which the <jsp:param> applies - private String fragName; - - public ParamVisitor(String fragName) { - this.fragName = fragName; - } - - public void visit(Node.ParamAction n) throws JasperException { - out.printin("_jspx_params.put("); - out.print(quote(n.getTextAttribute("name"))); - out.print(", "); - out.print(attributeValue(n.getValue(), false, - getParamClass(n), "null")); - out.println(");"); - } - - /* - * Checks to see if the given <jsp:param> matches a tag file - * variable scoped to the same fragment as the enclosing - * <jsp:invoke>. If a match is found, the class specified in - * the variable directive's 'variable-class' attribute (if - * present) is loaded and returned. - */ - private Class getParamClass(Node.ParamAction n) - throws JasperException { - - Class clazz = String.class; - - TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos(); - if (tagVars != null) { - String paramName = n.getTextAttribute("name"); - for (int i=0; i<tagVars.length; i++) { - String varName = tagVars[i].getNameGiven(); - if (varName == null) { - // XXX name-from-attribute: - // What to do in this case? - } - String tagVarFrag = tagVars[i].getFragment(); - if (!paramName.equals(varName) - || tagVarFrag == null - || !this.fragName.equals(tagVarFrag)) - continue; - try { - clazz = JspUtil.toClass(tagVars[i].getClassName(), loader); - } catch (ClassNotFoundException cnfe) { - throw new JasperException(cnfe); - } - } - } - - return clazz; - } - } - - // Assemble parameter map - out.printil("_jspx_params = new java.util.HashMap();"); - if (n.getBody() != null) { - prepareParams(n); - n.getBody().visit(new ParamVisitor( - n.getTextAttribute("fragment"))); - } - - // Invoke fragment with parameter map + // Invoke fragment String varReaderAttr = n.getTextAttribute("varReader"); String varAttr = n.getTextAttribute("var"); if (varReaderAttr != null || varAttr != null) { out.printil("_jspx_sout = new java.io.StringWriter();"); out.printin(toGetterMethod(n.getTextAttribute("fragment"))); - out.println(".invoke(_jspx_sout, _jspx_params);"); + out.println(".invoke(_jspx_sout);"); } else { out.printin(toGetterMethod(n.getTextAttribute("fragment"))); - out.println(".invoke(null, _jspx_params);"); + out.println(".invoke(null);"); } + // Copy page scope of invoking page back to virtual page scope of + // tag file + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyPageToTagScope(javax.servlet.jsp.tagext.VariableInfo.NESTED);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyPageToTagScope(javax.servlet.jsp.tagext.VariableInfo.AT_BEGIN);"); + // Store varReader in appropriate scope if (varReaderAttr != null || varAttr != null) { String scopeName = n.getTextAttribute("scope"); @@ -1932,68 +1875,26 @@ public void visit(Node.DoBodyAction n) throws JasperException { - /** - * A visitor to handle <jsp:param> in a <jsp:doBody> - */ - class ParamVisitor extends Node.Visitor { - - public void visit(Node.ParamAction n) throws JasperException { - out.printin("_jspx_params.put("); - out.print(quote(n.getTextAttribute("name"))); - out.print(", "); - out.print(attributeValue(n.getValue(), false, - String.class, "null")); - out.println(");"); - } - } - - // Assemble parameter map - out.printil("_jspx_params = new java.util.HashMap();"); - if (n.getBody() != null) { - prepareParams(n); - n.getBody().visit(new ParamVisitor()); - } - - // Add AT_BEGIN and NESTED scripting variables (that are not - // scoped to any fragment) to parameter map - TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos(); - if (tagVars != null) { - for (int i=0; i<tagVars.length; i++) { - if (tagVars[i].getFragment() != null) { - continue; - } - int scope = tagVars[i].getScope(); - if (scope != VariableInfo.AT_BEGIN - && scope != VariableInfo.NESTED) { - continue; - } - out.printin("_jspx_params.put("); - String name = tagVars[i].getNameGiven(); - if (name != null) { - out.print(quote(name)); - out.print(", pageContext.getAttribute("); - out.print(quote(name)); - out.println("));"); - } else { - String getter = toGetterMethod(tagVars[i].getNameFromAttribute()); - out.print(getter); - out.print(", pageContext.getAttribute("); - out.print(getter); - out.println("));"); - } - } - } + // Copy virtual page scope of tag file to page scope of invoking + // page + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.NESTED);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.AT_BEGIN);"); - // Invoke body with parameter map + // Invoke body String varReaderAttr = n.getTextAttribute("varReader"); String varAttr = n.getTextAttribute("var"); if (varReaderAttr != null || varAttr != null) { out.printil("_jspx_sout = new java.io.StringWriter();"); - out.printil("getJspBody().invoke(_jspx_sout, _jspx_params);"); + out.printil("getJspBody().invoke(_jspx_sout);"); } else { - out.printil("getJspBody().invoke(null, _jspx_params);"); + out.printil("getJspBody().invoke(null);"); } + // Copy page scope of invoking page back to virtual page scope of + // tag file + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyPageToTagScope(javax.servlet.jsp.tagext.VariableInfo.NESTED);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyPageToTagScope(javax.servlet.jsp.tagext.VariableInfo.AT_BEGIN);"); + // Store varReader in appropriate scope if (varReaderAttr != null || varAttr != null) { String scopeName = n.getTextAttribute("scope"); @@ -2986,25 +2887,6 @@ * Class body begins here */ - // Declare parameter map for fragment/body invocation. This must be - // declared as an instance variable (as opposed to a local variable in - // doTag()), so that it is accessible: - // - // - from the JspFragmentHelper subclass specific to the automatically - // generated tag handler, in case the fragment/body invocation is - // contained in a fragment body, as in: - // <my:simple> - // <jsp:invoke fragment="frag"/> - // </my:simple> - // - // - from the invocation of a classic tag handler that is separated out - // into its own method, if the fragment/body invocation is - // encapsulated in a custom action, as in: - // <my:classic> - // <jsp:invoke fragment="frag"/> - // </my:classic> - out.printil("private java.util.Map _jspx_params = null;"); - generateDeclarations(tag); // Static initializations here @@ -3071,38 +2953,9 @@ } private void generateTagHandlerPostamble( TagInfo tagInfo ) { - // Note: Before this point, the page author must have updated the - // scoped variables with the synced versions. We now transfer any - // of those scoped variables that are in the locally-scoped page - // context to the "real" page context of the calling code. - out.printil( "// Sync up variables with caller's page context:" ); - - TagVariableInfo[] tagVariableInfo = tagInfo.getTagVariableInfos(); - for( int i = 0; tagVariableInfo != null - && i < tagVariableInfo.length; i++ ) { - // XXX - Spec bug: Note, we don't know the value of - // this attribute at translation time, because we're defining - // the tag, and we don't know how page authors will call it. - // Instead, we make a best guess at runtime of what the - // name of the attribute is. There are lots of potential - // problems with this approach and this implementation, but - // we're expecting the spec to change. - if( ( tagVariableInfo[i].getScope() == VariableInfo.AT_BEGIN ) || - ( tagVariableInfo[i].getScope() == VariableInfo.AT_END ) ) - { - String var = tagVariableInfo[i].getNameFromAttribute(); - if( var == null ) { - var = "\"" + tagVariableInfo[i].getNameGiven() + "\""; - } - out.printil( "if( jspContext.getAttributesScope( " + var + - " ) == JspContext.PAGE_SCOPE ) {" ); - out.pushIndent(); - out.printil( "super.jspContext.setAttribute( " + var + - ", jspContext.getAttribute( " + var + " ) );" ); - out.popIndent(); - out.printil( "}" ); - } - } + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.AT_BEGIN);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).copyTagToPageScope(javax.servlet.jsp.tagext.VariableInfo.AT_END);"); + out.printil("((org.apache.jasper.runtime.JspContextWrapper) jspContext).restoreNestedVariables();"); out.popIndent(); @@ -3204,16 +3057,43 @@ // Define setter for JspContext so we can create a wrapper and // store both the original and the wrapper. We need the wrapper - // to maask the page context from the tag file and simulate a + // to mask the page context from the tag file and simulate a // fresh page context. We need the original to do things like // sync AT_BEGIN and AT_END scripting variables. out.printil( "protected JspContext jspContext;" ); out.println(); out.printil( "public void setJspContext( JspContext ctx ) {" ); out.pushIndent(); - out.printil( "super.setJspContext( ctx );" ); - out.printil( "this.jspContext = new org.apache.jasper.runtime.JspContextWrapper( ctx );" ); - out.popIndent(); + out.printil( "super.setJspContext(ctx);" ); + + out.printil("java.util.Vector _jspx_nested = new java.util.Vector();"); + out.printil("java.util.Vector _jspx_at_begin = new java.util.Vector();"); + out.printil("java.util.Vector _jspx_at_end = new java.util.Vector();"); + TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos(); + for (int i=0; tagVars != null && i<tagVars.length; i++) { + String name = tagVars[i].getNameGiven(); + /* XXX + if (name == null) { + name = toGetterMethod(tagVars[i].getNameFromAttribute()); + } + */ + switch(tagVars[i].getScope()) { + case VariableInfo.NESTED: + out.printin("_jspx_nested.addElement("); + break; + case VariableInfo.AT_BEGIN: + out.printin("_jspx_at_begin.addElement("); + break; + case VariableInfo.AT_END: + out.printin("_jspx_at_end.addElement("); + break; + } // switch + + out.print(quote(name)); + out.println(");"); + } + out.printil( "this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end);" ); + out.popIndent(); out.printil( "}" ); out.println(); out.printil( "public JspContext getJspContext() {" ); @@ -3477,8 +3357,7 @@ } else { out.printin("public void invoke"); } - out.println(result.getId() + "( " + - "java.io.Writer out, java.util.Map params ) " ); + out.println(result.getId() + "( " + "java.io.Writer out ) " ); out.pushIndent(); // Note: Throwable required because methods like _jspx_meth_* // throw Throwable. @@ -3515,19 +3394,12 @@ } // Generate postamble: - out.printil( "public void invoke( java.io.Writer writer, " + - "java.util.Map params )" ); + out.printil( "public void invoke( java.io.Writer writer )" ); out.pushIndent(); out.printil( "throws javax.servlet.jsp.JspException" ); out.popIndent(); out.printil( "{" ); out.pushIndent(); - out.printil( "java.util.Map _jspx_originalValues = null;" ); - out.printil( "if( params != null ) {" ); - out.pushIndent(); - out.printil( "_jspx_originalValues = preparePageScope( params );"); - out.popIndent(); - out.printil( "}" ); out.printil( "java.io.Writer out = null;" ); out.printil( "if( writer != null ) {" ); out.pushIndent(); @@ -3545,7 +3417,7 @@ for( int i = 0; i < fragments.size(); i++ ) { out.printil( "case " + i + ":" ); out.pushIndent(); - out.printil( "invoke" + i + "( out, params );" ); + out.printil( "invoke" + i + "( out );" ); out.printil( "break;" ); out.popIndent(); } @@ -3569,11 +3441,6 @@ out.popIndent(); out.printil( "}" ); - out.printil( "if( params != null ) {" ); - out.pushIndent(); - out.printil( "restorePageScope( _jspx_originalValues );"); - out.popIndent(); - out.printil( "}" ); out.popIndent(); out.printil( "}" ); // finally out.popIndent(); 1.36 +5 -5 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.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- Parser.java 17 Oct 2002 21:38:56 -0000 1.35 +++ Parser.java 28 Oct 2002 18:16:20 -0000 1.36 @@ -842,7 +842,7 @@ Node invokeNode = new Node.InvokeAction(attrs, start, parent); - parseOptionalBody(invokeNode, "jsp:invoke", JAVAX_BODY_CONTENT_PARAM); + parseEmptyBody(invokeNode, "jsp:invoke"); } private void parseDoBody(Node parent) throws JasperException { @@ -851,7 +851,7 @@ Node doBodyNode = new Node.DoBodyAction(attrs, start, parent); - parseOptionalBody(doBodyNode, "jsp:doBody", JAVAX_BODY_CONTENT_PARAM); + parseEmptyBody(doBodyNode, "jsp:doBody"); } /* 1.7 +4 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ScriptingVariabler.java Index: ScriptingVariabler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ScriptingVariabler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ScriptingVariabler.java 17 Oct 2002 20:43:06 -0000 1.6 +++ ScriptingVariabler.java 28 Oct 2002 18:16:20 -0000 1.7 @@ -157,8 +157,7 @@ } else { for (int i=0; i<tagVarInfos.length; i++) { if (tagVarInfos[i].getScope() != scope - || !tagVarInfos[i].getDeclare() - || tagVarInfos[i].getFragment() != null) { + || !tagVarInfos[i].getDeclare()) { continue; } String varName = tagVarInfos[i].getNameGiven(); 1.32 +14 -36 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java Index: TagFileProcessor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- TagFileProcessor.java 17 Oct 2002 20:43:06 -0000 1.31 +++ TagFileProcessor.java 28 Oct 2002 18:16:20 -0000 1.32 @@ -113,11 +113,9 @@ private static final JspUtil.ValidAttribute[] variableDirectiveAttrs = { new JspUtil.ValidAttribute("name-given"), - new JspUtil.ValidAttribute("name-from-attribute"), new JspUtil.ValidAttribute("variable-class"), new JspUtil.ValidAttribute("scope"), new JspUtil.ValidAttribute("declare"), - new JspUtil.ValidAttribute("fragment"), new JspUtil.ValidAttribute("description") }; @@ -144,7 +142,6 @@ private Vector attributeVector = new Vector(); private Vector variableVector = new Vector(); - private Map fragmentAttributesMap = new Hashtable(); public TagFileVisitor(Compiler compiler, TagLibraryInfo tagLibInfo, String name) { @@ -188,7 +185,6 @@ n.getAttributeValue("fragment")); String type = n.getAttributeValue("type"); if (fragment) { - fragmentAttributesMap.put(attrName, n); // type is fixed to "JspFragment" and a translation error // must occur if specified. if (type != null) { @@ -216,7 +212,6 @@ variableDirectiveAttrs, err); String nameGiven = n.getAttributeValue("name-given"); - String nameFromAttribute = n.getAttributeValue("name-from-attribute"); String className = n.getAttributeValue("variable-class"); if (className == null) className = "java.lang.String"; @@ -238,26 +233,11 @@ } } - String fragment = n.getAttributeValue("fragment"); - if (fragment != null) { - if (declareStr != null || scopeStr != null) { - err.jspError(n, "jsp.error.fragmentWithDeclareOrScope"); - } - - // Find the attribute node with matching name - Node.AttributeDirective attributeDirective = - (Node.AttributeDirective) fragmentAttributesMap.get(fragment); - if (attributeDirective == null) { - err.jspError(n, "jsp.error.nomatching.fragment", fragment); - } - variableVector.addElement( - new TagVariableInfo(nameGiven, nameFromAttribute, - className, declare, scope, fragment)); - } else { - variableVector.addElement( - new TagVariableInfo(nameGiven, nameFromAttribute, - className, declare, scope)); - } + variableVector.addElement(new TagVariableInfo(nameGiven, + null, + className, + declare, + scope)); } public TagInfo getTagInfo() { @@ -339,7 +319,7 @@ */ private Class loadTagFile(Compiler compiler, String tagFilePath, TagInfo tagInfo, - TagData tagData, PageInfo parentPageInfo) + PageInfo parentPageInfo) throws JasperException { JspCompilationContext ctxt = compiler.getCompilationContext(); @@ -350,12 +330,11 @@ synchronized(rctxt) { if (wrapper == null) { wrapper = new JspServletWrapper(ctxt.getServletContext(), - ctxt.getOptions(), - tagFilePath, - tagInfo, - tagData, - ctxt.getRuntimeContext(), - ctxt.getTagFileJars()); + ctxt.getOptions(), + tagFilePath, + tagInfo, + ctxt.getRuntimeContext(), + ctxt.getTagFileJars()); rctxt.addWrapper(tagFilePath,wrapper); } @@ -373,7 +352,6 @@ ctxt.getOptions(), tagFilePath, tagInfo, - tagData, ctxt.getRuntimeContext(), ctxt.getTagFileJars()); tagClass = tempWrapper.loadTagFilePrototype(); @@ -423,7 +401,7 @@ String tagFilePath = tagFileInfo.getPath(); pageInfo.addDependant(tagFilePath); Class c = loadTagFile(compiler, tagFilePath, n.getTagInfo(), - n.getTagData(), pageInfo); + pageInfo); n.setTagHandlerClass(c); } visitBody(n); 1.21 +4 -7 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java Index: TagLibraryInfoImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- TagLibraryInfoImpl.java 17 Oct 2002 21:38:56 -0000 1.20 +++ TagLibraryInfoImpl.java 28 Oct 2002 18:16:20 -0000 1.21 @@ -523,7 +523,6 @@ String className = "java.lang.String"; boolean declare = true; int scope = VariableInfo.NESTED; - String fragment = null; Iterator list = elem.findChildren(); while (list.hasNext()) { @@ -550,8 +549,6 @@ scope = VariableInfo.AT_END; } } - } else if ("fragment".equals(tname)) { - fragment = element.getBody(); } else if ("description".equals(tname) || // Ignored elements false ) { } else { @@ -561,7 +558,7 @@ } } return new TagVariableInfo(nameGiven, nameFromAttribute, - className, declare, scope, fragment); + className, declare, scope); } private TagLibraryValidator createValidator(TreeNode elem) { 1.48 +3 -91 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java Index: Validator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- Validator.java 23 Oct 2002 19:26:36 -0000 1.47 +++ Validator.java 28 Oct 2002 18:16:20 -0000 1.48 @@ -343,7 +343,6 @@ private PageInfo pageInfo; private ErrorDispatcher err; private TagInfo tagInfo; - private TagData tagData; private ClassLoader loader; // A FunctionMapper, used to validate EL expressions. @@ -428,7 +427,6 @@ this.pageInfo = compiler.getPageInfo(); this.err = compiler.getErrorDispatcher(); this.tagInfo = compiler.getCompilationContext().getTagInfo(); - this.tagData = compiler.getCompilationContext().getTagData(); this.loader = compiler.getCompilationContext().getClassLoader(); this.functionMapper = new ValidatorFunctionMapper( this.pageInfo, this.err, this.loader ); @@ -956,54 +954,6 @@ && n.getAttributeValue("varReader") != null) { err.jspError(n, "jsp.error.invoke.varAndVarReader"); } - - Node.Nodes subelements = n.getBody(); - if (subelements != null) { - for (int i=0; i<subelements.size(); i++) { - Node subelem = subelements.getNode(i); - if (!(subelem instanceof Node.ParamAction)) { - err.jspError(n, "jsp.error.invoke.invalidBodyContent"); - } - } - } - - /* - * One <jsp:param> element must be present for each variable - * declared using the variable directive that has a 'fragment' - * attribute equal to the name of the fragment being invoked. - */ - TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos(); - if (tagVars != null) { - String frag = n.getAttributeValue("fragment"); - for (int i=0; i<tagVars.length; i++) { - String varName = tagVars[i].getNameGiven(); - if (varName == null) { - varName = tagData.getAttributeString( - tagVars[i].getNameFromAttribute()); - } - String tagVarFrag = tagVars[i].getFragment(); - if (tagVarFrag == null || !tagVarFrag.equals(frag)) - continue; - if (subelements == null) { - err.jspError(n, "jsp.error.invoke.missingParam", - varName); - } - boolean found = false; - for (int j=0; j<subelements.size() && !found; j++) { - Node subelem = subelements.getNode(j); - String paramName = subelem.getAttributeValue("name"); - if (varName.equals(paramName)) { - found = true; - } - } - if (!found) { - err.jspError(n, "jsp.error.invoke.missingParam", - varName); - } - } - } - - visitBody(n); } public void visit(Node.DoBodyAction n) throws JasperException { @@ -1013,44 +963,6 @@ && n.getAttributeValue("varReader") != null) { err.jspError(n, "jsp.error.doBody.varAndVarReader"); } - - Node.Nodes subelements = n.getBody(); - if (subelements != null) { - for (int i=0; i<subelements.size(); i++) { - Node subelem = subelements.getNode(i); - if (!(subelem instanceof Node.ParamAction)) { - err.jspError(n, "jsp.error.doBody.invalidBodyContent"); - } - } - } - - /* - * A translation error must occur if a <jsp:param> is specified - * with the same name as a variable with a scope of AT_BEGIN or - * NESTED. - */ - TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos(); - if (tagVars != null && subelements != null) { - for (int i=0; i<tagVars.length; i++) { - if (tagVars[i].getScope() == VariableInfo.AT_END) - continue; - String varName = tagVars[i].getNameGiven(); - if (varName == null) { - varName = tagData.getAttributeString( - tagVars[i].getNameFromAttribute()); - } - for (int j=0; j<subelements.size(); j++) { - Node subelem = subelements.getNode(j); - String paramName = subelem.getAttributeValue("name"); - if (varName.equals(paramName)) { - err.jspError(n, "jsp.error.doBody.invalidParam", - varName); - } - } - } - } - - visitBody(n); } } 1.6 +168 -42 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspContextWrapper.java Index: JspContextWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspContextWrapper.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JspContextWrapper.java 3 Oct 2002 23:50:11 -0000 1.5 +++ JspContextWrapper.java 28 Oct 2002 18:16:21 -0000 1.6 @@ -66,6 +66,8 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.Vector; +import java.util.Iterator; import javax.servlet.Servlet; import javax.servlet.ServletConfig; @@ -78,8 +80,9 @@ import javax.servlet.jsp.JspContext; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.VariableInfo; +import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.el.ELException; import javax.servlet.jsp.el.ExpressionEvaluator; import javax.servlet.jsp.el.VariableResolver; @@ -93,15 +96,38 @@ * setJspContext(). * * @author Kin-man Chung + * @author Jan Luehe */ -public class JspContextWrapper extends PageContext implements VariableResolver { +public class JspContextWrapper + extends PageContext implements VariableResolver { + + // Invoking JSP context + private PageContext invokingJspCtxt; - private PageContext pageContext; private transient Hashtable pageAttributes; - public JspContextWrapper(JspContext jspContext) { - this.pageContext = (PageContext) jspContext; + // Vector of NESTED scripting variables + private Vector nestedVars; + + // Vector of AT_BEGIN scripting variables + private Vector atBeginVars; + + // Vector of AT_END scripting variables + private Vector atEndVars; + + private Hashtable originalNestedVars; + + public JspContextWrapper(JspContext jspContext, Vector nestedVars, + Vector atBeginVars, Vector atEndVars) { + this.invokingJspCtxt = (PageContext) jspContext; + this.nestedVars = nestedVars; + this.atBeginVars = atBeginVars; + this.atEndVars = atEndVars; this.pageAttributes = new Hashtable(16); + this.originalNestedVars = new Hashtable(nestedVars.size()); + + copyPageToTagScope(VariableInfo.AT_BEGIN); + saveNestedVariables(); } public void initialize(Servlet servlet, ServletRequest request, @@ -121,7 +147,7 @@ return pageAttributes.get(name); } - return pageContext.getAttribute(name, scope); + return invokingJspCtxt.getAttribute(name, scope); } public void setAttribute(String name, Object attribute) { @@ -132,36 +158,45 @@ if (scope == PAGE_SCOPE) { pageAttributes.put(name, o); } else { - pageContext.setAttribute(name, o, scope); + invokingJspCtxt.setAttribute(name, o, scope); } } public Object findAttribute(String name) { Object o = pageAttributes.get(name); - if (o != null) - return o; + if (o == null) { + o = invokingJspCtxt.getAttribute(name, REQUEST_SCOPE); + if (o == null) { + if (getSession() != null) { + o = invokingJspCtxt.getAttribute(name, SESSION_SCOPE); + } + if (o == null) { + o = invokingJspCtxt.getAttribute(name, APPLICATION_SCOPE); + } + } + } - return pageContext.findAttribute(name); + return o; + } + + public void removeAttribute(String name) { + removeAttribute(name, PAGE_SCOPE); + invokingJspCtxt.removeAttribute(name); } public void removeAttribute(String name, int scope) { if (scope == PAGE_SCOPE){ pageAttributes.remove(name); } else { - pageContext.removeAttribute(name, scope); + invokingJspCtxt.removeAttribute(name, scope); } } - public void removeAttribute(String name) { - removeAttribute(name, PAGE_SCOPE); - pageContext.removeAttribute(name); - } - public int getAttributesScope(String name) { if (pageAttributes.get(name) != null) { return PAGE_SCOPE; } else { - return pageContext.getAttributesScope(name); + return invokingJspCtxt.getAttributesScope(name); } } @@ -170,55 +205,55 @@ return pageAttributes.keys(); } - return pageContext.getAttributeNamesInScope(scope); + return invokingJspCtxt.getAttributeNamesInScope(scope); } public void release() { - pageContext.release(); + invokingJspCtxt.release(); } public JspWriter getOut() { - return pageContext.getOut(); + return invokingJspCtxt.getOut(); } public HttpSession getSession() { - return pageContext.getSession(); + return invokingJspCtxt.getSession(); } public Object getPage() { - return pageContext.getPage(); + return invokingJspCtxt.getPage(); } public ServletRequest getRequest() { - return pageContext.getRequest(); + return invokingJspCtxt.getRequest(); } public ServletResponse getResponse() { - return pageContext.getResponse(); + return invokingJspCtxt.getResponse(); } public Exception getException() { - return pageContext.getException(); + return invokingJspCtxt.getException(); } public ServletConfig getServletConfig() { - return pageContext.getServletConfig(); + return invokingJspCtxt.getServletConfig(); } public ServletContext getServletContext() { - return pageContext.getServletContext(); + return invokingJspCtxt.getServletContext(); } public void forward(String relativeUrlPath) throws ServletException, IOException { - pageContext.forward(relativeUrlPath); + invokingJspCtxt.forward(relativeUrlPath); } public void include(String relativeUrlPath) throws ServletException, IOException { - pageContext.include(relativeUrlPath); + invokingJspCtxt.include(relativeUrlPath); } public void include(String relativeUrlPath, boolean flush) @@ -231,19 +266,19 @@ } public BodyContent pushBody() { - return pageContext.pushBody(); + return invokingJspCtxt.pushBody(); } public JspWriter pushBody(Writer writer) { - return pageContext.pushBody(writer); + return invokingJspCtxt.pushBody(writer); } public JspWriter popBody() { - return pageContext.popBody(); + return invokingJspCtxt.popBody(); } public ExpressionEvaluator getExpressionEvaluator() { - return pageContext.getExpressionEvaluator(); + return invokingJspCtxt.getExpressionEvaluator(); } public void handlePageException(Exception ex) @@ -257,7 +292,7 @@ public void handlePageException(Throwable t) throws IOException, ServletException { - pageContext.handlePageException(t); + invokingJspCtxt.handlePageException(t); } /** @@ -266,12 +301,103 @@ public Object resolveVariable( String pName, Object pContext ) throws ELException { - if (pageContext instanceof PageContextImpl) { - return ((PageContextImpl)pageContext). - resolveVariable(pName, pContext); + if (invokingJspCtxt instanceof PageContextImpl) { + return ((PageContextImpl) invokingJspCtxt).resolveVariable(pName, + pContext); } - return ((JspContextWrapper)pageContext). - resolveVariable(pName, pContext); + return ((JspContextWrapper) invokingJspCtxt).resolveVariable(pName, + pContext); + } + + /** + * Copies the variables of the given scope from the page scope of the + * invoking JSP context to the virtual page scope of this JSP context + * wrapper. + * + * @param scope variable scope (one of NESTED or AT_BEGIN) + */ + public void copyPageToTagScope(int scope) { + Iterator iter = null; + + switch (scope) { + case VariableInfo.NESTED: + iter = nestedVars.iterator(); + break; + case VariableInfo.AT_BEGIN: + iter = atBeginVars.iterator(); + break; + } + + while (iter.hasNext()) { + String varName = (String) iter.next(); + Object obj = invokingJspCtxt.getAttribute(varName); + if (obj != null) { + setAttribute(varName, obj); + } + } + } + + /** + * Copies the variables of the given scope from the virtual page scope of + * this JSP context wrapper to the page scope of the invoking JSP context. + * + * @param scope variable scope (one of NESTED, AT_BEGIN, or AT_END) + */ + public void copyTagToPageScope(int scope) { + Iterator iter = null; + + switch (scope) { + case VariableInfo.NESTED: + iter = nestedVars.iterator(); + break; + case VariableInfo.AT_BEGIN: + iter = atBeginVars.iterator(); + break; + case VariableInfo.AT_END: + iter = atEndVars.iterator(); + break; + } + + while (iter.hasNext()) { + String varName = (String) iter.next(); + Object obj = getAttribute(varName); + if (obj != null) { + invokingJspCtxt.setAttribute(varName, obj); + } + } + } + + /** + * Saves the values of any NESTED variables that are present in + * the invoking JSP context, so they can later be restored. + */ + public void saveNestedVariables() { + Iterator iter = nestedVars.iterator(); + while (iter.hasNext()) { + String varName = (String) iter.next(); + Object obj = invokingJspCtxt.getAttribute(varName); + if (obj != null) { + originalNestedVars.put(varName, obj); + } + } + } + + /** + * Restores the values of any NESTED variables in the invoking JSP + * context. + */ + public void restoreNestedVariables() { + Iterator iter = nestedVars.iterator(); + while (iter.hasNext()) { + String varName = (String) iter.next(); + Object obj = originalNestedVars.get(varName); + if (obj != null) { + invokingJspCtxt.setAttribute(varName, obj); + } else { + invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE); + } + } } } + 1.5 +3 -52 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspFragmentHelper.java Index: JspFragmentHelper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspFragmentHelper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JspFragmentHelper.java 21 Aug 2002 16:21:56 -0000 1.4 +++ JspFragmentHelper.java 28 Oct 2002 18:16:21 -0000 1.5 @@ -111,53 +111,4 @@ return this.parentTag; } - /** - * Takes a snapshot of the current JspContext and stores - * the results in a Map for later restoration. Also sets the - * new values in the page context, given the provided parameters. - * - * @param params the parameters to set in the page scope - * @return A map that contains a snapshot of the old page scope. - */ - protected Map preparePageScope( Map params ) { - Map originalValues = new HashMap(); - Iterator keys = params.keySet().iterator(); - while( keys.hasNext() ) { - String key = (String)keys.next(); - // Remember original values to restore later - originalValues.put( key, jspContext.getAttribute( key ) ); - // Set new values, based on params - Object newValue = params.get( key ); - if( newValue != null ) { - jspContext.setAttribute( key, newValue ); - } - else { - jspContext.removeAttribute( key ); - } - } - return originalValues; - } - - /** - * Restores the state of the page scope in the current page context, - * from the given map. - * - * @param originalValues the values to restore in the page context. - */ - protected void restorePageScope( Map originalValues ) { - Iterator keys = originalValues.keySet().iterator(); - while( keys.hasNext() ) { - String key = (String)keys.next(); - Object value = originalValues.get( key ); - if( value == null ) { - // Value to be cleared: - jspContext.removeAttribute( key ); - } - else { - // Value to be restored: - jspContext.setAttribute( key, value ); - } - } - } - } 1.19 +10 -8 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java Index: JspServletWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- JspServletWrapper.java 11 Sep 2002 19:07:33 -0000 1.18 +++ JspServletWrapper.java 28 Oct 2002 18:16:21 -0000 1.19 @@ -136,18 +136,20 @@ /* * JspServletWrapper for tag files. */ - public JspServletWrapper(ServletContext servletContext, Options options, - String tagFilePath, TagInfo tagInfo, - TagData tagData, JspRuntimeContext rctxt, + public JspServletWrapper(ServletContext servletContext, + Options options, + String tagFilePath, + TagInfo tagInfo, + JspRuntimeContext rctxt, Hashtable tagFileJars) - throws JasperException { + throws JasperException { this.isTagFile = true; this.config = null; // not used this.options = options; this.jspUri = tagFilePath; this.tripCount = 0; - ctxt = new JspCompilationContext(jspUri, tagInfo, tagData, options, + ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, tagFileJars); 1.50 +2 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties Index: messages.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- messages.properties 25 Oct 2002 00:57:31 -0000 1.49 +++ messages.properties 28 Oct 2002 18:16:21 -0000 1.50 @@ -79,7 +79,7 @@ jsp.error.mandatory.attribute={0}: Mandatory attribute {1} missing jsp.engine.info=Jasper JSP 1.1 Engine jsp.error.invalid.expression="{0}" contains invalid expression(s): {1} -jsp.error.invalid.attribute={0}: Invalid attribute, {1} +jsp.error.invalid.attribute={0} has invalid attribute: {1} jsp.error.usebean.class.notfound=Class: {0} not found jsp.error.file.cannot.read=Cannot read file: {0} jsp.error.file.already.registered=Recursive include of file {0} @@ -287,10 +287,7 @@ jsp.error.fragmentwithrtexprvalue=Cannot specify both 'fragment' and 'rtexprvalue' attributes. If 'fragment' is present, 'rtexprvalue' is fixed as 'true' jsp.error.fragmentWithDeclareOrScope=Both 'fragment' and 'declare' or 'scope' attributes specified in variable directive jsp.error.invoke.varAndVarReader=Both 'var' and 'varReader' specified in jsp:invoke -jsp.error.invoke.invalidBodyContent=jsp:invoke contains body content other than whitespace and jsp:param subelements -jsp.error.invoke.missingParam=Missing jsp:param subelement for variable {0} jsp.error.doBody.varAndVarReader=Both 'var' and 'varReader' specified in jsp:doBody -jsp.error.doBody.invalidParam=jsp:doBody has a jsp:param subelement with the same name as a variable ({0}) with a scope of AT_BEGIN or NESTED jsp.warning.bad.urlpattern.propertygroup=Bad value {0} in the url-pattern subelement in web.xml jsp.error.unknown_attribute_type=Unknown attribute type ({1}) for attribute {0}. jsp.error.jspelement.missing.name=Mandatory attribute 'name' missing in jsp:element 1.17 +1 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties Index: messages_es.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_es.properties,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- messages_es.properties 9 Oct 2002 20:21:52 -0000 1.16 +++ messages_es.properties 28 Oct 2002 18:16:21 -0000 1.17 @@ -215,9 +215,6 @@ jsp.error.invoke.varAndVarReader= jsp.error.doBody.varAndVarReader= jsp.warning.bad.urlpattern.propertygroup= -jsp.error.invoke.invalidBodyContent= -jsp.error.invoke.missingParam= -jsp.error.doBody.invalidParam= jsp.error.jspelement.missing.name= jsp.error.tagdirective.badbodycontent= jsp.error.page.pageencoding.conflict= 1.17 +1 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties Index: messages_ja.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages_ja.properties,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- messages_ja.properties 9 Oct 2002 20:21:52 -0000 1.16 +++ messages_ja.properties 28 Oct 2002 18:16:21 -0000 1.17 @@ -246,9 +246,6 @@ jsp.error.invoke.varAndVarReader= jsp.error.doBody.varAndVarReader= jsp.warning.bad.urlpattern.propertygroup= -jsp.error.invoke.invalidBodyContent= -jsp.error.invoke.missingParam= -jsp.error.doBody.invalidParam= jsp.error.jspelement.missing.name= jsp.error.tagdirective.badbodycontent= jsp.error.page.pageencoding.conflict=
-- To unsubscribe, e-mail: <mailto:tomcat-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:tomcat-dev-help@;jakarta.apache.org>