javax.servlet.jsp.tagext.TagVariableInfo Java Examples

The following examples show how to use javax.servlet.jsp.tagext.TagVariableInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JasperTagInfo.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);

    this.dynamicAttrsMapName = mapName;
}
 
Example #2
Source File: JasperTagInfo.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);
    
    this.dynamicAttrsMapName = mapName;
}
 
Example #3
Source File: TagFileProcessor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public TagInfo getTagInfo() throws JasperException {

            if (name == null) {
                // XXX Get it from tag file name
            }

            if (bodycontent == null) {
                bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
            }

            String tagClassName = JspUtil.getTagHandlerClassName(
                    path, tagLibInfo.getReliableURN(), err);

            TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
                    .size()];
            variableVector.copyInto(tagVariableInfos);

            TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
                    .size()];
            attributeVector.copyInto(tagAttributeInfo);

            return new JasperTagInfo(name, tagClassName, bodycontent,
                    description, tagLibInfo, tei, tagAttributeInfo,
                    displayName, smallIcon, largeIcon, tagVariableInfos,
                    dynamicAttrsMapName);
        }
 
Example #4
Source File: TagFileProcessor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public TagInfo getTagInfo() throws JasperException {

            if (name == null) {
                // XXX Get it from tag file name
            }

            if (bodycontent == null) {
                bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
            }

            String tagClassName = JspUtil.getTagHandlerClassName(
                    path, tagLibInfo.getReliableURN(), err);

            TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
                    .size()];
            variableVector.copyInto(tagVariableInfos);

            TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
                    .size()];
            attributeVector.copyInto(tagAttributeInfo);

            return new JasperTagInfo(name, tagClassName, bodycontent,
                    description, tagLibInfo, tei, tagAttributeInfo,
                    displayName, smallIcon, largeIcon, tagVariableInfos,
                    dynamicAttrsMapName);
        }
 
Example #5
Source File: TagFileProcessor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public TagInfo getTagInfo() throws JasperException {

            if (name == null) {
                // XXX Get it from tag file name
            }

            if (bodycontent == null) {
                bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
            }

            String tagClassName = JspUtil.getTagHandlerClassName(
                    path, tagLibInfo.getReliableURN(), err);

            TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector
                    .size()];
            variableVector.copyInto(tagVariableInfos);

            TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector
                    .size()];
            attributeVector.copyInto(tagAttributeInfo);

            return new JasperTagInfo(name, tagClassName, bodycontent,
                    description, tagLibInfo, null, tagAttributeInfo,
                    displayName, smallIcon, largeIcon, tagVariableInfos,
                    dynamicAttrsMapName);
        }
 
Example #6
Source File: JasperTagInfo.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public JasperTagInfo(String tagName,
        String tagClassName,
        String bodyContent,
        String infoString,
        TagLibraryInfo taglib,
        TagExtraInfo tagExtraInfo,
        TagAttributeInfo[] attributeInfo,
        String displayName,
        String smallIcon,
        String largeIcon,
        TagVariableInfo[] tvi,
        String mapName) {

    super(tagName, tagClassName, bodyContent, infoString, taglib,
            tagExtraInfo, attributeInfo, displayName, smallIcon, largeIcon,
            tvi);
    
    this.dynamicAttrsMapName = mapName;
}
 
Example #7
Source File: Generator.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private void declareScriptingVars(Node.CustomTag n, int scope) {

            // Skip if the page is scriptless
            if (pageInfo.isScriptless()) return;

            ArrayList<Object> vec = n.getScriptingVars(scope);
            if (vec != null) {
                for (int i = 0; i < vec.size(); i++) {
                    Object elem = vec.get(i);
                    if (elem instanceof VariableInfo) {
                        VariableInfo varInfo = (VariableInfo)elem;
                        if (varInfo.getDeclare()) {
                            out.printin(varInfo.getClassName());
                            out.print(" ");
                            out.print(varInfo.getVarName());
                            out.println(" = null;");
                        }
                    } else {
                        TagVariableInfo tagVarInfo = (TagVariableInfo)elem;
                        if (tagVarInfo.getDeclare()) {
                            String varName = tagVarInfo.getNameGiven();
                            if (varName == null) {
                                varName =
                                    n.getTagData().getAttributeString(
                                        tagVarInfo.getNameFromAttribute());
                            } else if (
                                tagVarInfo.getNameFromAttribute() != null) {
                                // alias
                                continue;
                            }
                            out.printin(tagVarInfo.getClassName());
                            out.print(" ");
                            out.print(varName);
                            out.println(" = null;");
                        }
                    }
                }
            }
        }
 
