Search in sources :

Example 1 with TagVariableInfo

use of javax.servlet.jsp.tagext.TagVariableInfo in project sling by apache.

the class Generator method declareTemporaryScriptingVars.

private void declareTemporaryScriptingVars(Node.Nodes page) throws JasperException {
    class ScriptingVarVisitor extends Node.Visitor {

        private Vector vars;

        ScriptingVarVisitor() {
            vars = new Vector();
        }

        @Override
        public void visit(Node.CustomTag n) throws JasperException {
            if (n.getCustomNestingLevel() > 0) {
                TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
                VariableInfo[] varInfos = n.getVariableInfos();
                if (varInfos.length > 0) {
                    for (int i = 0; i < varInfos.length; i++) {
                        String varName = varInfos[i].getVarName();
                        String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel();
                        if (!vars.contains(tmpVarName)) {
                            vars.add(tmpVarName);
                            out.printin(varInfos[i].getClassName());
                            out.print(" ");
                            out.print(tmpVarName);
                            out.print(" = ");
                            out.print(null);
                            out.println(";");
                        }
                    }
                } else {
                    for (int i = 0; i < tagVarInfos.length; i++) {
                        String varName = tagVarInfos[i].getNameGiven();
                        if (varName == null) {
                            varName = n.getTagData().getAttributeString(tagVarInfos[i].getNameFromAttribute());
                        } else if (tagVarInfos[i].getNameFromAttribute() != null) {
                            // alias
                            continue;
                        }
                        String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel();
                        if (!vars.contains(tmpVarName)) {
                            vars.add(tmpVarName);
                            out.printin(tagVarInfos[i].getClassName());
                            out.print(" ");
                            out.print(tmpVarName);
                            out.print(" = ");
                            out.print(null);
                            out.println(";");
                        }
                    }
                }
            }
            visitBody(n);
        }
    }
    page.visit(new ScriptingVarVisitor());
}
Also used : VariableInfo(javax.servlet.jsp.tagext.VariableInfo) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo) Vector(java.util.Vector)

Example 2 with TagVariableInfo

use of javax.servlet.jsp.tagext.TagVariableInfo in project sling by apache.

the class TagLibraryInfoImpl method createTagInfo.

