Search in sources :

Example 6 with TreeNode

use of org.apache.jasper.xmlparser.TreeNode in project tomcat70 by apache.

the class TagPluginManager method loadTagPlugins.

private void loadTagPlugins(ErrorDispatcher err, InputStream is) throws JasperException {
    String blockExternalString = ctxt.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }
    ParserUtils pu = new ParserUtils(false, blockExternal);
    TreeNode root = pu.parseXMLDocument(TAG_PLUGINS_XML, is);
    if (!TAG_PLUGINS_ROOT_ELEM.equals(root.getName())) {
        err.jspError("jsp.error.plugin.wrongRootElement", TAG_PLUGINS_XML, TAG_PLUGINS_ROOT_ELEM);
    }
    tagPlugins = new HashMap<String, TagPlugin>();
    Iterator<TreeNode> pluginList = root.findChildren("tag-plugin");
    while (pluginList.hasNext()) {
        TreeNode pluginNode = pluginList.next();
        TreeNode tagClassNode = pluginNode.findChild("tag-class");
        if (tagClassNode == null) {
            // Error
            return;
        }
        String tagClass = tagClassNode.getBody().trim();
        TreeNode pluginClassNode = pluginNode.findChild("plugin-class");
        if (pluginClassNode == null) {
            // Error
            return;
        }
        String pluginClassStr = pluginClassNode.getBody();
        TagPlugin tagPlugin = null;
        try {
            Class<?> pluginClass = ctxt.getClassLoader().loadClass(pluginClassStr);
            tagPlugin = (TagPlugin) pluginClass.newInstance();
            tagPlugins.put(tagClass, tagPlugin);
        } catch (Exception e) {
            throw new JasperException(e);
        }
    }
    initialized = true;
}
Also used : JasperException(org.apache.jasper.JasperException) TreeNode(org.apache.jasper.xmlparser.TreeNode) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin) ParserUtils(org.apache.jasper.xmlparser.ParserUtils) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Example 7 with TreeNode

use of org.apache.jasper.xmlparser.TreeNode in project tomcat70 by apache.

the class JspConfig method processWebDotXml.