Example #8
Source File: Generator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Generate code to create a map for the alias variables
 *
 * @return the name of the map
 */
private String generateAliasMap(Node.CustomTag n,
        String tagHandlerVar) {

    TagVariableInfo[] tagVars = n.getTagVariableInfos();
    String aliasMapVar = null;

    boolean aliasSeen = false;
    for (int i = 0; i < tagVars.length; i++) {

        String nameFrom = tagVars[i].getNameFromAttribute();
        if (nameFrom != null) {
            String aliasedName = n.getAttributeValue(nameFrom);
            if (aliasedName == null)
                continue;

            if (!aliasSeen) {
                out.printin("java.util.HashMap ");
                aliasMapVar = tagHandlerVar + "_aliasMap";
                out.print(aliasMapVar);
                out.println(" = new java.util.HashMap();");
                aliasSeen = true;
            }
            out.printin(aliasMapVar);
            out.print(".put(");
            out.print(quote(tagVars[i].getNameGiven()));
            out.print(", ");
            out.print(quote(aliasedName));
            out.println(");");
        }
    }
    return aliasMapVar;
}
 
Example #9
Source File: Generator.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
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;
    }

    List<Object> vec = n.getScriptingVars(scope);
    if (vec != null) {
        for (int i = 0; i < vec.size(); i++) {
            Object elem = vec.get(i);
            if (elem instanceof VariableInfo) {
                VariableInfo varInfo = (VariableInfo) elem;
                if (varInfo.getDeclare()) {
                    out.printin(varInfo.getClassName());
                    out.print(" ");
                    out.print(varInfo.getVarName());
                    out.println(" = null;");
                }
            } else {
                TagVariableInfo tagVarInfo = (TagVariableInfo) elem;
                if (tagVarInfo.getDeclare()) {
                    String varName = tagVarInfo.getNameGiven();
                    if (varName == null) {
                        varName = n.getTagData().getAttributeString(
                                tagVarInfo.getNameFromAttribute());
                    } else if (tagVarInfo.getNameFromAttribute() != null) {
                        // alias
                        continue;
                    }
                    out.printin(tagVarInfo.getClassName());
                    out.print(" ");
                    out.print(varName);
                    out.println(" = null;");
                }
            }
        }
    }
}
 
Example #10
Source File: TagFileProcessor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
        TagLibraryInfo tagLibInfo, String name, String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new Vector<TagAttributeInfo>();
    variableVector = new Vector<TagVariableInfo>();
}
 
Example #11
Source File: TagFileProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
        TagLibraryInfo tagLibInfo, String name, String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new Vector<TagAttributeInfo>();
    variableVector = new Vector<TagVariableInfo>();
}
 
Example #12
Source File: Generator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Generate code to create a map for the alias variables
 *
 * @return the name of the map
 */
private String generateAliasMap(Node.CustomTag n,
        String tagHandlerVar) {

    TagVariableInfo[] tagVars = n.getTagVariableInfos();
    String aliasMapVar = null;

    boolean aliasSeen = false;
    for (int i = 0; i < tagVars.length; i++) {

        String nameFrom = tagVars[i].getNameFromAttribute();
        if (nameFrom != null) {
            String aliasedName = n.getAttributeValue(nameFrom);
            if (aliasedName == null)
                continue;

            if (!aliasSeen) {
                out.printin("java.util.HashMap ");
                aliasMapVar = tagHandlerVar + "_aliasMap";
                out.print(aliasMapVar);
                out.println(" = new java.util.HashMap();");
                aliasSeen = true;
            }
            out.printin(aliasMapVar);
            out.print(".put(");
            out.print(quote(tagVars[i].getNameGiven()));
            out.print(", ");
            out.print(quote(aliasedName));
            out.println(");");
        }
    }
    return aliasMapVar;
}
 