private TagInfo createTagInfo(TreeNode elem, String jspVersion) throws JasperException {
    String tagName = null;
    String tagClassName = null;
    String teiClassName = null;
    /*
         * Default body content for JSP 1.2 tag handlers (<body-content> has
         * become mandatory in JSP 2.0, because the default would be invalid for
         * simple tag handlers)
         */
    String bodycontent = "JSP";
    String info = null;
    String displayName = null;
    String smallIcon = null;
    String largeIcon = null;
    boolean dynamicAttributes = false;
    Vector attributeVector = new Vector();
    Vector variableVector = new Vector();
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("name".equals(tname)) {
            tagName = element.getBody();
        } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) {
            tagClassName = element.getBody();
        } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) {
            teiClassName = element.getBody();
        } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) {
            bodycontent = element.getBody();
        } else if ("display-name".equals(tname)) {
            displayName = element.getBody();
        } else if ("small-icon".equals(tname)) {
            smallIcon = element.getBody();
        } else if ("large-icon".equals(tname)) {
            largeIcon = element.getBody();
        } else if ("icon".equals(tname)) {
            TreeNode icon = element.findChild("small-icon");
            if (icon != null) {
                smallIcon = icon.getBody();
            }
            icon = element.findChild("large-icon");
            if (icon != null) {
                largeIcon = icon.getBody();
            }
        } else if ("info".equals(tname) || "description".equals(tname)) {
            info = element.getBody();
        } else if ("variable".equals(tname)) {
            variableVector.addElement(createVariable(element));
        } else if ("attribute".equals(tname)) {
            attributeVector.addElement(createAttribute(element, jspVersion));
        } else if ("dynamic-attributes".equals(tname)) {
            dynamicAttributes = JspUtil.booleanValue(element.getBody());
        } else if ("example".equals(tname)) {
        // Ignored elements
        } else if ("tag-extension".equals(tname)) {
        // Ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tag", tname));
            }
        }
    }
    TagExtraInfo tei = null;
    if (teiClassName != null && !teiClassName.equals("")) {
        try {
            Class teiClass = ctxt.getClassLoader().loadClass(teiClassName);
            tei = (TagExtraInfo) teiClass.newInstance();
        } catch (Exception e) {
            err.jspError("jsp.error.teiclass.instantiation", teiClassName, e);
        }
    }
    TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()];
    attributeVector.copyInto(tagAttributeInfo);
    TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()];
    variableVector.copyInto(tagVariableInfos);
    TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes);
    return taginfo;
}
Also used : TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) TagExtraInfo(javax.servlet.jsp.tagext.TagExtraInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Iterator(java.util.Iterator) Vector(java.util.Vector)

Example 3 with TagVariableInfo

use of javax.servlet.jsp.tagext.TagVariableInfo in project sling by apache.

the class TagLibraryInfoImpl method createVariable.

TagVariableInfo createVariable(TreeNode elem) {
    String nameGiven = null;
    String nameFromAttribute = null;
    String className = "java.lang.String";
    boolean declare = true;
    int scope = VariableInfo.NESTED;
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("name-given".equals(tname))
            nameGiven = element.getBody();
        else if ("name-from-attribute".equals(tname))
            nameFromAttribute = element.getBody();
        else if ("variable-class".equals(tname))
            className = element.getBody();
        else if ("declare".equals(tname)) {
            String s = element.getBody();
            if (s != null)
                declare = JspUtil.booleanValue(s);
        } else if ("scope".equals(tname)) {
            String s = element.getBody();
            if (s != null) {
                if ("NESTED".equals(s)) {
                    scope = VariableInfo.NESTED;
                } else if ("AT_BEGIN".equals(s)) {
                    scope = VariableInfo.AT_BEGIN;
                } else if ("AT_END".equals(s)) {
                    scope = VariableInfo.AT_END;
                }
            }
        } else if (// Ignored elements
        "description".equals(tname) || false) {
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.variable", tname));
            }
        }
    }
    return new TagVariableInfo(nameGiven, nameFromAttribute, className, declare, scope);
}
Also used : TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo)

Example 4 with TagVariableInfo

use of javax.servlet.jsp.tagext.TagVariableInfo in project tomcat70 by apache.

the class TagLibraryInfoImpl method createTagInfo.