private void processWebDotXml() throws JasperException {
    WebXml webXml = null;
    try {
        webXml = new WebXml(ctxt);
        boolean validate = Boolean.parseBoolean(ctxt.getInitParameter(Constants.XML_VALIDATION_INIT_PARAM));
        String blockExternalString = ctxt.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
        boolean blockExternal;
        if (blockExternalString == null) {
            blockExternal = true;
        } else {
            blockExternal = Boolean.parseBoolean(blockExternalString);
        }
        TreeNode webApp = null;
        if (webXml.getInputSource() != null) {
            ParserUtils pu = new ParserUtils(validate, blockExternal);
            webApp = pu.parseXMLDocument(webXml.getSystemId(), webXml.getInputSource());
        }
        if (webApp == null || getVersion(webApp) < 2.4) {
            defaultIsELIgnored = "true";
            defaultDeferedSyntaxAllowedAsLiteral = "true";
            return;
        }
        if (getVersion(webApp) < 2.5) {
            defaultDeferedSyntaxAllowedAsLiteral = "true";
        }
        TreeNode jspConfig = webApp.findChild("jsp-config");
        if (jspConfig == null) {
            return;
        }
        jspProperties = new Vector<JspPropertyGroup>();
        Iterator<TreeNode> jspPropertyList = jspConfig.findChildren("jsp-property-group");
        while (jspPropertyList.hasNext()) {
            TreeNode element = jspPropertyList.next();
            Iterator<TreeNode> list = element.findChildren();
            Vector<String> urlPatterns = new Vector<String>();
            String pageEncoding = null;
            String scriptingInvalid = null;
            String elIgnored = null;
            String isXml = null;
            Vector<String> includePrelude = new Vector<String>();
            Vector<String> includeCoda = new Vector<String>();
            String deferredSyntaxAllowedAsLiteral = null;
            String trimDirectiveWhitespaces = null;
            String defaultContentType = null;
            String buffer = null;
            String errorOnUndeclaredNamespace = null;
            while (list.hasNext()) {
                element = list.next();
                String tname = element.getName();
                if ("url-pattern".equals(tname))
                    urlPatterns.addElement(element.getBody());
                else if ("page-encoding".equals(tname))
                    pageEncoding = element.getBody();
                else if ("is-xml".equals(tname))
                    isXml = element.getBody();
                else if ("el-ignored".equals(tname))
                    elIgnored = element.getBody();
                else if ("scripting-invalid".equals(tname))
                    scriptingInvalid = element.getBody();
                else if ("include-prelude".equals(tname))
                    includePrelude.addElement(element.getBody());
                else if ("include-coda".equals(tname))
                    includeCoda.addElement(element.getBody());
                else if ("deferred-syntax-allowed-as-literal".equals(tname))
                    deferredSyntaxAllowedAsLiteral = element.getBody();
                else if ("trim-directive-whitespaces".equals(tname))
                    trimDirectiveWhitespaces = element.getBody();
                else if ("default-content-type".equals(tname))
                    defaultContentType = element.getBody();
                else if ("buffer".equals(tname))
                    buffer = element.getBody();
                else if ("error-on-undeclared-namespace".equals(tname))
                    errorOnUndeclaredNamespace = element.getBody();
            }
            if (urlPatterns.size() == 0) {
                continue;
            }
            // the matching logic easier.
            for (int p = 0; p < urlPatterns.size(); p++) {
                String urlPattern = urlPatterns.elementAt(p);
                String path = null;
                String extension = null;
                if (urlPattern.indexOf('*') < 0) {
                    // Exact match
                    path = urlPattern;
                } else {
                    int i = urlPattern.lastIndexOf('/');
                    String file;
                    if (i >= 0) {
                        path = urlPattern.substring(0, i + 1);
                        file = urlPattern.substring(i + 1);
                    } else {
                        file = urlPattern;
                    }
                    // pattern must be "*", or of the form "*.jsp"
                    if (file.equals("*")) {
                        extension = "*";
                    } else if (file.startsWith("*.")) {
                        extension = file.substring(file.indexOf('.') + 1);
                    }
                    // The url patterns are reconstructed as the following:
                    // path != null, extension == null:  / or /foo/bar.ext
                    // path == null, extension != null:  *.ext
                    // path != null, extension == "*":   /foo/*
                    boolean isStar = "*".equals(extension);
                    if ((path == null && (extension == null || isStar)) || (path != null && !isStar)) {
                        if (log.isWarnEnabled()) {
                            log.warn(Localizer.getMessage("jsp.warning.bad.urlpattern.propertygroup", urlPattern));
                        }
                        continue;
                    }
                }
                JspProperty property = new JspProperty(isXml, elIgnored, scriptingInvalid, pageEncoding, includePrelude, includeCoda, deferredSyntaxAllowedAsLiteral, trimDirectiveWhitespaces, defaultContentType, buffer, errorOnUndeclaredNamespace);
                JspPropertyGroup propertyGroup = new JspPropertyGroup(path, extension, property);
                jspProperties.addElement(propertyGroup);
            }
        }
    } catch (Exception ex) {
        throw new JasperException(ex);
    } finally {
        if (webXml != null) {
            webXml.close();
        }
    }
}
Also used : JasperException(org.apache.jasper.JasperException) JasperException(org.apache.jasper.JasperException) TreeNode(org.apache.jasper.xmlparser.TreeNode) ParserUtils(org.apache.jasper.xmlparser.ParserUtils) Vector(java.util.Vector)

Example 8 with TreeNode

use of org.apache.jasper.xmlparser.TreeNode 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 9 with TreeNode

use of org.apache.jasper.xmlparser.TreeNode 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)

Example 10 with TreeNode

use of org.apache.jasper.xmlparser.TreeNode in project tomcat70 by apache.

the class TagLibraryInfoImpl method createFunctionInfo.

FunctionInfo createFunctionInfo(TreeNode elem) {
    String name = null;
    String klass = null;
    String signature = null;
    Iterator<TreeNode> list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();
        if ("name".equals(tname)) {
            name = element.getBody();
        } else if ("function-class".equals(tname)) {
            klass = element.getBody();
        } else if ("function-signature".equals(tname)) {
            signature = element.getBody();
        } else if (// Ignored elements
        "display-name".equals(tname) || "small-icon".equals(tname) || "large-icon".equals(tname) || "description".equals(tname) || "example".equals(tname)) {
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.function", tname));
            }
        }
    }
    return new FunctionInfo(name, klass, signature);
}
Also used : TreeNode(org.apache.jasper.xmlparser.TreeNode) FunctionInfo(javax.servlet.jsp.tagext.FunctionInfo)

Aggregations

TreeNode (org.apache.jasper.xmlparser.TreeNode)12 JasperException (org.apache.jasper.JasperException)5 ParserUtils (org.apache.jasper.xmlparser.ParserUtils)5 Vector (java.util.Vector)3 TagInfo (javax.servlet.jsp.tagext.TagInfo)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Hashtable (java.util.Hashtable)2 FunctionInfo (javax.servlet.jsp.tagext.FunctionInfo)2 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)2 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)2 TagVariableInfo (javax.servlet.jsp.tagext.TagVariableInfo)2 ServletContext (javax.servlet.ServletContext)1 TagExtraInfo (javax.servlet.jsp.tagext.TagExtraInfo)1 TagLibraryValidator (javax.servlet.jsp.tagext.TagLibraryValidator)1 TagPlugin (org.apache.jasper.compiler.tagplugin.TagPlugin)1