Example #13
Source File: Generator.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
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;
    }

    List<Object> vec = n.getScriptingVars(scope);
    if (vec != null) {
        for (int i = 0; i < vec.size(); i++) {
            Object elem = vec.get(i);
            if (elem instanceof VariableInfo) {
                VariableInfo varInfo = (VariableInfo) elem;
                if (varInfo.getDeclare()) {
                    out.printin(varInfo.getClassName());
                    out.print(" ");
                    out.print(varInfo.getVarName());
                    out.println(" = null;");
                }
            } else {
                TagVariableInfo tagVarInfo = (TagVariableInfo) elem;
                if (tagVarInfo.getDeclare()) {
                    String varName = tagVarInfo.getNameGiven();
                    if (varName == null) {
                        varName = n.getTagData().getAttributeString(
                                tagVarInfo.getNameFromAttribute());
                    } else if (tagVarInfo.getNameFromAttribute() != null) {
                        // alias
                        continue;
                    }
                    out.printin(tagVarInfo.getClassName());
                    out.print(" ");
                    out.print(varName);
                    out.println(" = null;");
                }
            }
        }
    }
}
 
Example #14
Source File: Generator.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Generate code to create a map for the alias variables
 * @return the name of the map
 */
private String generateAliasMap(Node.CustomTag n, String tagHandlerVar)
    throws JasperException {

    TagVariableInfo[] tagVars = n.getTagVariableInfos();
    String aliasMapVar = null;

    boolean aliasSeen = false;
    for (int i = 0; i < tagVars.length; i++) {

        String nameFrom = tagVars[i].getNameFromAttribute();
        if (nameFrom != null) {
            String aliasedName = n.getAttributeValue(nameFrom);
            if (aliasedName == null)
                continue;

            if (!aliasSeen) {
                out.printin("java.util.HashMap ");
                aliasMapVar = tagHandlerVar + "_aliasMap";
                out.print(aliasMapVar);
                out.println(" = new java.util.HashMap();");
                aliasSeen = true;
            }
            out.printin(aliasMapVar);
            out.print(".put(");
            out.print(quote(tagVars[i].getNameGiven()));
            out.print(", ");
            out.print(quote(aliasedName));
            out.println(");");
        }
    }
    return aliasMapVar;
}
 
Example #15
Source File: Generator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Generate code to create a map for the alias variables
 *
 * @return the name of the map
 */
private String generateAliasMap(Node.CustomTag n,
        String tagHandlerVar) {

    TagVariableInfo[] tagVars = n.getTagVariableInfos();
    String aliasMapVar = null;

    boolean aliasSeen = false;
    for (int i = 0; i < tagVars.length; i++) {

        String nameFrom = tagVars[i].getNameFromAttribute();
        if (nameFrom != null) {
            String aliasedName = n.getAttributeValue(nameFrom);
            if (aliasedName == null)
                continue;

            if (!aliasSeen) {
                out.printin("java.util.HashMap ");
                aliasMapVar = tagHandlerVar + "_aliasMap";
                out.print(aliasMapVar);
                out.println(" = new java.util.HashMap();");
                aliasSeen = true;
            }
            out.printin(aliasMapVar);
            out.print(".put(");
            out.print(quote(tagVars[i].getNameGiven()));
            out.print(", ");
            out.print(quote(aliasedName));
            out.println(");");
        }
    }
    return aliasMapVar;
}
 
Example #16
Source File: TagFileProcessor.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public TagFileDirectiveVisitor(Compiler compiler,
                               TagLibraryInfo tagLibInfo,
                               String name,
                               String path) {
    err = compiler.getErrorDispatcher();
    this.tagLibInfo = tagLibInfo;
    this.name = name;
    this.path = path;
    attributeVector = new ArrayList<TagAttributeInfo>();
    variableVector = new ArrayList<TagVariableInfo>();

    jspVersionDouble = Double.valueOf(tagLibInfo.getRequiredVersion());
}
 
