Java Code Examples for org.apache.jasper.xmlparser.TreeNode#findAttribute()

The following examples show how to use org.apache.jasper.xmlparser.TreeNode#findAttribute() . 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: JspConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private double getVersion(TreeNode webApp) {
    String v = webApp.findAttribute("version");
    if (v != null) {
        try {
            return Double.parseDouble(v);
        } catch (NumberFormatException e) {
        }
    }
    return 2.3;
}
 
Example 2
Source File: JspConfig.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private double getVersion(TreeNode webApp) {
    String v = webApp.findAttribute("version");
    if (v != null) {
        try {
            return Double.parseDouble(v);
        } catch (NumberFormatException e) {
        }
    }
    return 2.3;
}
 
Example 3
Source File: TagLibraryInfoImpl.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void parseTLD(String uri, InputStream in, JarResource jarResource)
        throws JasperException {
    Vector<TagInfo> tagVector = new Vector<TagInfo>();
    Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>();
    Hashtable<String, FunctionInfo> functionTable = new Hashtable<String, FunctionInfo>();

    ServletContext servletContext = ctxt.getServletContext();
    boolean validate = Boolean.parseBoolean(servletContext.getInitParameter(
            Constants.XML_VALIDATION_TLD_INIT_PARAM));
    String blockExternalString = servletContext.getInitParameter(
            Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }

    // Create an iterator over the child elements of our <taglib> element
    ParserUtils pu = new ParserUtils(validate, blockExternal);
    TreeNode tld = pu.parseXMLDocument(uri, in);

    // Check to see if the <taglib> root element contains a 'version'
    // attribute, which was added in JSP 2.0 to replace the <jsp-version>
    // subelement
    this.jspversion = tld.findAttribute("version");

    // Process each child element of our <taglib> element
    Iterator<TreeNode> list = tld.findChildren();

    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();

        if ("tlibversion".equals(tname) // JSP 1.1
                || "tlib-version".equals(tname)) { // JSP 1.2
            this.tlibversion = element.getBody();
        } else if ("jspversion".equals(tname)
                || "jsp-version".equals(tname)) {
            this.jspversion = element.getBody();
        } else if ("shortname".equals(tname) || "short-name".equals(tname))
            this.shortname = element.getBody();
        else if ("uri".equals(tname))
            this.urn = element.getBody();
        else if ("info".equals(tname) || "description".equals(tname))
            this.info = element.getBody();
        else if ("validator".equals(tname))
            this.tagLibraryValidator = createValidator(element);
        else if ("tag".equals(tname))
            tagVector.addElement(createTagInfo(element, jspversion));
        else if ("tag-file".equals(tname)) {
            TagFileInfo tagFileInfo = createTagFileInfo(element,
                    jarResource);
            tagFileVector.addElement(tagFileInfo);
        } else if ("function".equals(tname)) { // JSP2.0
            FunctionInfo funcInfo = createFunctionInfo(element);
            String funcName = funcInfo.getName();
            if (functionTable.containsKey(funcName)) {
                err.jspError("jsp.error.tld.fn.duplicate.name", funcName,
                        uri);

            }
            functionTable.put(funcName, funcInfo);
        } else if ("display-name".equals(tname) ||
                "small-icon".equals(tname) || "large-icon".equals(tname)
                || "listener".equals(tname)) {
            // Ignored elements
        } else if ("taglib-extension".equals(tname)) {
            // Recognized but ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage(
                        "jsp.warning.unknown.element.in.taglib", tname));
            }
        }

    }

    if (tlibversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing",
                "tlib-version", uri);
    }
    if (jspversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing",
                "jsp-version", uri);
    }

    this.tags = new TagInfo[tagVector.size()];
    tagVector.copyInto(this.tags);

    this.tagFiles = new TagFileInfo[tagFileVector.size()];
    tagFileVector.copyInto(this.tagFiles);

    this.functions = new FunctionInfo[functionTable.size()];
    int i = 0;
    Enumeration<FunctionInfo> enumeration = functionTable.elements();
    while (enumeration.hasMoreElements()) {
        this.functions[i++] = enumeration.nextElement();
    }
}
 