private TagInfo createTagInfo(TreeNode elem, String jspVersion) throws JasperException {
    String tagName = null;
    String tagClassName = null;
    String teiClassName = null;
    /*
         * Default body content for JSP 1.2 tag handlers (<body-content> has
         * become mandatory in JSP 2.0, because the default would be invalid for
         * simple tag handlers)
         */
    String bodycontent = "JSP";
    String info = null;
    String displayName = null;
    String smallIcon = null;
    String largeIcon = null;
    boolean dynamicAttributes = false;
    Vector<TagAttributeInfo> attributeVector = new Vector<TagAttributeInfo>();
    Vector<TagVariableInfo> variableVector = new Vector<TagVariableInfo>();
    Iterator<TreeNode> list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();
        if ("name".equals(tname)) {
            tagName = element.getBody();
        } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) {
            tagClassName = element.getBody();
        } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) {
            teiClassName = element.getBody();
        } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) {
            bodycontent = element.getBody();
        } else if ("display-name".equals(tname)) {
            displayName = element.getBody();
        } else if ("small-icon".equals(tname)) {
            smallIcon = element.getBody();
        } else if ("large-icon".equals(tname)) {
            largeIcon = element.getBody();
        } else if ("icon".equals(tname)) {
            TreeNode icon = element.findChild("small-icon");
            if (icon != null) {
                smallIcon = icon.getBody();
            }
            icon = element.findChild("large-icon");
            if (icon != null) {
                largeIcon = icon.getBody();
            }
        } else if ("info".equals(tname) || "description".equals(tname)) {
            info = element.getBody();
        } else if ("variable".equals(tname)) {
            variableVector.addElement(createVariable(element));
        } else if ("attribute".equals(tname)) {
            attributeVector.addElement(createAttribute(element, jspVersion));
        } else if ("dynamic-attributes".equals(tname)) {
            dynamicAttributes = JspUtil.booleanValue(element.getBody());
        } else if ("example".equals(tname)) {
        // Ignored elements
        } else if ("tag-extension".equals(tname)) {
        // Ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tag", tname));
            }
        }
    }
    TagExtraInfo tei = null;
    if (teiClassName != null && !teiClassName.equals("")) {
        try {
            Class<?> teiClass = ctxt.getClassLoader().loadClass(teiClassName);
            tei = (TagExtraInfo) teiClass.newInstance();
        } catch (Exception e) {
            err.jspError(e, "jsp.error.teiclass.instantiation", teiClassName);
        }
    }
    TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()];
    attributeVector.copyInto(tagAttributeInfo);
    TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()];
    variableVector.copyInto(tagVariableInfos);
    TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes);
    return taginfo;
}
Also used : TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo) JasperException(org.apache.jasper.JasperException) FileNotFoundException(java.io.FileNotFoundException) TreeNode(org.apache.jasper.xmlparser.TreeNode) TagExtraInfo(javax.servlet.jsp.tagext.TagExtraInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Vector(java.util.Vector)

Example 5 with TagVariableInfo

use of javax.servlet.jsp.tagext.TagVariableInfo in project tomcat70 by apache.

the class TagLibraryInfoImpl method createVariable.

TagVariableInfo createVariable(TreeNode elem) {
    String nameGiven = null;
    String nameFromAttribute = null;
    String className = "java.lang.String";
    boolean declare = true;
    int scope = VariableInfo.NESTED;
    Iterator<TreeNode> list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();
        if ("name-given".equals(tname))
            nameGiven = element.getBody();
        else if ("name-from-attribute".equals(tname))
            nameFromAttribute = element.getBody();
        else if ("variable-class".equals(tname))
            className = element.getBody();
        else if ("declare".equals(tname)) {
            String s = element.getBody();
            if (s != null)
                declare = JspUtil.booleanValue(s);
        } else if ("scope".equals(tname)) {
            String s = element.getBody();
            if (s != null) {
                if ("NESTED".equals(s)) {
                    scope = VariableInfo.NESTED;
                } else if ("AT_BEGIN".equals(s)) {
                    scope = VariableInfo.AT_BEGIN;
                } else if ("AT_END".equals(s)) {
                    scope = VariableInfo.AT_END;
                }
            }
        } else if (// Ignored elements
        "description".equals(tname) || false) {
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.variable", tname));
            }
        }
    }
    return new TagVariableInfo(nameGiven, nameFromAttribute, className, declare, scope);
}
Also used : TreeNode(org.apache.jasper.xmlparser.TreeNode) TagVariableInfo(javax.servlet.jsp.tagext.TagVariableInfo)

Aggregations

TagVariableInfo (javax.servlet.jsp.tagext.TagVariableInfo)5 Vector (java.util.Vector)3 FileNotFoundException (java.io.FileNotFoundException)2 Iterator (java.util.Iterator)2 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)2 TagExtraInfo (javax.servlet.jsp.tagext.TagExtraInfo)2 TagInfo (javax.servlet.jsp.tagext.TagInfo)2 TreeNode (org.apache.jasper.xmlparser.TreeNode)2 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)2 IOException (java.io.IOException)1 VariableInfo (javax.servlet.jsp.tagext.VariableInfo)1 JasperException (org.apache.jasper.JasperException)1 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)1