Example #17
Source File: Generator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
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;
    }

    List<Object> vec = n.getScriptingVars(scope);
    if (vec != null) {
        for (int i = 0; i < vec.size(); i++) {
            Object elem = vec.get(i);
            if (elem instanceof VariableInfo) {
                VariableInfo varInfo = (VariableInfo) elem;
                if (varInfo.getDeclare()) {
                    out.printin(varInfo.getClassName());
                    out.print(" ");
                    out.print(varInfo.getVarName());
                    out.println(" = null;");
                }
            } else {
                TagVariableInfo tagVarInfo = (TagVariableInfo) elem;
                if (tagVarInfo.getDeclare()) {
                    String varName = tagVarInfo.getNameGiven();
                    if (varName == null) {
                        varName = n.getTagData().getAttributeString(
                                tagVarInfo.getNameFromAttribute());
                    } else if (tagVarInfo.getNameFromAttribute() != null) {
                        // alias
                        continue;
                    }
                    out.printin(tagVarInfo.getClassName());
                    out.print(" ");
                    out.print(varName);
                    out.println(" = null;");
                }
            }
        }
    }
}
 
Example #18
Source File: TagFileProcessor.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public TagInfo getTagInfo() throws JasperException {

            if (name == null) {
                // XXX Get it from tag file name
            }

            if (bodycontent == null) {
                bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS;
            }

            String tagClassName = JspUtil.getTagHandlerClassName(path, err);

            TagVariableInfo[] tagVariableInfos
                = variableVector.toArray(new TagVariableInfo[0]);

            TagAttributeInfo[] tagAttributeInfo
                = attributeVector.toArray(new TagAttributeInfo[0]);

            return new JasperTagInfo(name,
			       tagClassName,
			       bodycontent,
			       description,
			       tagLibInfo,
			       tei,
			       tagAttributeInfo,
			       displayName,
			       smallIcon,
			       largeIcon,
			       tagVariableInfos,
			       dynamicAttrsMapName);
        }
 
Example #19
Source File: TagFileProcessor.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Node.VariableDirective n) throws JasperException {

    JspUtil.checkAttributes("Variable directive", n,
            variableDirectiveAttrs, err);

    String nameGiven = n.getAttributeValue("name-given");
    String nameFromAttribute = n
            .getAttributeValue("name-from-attribute");
    if (nameGiven == null && nameFromAttribute == null) {
        err.jspError("jsp.error.variable.either.name");
    }

    if (nameGiven != null && nameFromAttribute != null) {
        err.jspError("jsp.error.variable.both.name");
    }

    String alias = n.getAttributeValue("alias");
    if (nameFromAttribute != null && alias == null
            || nameFromAttribute == null && alias != null) {
        err.jspError("jsp.error.variable.alias");
    }

    String className = n.getAttributeValue("variable-class");
    if (className == null)
        className = "java.lang.String";

    String declareStr = n.getAttributeValue("declare");
    boolean declare = true;
    if (declareStr != null)
        declare = JspUtil.booleanValue(declareStr);

    int scope = VariableInfo.NESTED;
    String scopeStr = n.getAttributeValue("scope");
    if (scopeStr != null) {
        if ("NESTED".equals(scopeStr)) {
            // Already the default
        } else if ("AT_BEGIN".equals(scopeStr)) {
            scope = VariableInfo.AT_BEGIN;
        } else if ("AT_END".equals(scopeStr)) {
            scope = VariableInfo.AT_END;
        }
    }

    if (nameFromAttribute != null) {
        /*
         * An alias has been specified. We use 'nameGiven' to hold the
         * value of the alias, and 'nameFromAttribute' to hold the name
         * of the attribute whose value (at invocation-time) denotes the
         * name of the variable that is being aliased
         */
        nameGiven = alias;
        checkUniqueName(nameFromAttribute, VAR_NAME_FROM, n);
        checkUniqueName(alias, VAR_ALIAS, n);
    } else {
        // name-given specified
        checkUniqueName(nameGiven, VAR_NAME_GIVEN, n);
    }

    variableVector.addElement(new TagVariableInfo(nameGiven,
            nameFromAttribute, className, declare, scope));
}
 