Example 4
Source File: TagLibraryInfoImpl.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void parseTLD(String uri, InputStream in, JarResource jarResource)
        throws JasperException {
    Vector<TagInfo> tagVector = new Vector<TagInfo>();
    Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>();
    Hashtable<String, FunctionInfo> functionTable = new Hashtable<String, FunctionInfo>();

    ServletContext servletContext = ctxt.getServletContext();
    boolean validate = Boolean.parseBoolean(servletContext.getInitParameter(
            Constants.XML_VALIDATION_TLD_INIT_PARAM));
    String blockExternalString = servletContext.getInitParameter(
            Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }

    // Create an iterator over the child elements of our <taglib> element
    ParserUtils pu = new ParserUtils(validate, blockExternal);
    TreeNode tld = pu.parseXMLDocument(uri, in);

    // Check to see if the <taglib> root element contains a 'version'
    // attribute, which was added in JSP 2.0 to replace the <jsp-version>
    // subelement
    this.jspversion = tld.findAttribute("version");

    // Process each child element of our <taglib> element
    Iterator<TreeNode> list = tld.findChildren();

    while (list.hasNext()) {
        TreeNode element = list.next();
        String tname = element.getName();

        if ("tlibversion".equals(tname) // JSP 1.1
                || "tlib-version".equals(tname)) { // JSP 1.2
            this.tlibversion = element.getBody();
        } else if ("jspversion".equals(tname)
                || "jsp-version".equals(tname)) {
            this.jspversion = element.getBody();
        } else if ("shortname".equals(tname) || "short-name".equals(tname))
            this.shortname = element.getBody();
        else if ("uri".equals(tname))
            this.urn = element.getBody();
        else if ("info".equals(tname) || "description".equals(tname))
            this.info = element.getBody();
        else if ("validator".equals(tname))
            this.tagLibraryValidator = createValidator(element);
        else if ("tag".equals(tname))
            tagVector.addElement(createTagInfo(element, jspversion));
        else if ("tag-file".equals(tname)) {
            TagFileInfo tagFileInfo = createTagFileInfo(element,
                    jarResource);
            tagFileVector.addElement(tagFileInfo);
        } else if ("function".equals(tname)) { // JSP2.0
            FunctionInfo funcInfo = createFunctionInfo(element);
            String funcName = funcInfo.getName();
            if (functionTable.containsKey(funcName)) {
                err.jspError("jsp.error.tld.fn.duplicate.name", funcName,
                        uri);

            }
            functionTable.put(funcName, funcInfo);
        } else if ("display-name".equals(tname) ||
                "small-icon".equals(tname) || "large-icon".equals(tname)
                || "listener".equals(tname)) {
            // Ignored elements
        } else if ("taglib-extension".equals(tname)) {
            // Recognized but ignored
        } else {
            if (log.isWarnEnabled()) {
                log.warn(Localizer.getMessage(
                        "jsp.warning.unknown.element.in.taglib", tname));
            }
        }

    }

    if (tlibversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing",
                "tlib-version", uri);
    }
    if (jspversion == null) {
        err.jspError("jsp.error.tld.mandatory.element.missing",
                "jsp-version", uri);
    }

    this.tags = new TagInfo[tagVector.size()];
    tagVector.copyInto(this.tags);

    this.tagFiles = new TagFileInfo[tagFileVector.size()];
    tagFileVector.copyInto(this.tagFiles);

    this.functions = new FunctionInfo[functionTable.size()];
    int i = 0;
    Enumeration<FunctionInfo> enumeration = functionTable.elements();
    while (enumeration.hasMoreElements()) {
        this.functions[i++] = enumeration.nextElement();
    }
}
 
Example 5
Source File: ImplicitTagLibraryInfo.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Parses the JSP version and tlib-version from the implicit.tld at the
 * given path.
 */
private void parseImplicitTld(JspCompilationContext ctxt, String path)
        throws JasperException {

    InputStream is = null;
    TreeNode tld = null;

    try {
        URL uri = ctxt.getResource(path);
        if (uri == null) {
            // no implicit.tld
            return;
        }

        is = uri.openStream();
        /* SJSAS 6384538
        tld = new ParserUtils().parseXMLDocument(IMPLICIT_TLD, is);
        */
        // START SJSAS 6384538
        tld = new ParserUtils().parseXMLDocument(
            IMPLICIT_TLD, is, ctxt.getOptions().isValidationEnabled());
        // END SJSAS 6384538
    } catch (Exception ex) {
        throw new JasperException(ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Throwable t) {}
        }
    }

    this.jspversion = tld.findAttribute("version");

    Iterator list = tld.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();
        if ("tlibversion".equals(tname)
                || "tlib-version".equals(tname)) {
            this.tlibversion = element.getBody();
        } else if ("jspversion".equals(tname)
                || "jsp-version".equals(tname)) {
            this.jspversion = element.getBody();
        } else if (!"shortname".equals(tname)
                && !"short-name".equals(tname)) {
            err.jspError("jsp.error.implicitTld.additionalElements",
                         path, tname);
        }
    }

    // JSP version in implicit.tld must be 2.0 or greater
    Double jspVersionDouble = Double.valueOf(this.jspversion);
    if (Double.compare(jspVersionDouble, Constants.JSP_VERSION_2_0) < 0) {
        err.jspError("jsp.error.implicitTld.jspVersion", path,
                     this.jspversion);
    }
}