Example #20
Source File: Node.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public TagVariableInfo[] getTagVariableInfos() {
   return tagInfo.getTagVariableInfos();
}
 
Example #21
Source File: Generator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void syncScriptingVars(Node.CustomTag n, int scope) {

            // Skip if the page is scriptless
            if (pageInfo.isScriptless()) return;

            TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
            VariableInfo[] varInfos = n.getVariableInfos();

            if ((varInfos.length == 0) && (tagVarInfos.length == 0)) {
                return;
            }

            if (varInfos.length > 0) {
                for (int i = 0; i < varInfos.length; i++) {
                    if (varInfos[i].getScope() == scope) {
                        out.printin(varInfos[i].getVarName());
                        out.print(" = (");
                        out.print(varInfos[i].getClassName());
                        out.print(") _jspx_page_context.findAttribute(");
                        out.print(quote(varInfos[i].getVarName()));
                        out.println(");");
                    }
                }
            } else {
                for (int i = 0; i < tagVarInfos.length; i++) {
                    if (tagVarInfos[i].getScope() == scope) {
                        String name = tagVarInfos[i].getNameGiven();
                        if (name == null) {
                            name =
                                n.getTagData().getAttributeString(
                                    tagVarInfos[i].getNameFromAttribute());
                        } else if (
                            tagVarInfos[i].getNameFromAttribute() != null) {
                            // alias
                            continue;
                        }
                        out.printin(name);
                        out.print(" = (");
                        out.print(tagVarInfos[i].getClassName());
                        out.print(") _jspx_page_context.findAttribute(");
                        out.print(quote(name));
                        out.println(");");
                    }
                }
            }
        }
 
Example #22
Source File: Generator.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void generateSetJspContext(TagInfo tagInfo) {

        boolean nestedSeen = false;
        boolean atBeginSeen = false;
        boolean atEndSeen = false;

        // Determine if there are any aliases
        boolean aliasSeen = false;
        TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
        for (int i = 0; i < tagVars.length; i++) {
            if (tagVars[i].getNameFromAttribute() != null
                && tagVars[i].getNameGiven() != null) {
                aliasSeen = true;
                break;
            }
        }

        if (aliasSeen) {
            out.printil(
                "public void setJspContext(JspContext ctx, java.util.Map aliasMap) {");
        } else {
            out.printil("public void setJspContext(JspContext ctx) {");
        }
        out.pushIndent();
        out.printil("super.setJspContext(ctx);");
        out.printil("java.util.ArrayList<String> _jspx_nested = null;");
        out.printil("java.util.ArrayList<String> _jspx_at_begin = null;");
        out.printil("java.util.ArrayList<String> _jspx_at_end = null;");

        for (int i = 0; i < tagVars.length; i++) {

            switch (tagVars[i].getScope()) {
                case VariableInfo.NESTED :
                    if (!nestedSeen) {
                        out.printil(
                            "_jspx_nested = new java.util.ArrayList<String>();");
                        nestedSeen = true;
                    }
                    out.printin("_jspx_nested.add(");
                    break;

                case VariableInfo.AT_BEGIN :
                    if (!atBeginSeen) {
                        out.printil(
                            "_jspx_at_begin = new java.util.ArrayList<String>();");
                        atBeginSeen = true;
                    }
                    out.printin("_jspx_at_begin.add(");
                    break;

                case VariableInfo.AT_END :
                    if (!atEndSeen) {
                        out.printil(
                            "_jspx_at_end = new java.util.ArrayList<String>();");
                        atEndSeen = true;
                    }
                    out.printin("_jspx_at_end.add(");
                    break;
            } // switch

            out.print(quote(tagVars[i].getNameGiven()));
            out.println(");");
        }
        if (aliasSeen) {
            out.printil(
                "this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, aliasMap);");
        } else {
            out.printil(
                "this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, null);");
        }
        out.popIndent();
        out.printil("}");
        out.println();
        out.printil("public JspContext getJspContext() {");
        out.pushIndent();
        out.printil("return this.jspContext;");
        out.popIndent();
        out.printil("}");
    }
 
Example #23
Source File: TagFileProcessor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Node.VariableDirective n) throws JasperException {

    JspUtil.checkAttributes("Variable directive", n,
            variableDirectiveAttrs, err);

    String nameGiven = n.getAttributeValue("name-given");
    String nameFromAttribute = n
            .getAttributeValue("name-from-attribute");
    if (nameGiven == null && nameFromAttribute == null) {
        err.jspError("jsp.error.variable.either.name");
    }

    if (nameGiven != null && nameFromAttribute != null) {
        err.jspError("jsp.error.variable.both.name");
    }

    String alias = n.getAttributeValue("alias");
    if (nameFromAttribute != null && alias == null
            || nameFromAttribute == null && alias != null) {
        err.jspError("jsp.error.variable.alias");
    }

    String className = n.getAttributeValue("variable-class");
    if (className == null)
        className = "java.lang.String";

    String declareStr = n.getAttributeValue("declare");
    boolean declare = true;
    if (declareStr != null)
        declare = JspUtil.booleanValue(declareStr);

    int scope = VariableInfo.NESTED;
    String scopeStr = n.getAttributeValue("scope");
    if (scopeStr != null) {
        if ("NESTED".equals(scopeStr)) {
            // Already the default
        } else if ("AT_BEGIN".equals(scopeStr)) {
            scope = VariableInfo.AT_BEGIN;
        } else if ("AT_END".equals(scopeStr)) {
            scope = VariableInfo.AT_END;
        }
    }

    if (nameFromAttribute != null) {
        /*
         * An alias has been specified. We use 'nameGiven' to hold the
         * value of the alias, and 'nameFromAttribute' to hold the name
         * of the attribute whose value (at invocation-time) denotes the
         * name of the variable that is being aliased
         */
        nameGiven = alias;
        checkUniqueName(nameFromAttribute, VAR_NAME_FROM, n);
        checkUniqueName(alias, VAR_ALIAS, n);
    } else {
        // name-given specified
        checkUniqueName(nameGiven, VAR_NAME_GIVEN, n);
    }

    variableVector.addElement(new TagVariableInfo(nameGiven,
            nameFromAttribute, className, declare, scope));
}
 
Example #24
Source File: TagFileProcessor.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public void visit(Node.VariableDirective n) throws JasperException {

            JspUtil.checkAttributes("Variable directive", n,
                                    variableDirectiveAttrs, err);

            String nameGiven = n.getAttributeValue("name-given");
            String nameFromAttribute = n.getAttributeValue("name-from-attribute");
            if (nameGiven == null && nameFromAttribute == null) {
                err.jspError("jsp.error.variable.either.name");
            }

            if (nameGiven != null && nameFromAttribute != null) {
                err.jspError("jsp.error.variable.both.name");
            }

            String alias = n.getAttributeValue("alias");
            if (nameFromAttribute != null && alias == null ||
                nameFromAttribute == null && alias != null) {
                err.jspError("jsp.error.variable.alias");
            }

            String className = n.getAttributeValue("variable-class");
            if (className == null)
                className = "java.lang.String";

            String declareStr = n.getAttributeValue("declare");
            boolean declare = true;
            if (declareStr != null)
                declare = JspUtil.booleanValue(declareStr);

            int scope = VariableInfo.NESTED;
            String scopeStr = n.getAttributeValue("scope");
            if (scopeStr != null) {
                if ("NESTED".equals(scopeStr)) {
                    // Already the default
                } else if ("AT_BEGIN".equals(scopeStr)) {
                    scope = VariableInfo.AT_BEGIN;
                } else if ("AT_END".equals(scopeStr)) {
                    scope = VariableInfo.AT_END;
                }
            }

            if (nameFromAttribute != null) {
                /*
		 * An alias has been specified. We use 'nameGiven' to hold the
		 * value of the alias, and 'nameFromAttribute' to hold the 
		 * name of the attribute whose value (at invocation-time)
		 * denotes the name of the variable that is being aliased
		 */
                nameGiven = alias;
                checkUniqueName(nameFromAttribute, Name.VAR_NAME_FROM, n);
                checkUniqueName(alias, Name.VAR_ALIAS, n);
            }
            else {
                // name-given specified
                checkUniqueName(nameGiven, Name.VAR_NAME_GIVEN, n);
            }
                
            variableVector.add(new TagVariableInfo(
                                                nameGiven,
                                                nameFromAttribute,
                                                className,
                                                declare,
                                                scope));
        }
 
Example #25
Source File: Generator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void generateSetJspContext(TagInfo tagInfo) {

        boolean nestedSeen = false;
        boolean atBeginSeen = false;
        boolean atEndSeen = false;

        // Determine if there are any aliases
        boolean aliasSeen = false;
        TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
        for (int i = 0; i < tagVars.length; i++) {
            if (tagVars[i].getNameFromAttribute() != null
                    && tagVars[i].getNameGiven() != null) {
                aliasSeen = true;
                break;
            }
        }

        if (aliasSeen) {
            out.printil("public void setJspContext(javax.servlet.jsp.JspContext ctx, java.util.Map aliasMap) {");
        } else {
            out.printil("public void setJspContext(javax.servlet.jsp.JspContext ctx) {");
        }
        out.pushIndent();
        out.printil("super.setJspContext(ctx);");
        out.printil("java.util.ArrayList _jspx_nested = null;");
        out.printil("java.util.ArrayList _jspx_at_begin = null;");
        out.printil("java.util.ArrayList _jspx_at_end = null;");

        for (int i = 0; i < tagVars.length; i++) {

            switch (tagVars[i].getScope()) {
            case VariableInfo.NESTED:
                if (!nestedSeen) {
                    out.printil("_jspx_nested = new java.util.ArrayList();");
                    nestedSeen = true;
                }
                out.printin("_jspx_nested.add(");
                break;

            case VariableInfo.AT_BEGIN:
                if (!atBeginSeen) {
                    out.printil("_jspx_at_begin = new java.util.ArrayList();");
                    atBeginSeen = true;
                }
                out.printin("_jspx_at_begin.add(");
                break;

            case VariableInfo.AT_END:
                if (!atEndSeen) {
                    out.printil("_jspx_at_end = new java.util.ArrayList();");
                    atEndSeen = true;
                }
                out.printin("_jspx_at_end.add(");
                break;
            } // switch

            out.print(quote(tagVars[i].getNameGiven()));
            out.println(");");
        }
        if (aliasSeen) {
            out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, aliasMap);");
        } else {
            out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, null);");
        }
        out.popIndent();
        out.printil("}");
        out.println();
        out.printil("public javax.servlet.jsp.JspContext getJspContext() {");
        out.pushIndent();
        out.printil("return this.jspContext;");
        out.popIndent();
        out.printil("}");
    }
 
Example #26
Source File: Generator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
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();

    if ((varInfos.length == 0) && (tagVarInfos.length == 0)) {
        return;
    }

    if (varInfos.length > 0) {
        for (int i = 0; i < varInfos.length; i++) {
            if (varInfos[i].getScope() == scope) {
                out.printin(varInfos[i].getVarName());
                out.print(" = (");
                out.print(varInfos[i].getClassName());
                out.print(") _jspx_page_context.findAttribute(");
                out.print(quote(varInfos[i].getVarName()));
                out.println(");");
            }
        }
    } else {
        for (int i = 0; i < tagVarInfos.length; i++) {
            if (tagVarInfos[i].getScope() == scope) {
                String name = tagVarInfos[i].getNameGiven();
                if (name == null) {
                    name = n.getTagData().getAttributeString(
                            tagVarInfos[i].getNameFromAttribute());
                } else if (tagVarInfos[i].getNameFromAttribute() != null) {
                    // alias
                    continue;
                }
                out.printin(name);
                out.print(" = (");
                out.print(tagVarInfos[i].getClassName());
                out.print(") _jspx_page_context.findAttribute(");
                out.print(quote(name));
                out.println(");");
            }
        }
    }
}
 
Example #27
Source File: Node.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public TagVariableInfo[] getTagVariableInfos() {
    return tagInfo.getTagVariableInfos();
}
 
Example #28
Source File: TldRuleSet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public TagVariableInfo toTagVariableInfo() {
    return new TagVariableInfo(nameGiven, nameFromAttribute, className, declare, scope);
}
 
Example #29
Source File: Generator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void generateSetJspContext(TagInfo tagInfo) {

        boolean nestedSeen = false;
        boolean atBeginSeen = false;
        boolean atEndSeen = false;

        // Determine if there are any aliases
        boolean aliasSeen = false;
        TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
        for (int i = 0; i < tagVars.length; i++) {
            if (tagVars[i].getNameFromAttribute() != null
                    && tagVars[i].getNameGiven() != null) {
                aliasSeen = true;
                break;
            }
        }

        if (aliasSeen) {
            out.printil("public void setJspContext(javax.servlet.jsp.JspContext ctx, java.util.Map aliasMap) {");
        } else {
            out.printil("public void setJspContext(javax.servlet.jsp.JspContext ctx) {");
        }
        out.pushIndent();
        out.printil("super.setJspContext(ctx);");
        out.printil("java.util.ArrayList _jspx_nested = null;");
        out.printil("java.util.ArrayList _jspx_at_begin = null;");
        out.printil("java.util.ArrayList _jspx_at_end = null;");

        for (int i = 0; i < tagVars.length; i++) {

            switch (tagVars[i].getScope()) {
            case VariableInfo.NESTED:
                if (!nestedSeen) {
                    out.printil("_jspx_nested = new java.util.ArrayList();");
                    nestedSeen = true;
                }
                out.printin("_jspx_nested.add(");
                break;

            case VariableInfo.AT_BEGIN:
                if (!atBeginSeen) {
                    out.printil("_jspx_at_begin = new java.util.ArrayList();");
                    atBeginSeen = true;
                }
                out.printin("_jspx_at_begin.add(");
                break;

            case VariableInfo.AT_END:
                if (!atEndSeen) {
                    out.printil("_jspx_at_end = new java.util.ArrayList();");
                    atEndSeen = true;
                }
                out.printin("_jspx_at_end.add(");
                break;
            } // switch

            out.print(quote(tagVars[i].getNameGiven()));
            out.println(");");
        }
        if (aliasSeen) {
            out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, aliasMap);");
        } else {
            out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, null);");
        }
        out.popIndent();
        out.printil("}");
        out.println();
        out.printil("public javax.servlet.jsp.JspContext getJspContext() {");
        out.pushIndent();
        out.printil("return this.jspContext;");
        out.popIndent();
        out.printil("}");
    }
 
Example #30
Source File: Generator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
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();

    if ((varInfos.length == 0) && (tagVarInfos.length == 0)) {
        return;
    }

    if (varInfos.length > 0) {
        for (int i = 0; i < varInfos.length; i++) {
            if (varInfos[i].getScope() == scope) {
                out.printin(varInfos[i].getVarName());
                out.print(" = (");
                out.print(varInfos[i].getClassName());
                out.print(") _jspx_page_context.findAttribute(");
                out.print(quote(varInfos[i].getVarName()));
                out.println(");");
            }
        }
    } else {
        for (int i = 0; i < tagVarInfos.length; i++) {
            if (tagVarInfos[i].getScope() == scope) {
                String name = tagVarInfos[i].getNameGiven();
                if (name == null) {
                    name = n.getTagData().getAttributeString(
                            tagVarInfos[i].getNameFromAttribute());
                } else if (tagVarInfos[i].getNameFromAttribute() != null) {
                    // alias
                    continue;
                }
                out.printin(name);
                out.print(" = (");
                out.print(tagVarInfos[i].getClassName());
                out.print(") _jspx_page_context.findAttribute(");
                out.print(quote(name));
                out.println(");");
            }
        }
    }
}