org.apache.jasper.xmlparser.ParserUtils Java Examples

The following examples show how to use org.apache.jasper.xmlparser.ParserUtils. 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: OptionsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of OptionsImpl */
public OptionsImpl(ServletContext context) {
    ParserUtils.setSchemaResourcePrefix("/resources/schemas/");
    ParserUtils.setDtdResourcePrefix("/resources/dtds/");
    scanner = new TldScanner(context, false);
    // #188703 - JSTL 1.1 handling
    clearStaticHashSet(TldScanner.class, "systemUris");
    clearStaticHashSet(TldScanner.class, "systemUrisJsf");
    jspConfig = new JspConfig(context);
    tagPluginManager = new TagPluginManager(context);
}
 
Example #2
Source File: TldLocationsCache.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void tldScanWebXml() throws Exception {

        WebXml webXml = null;
        try {
            webXml = new WebXml(ctxt);
            if (webXml.getInputSource() == null) {
                return;
            }

            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);
            }
            
            // Parse the web application deployment descriptor
            ParserUtils pu = new ParserUtils(validate, blockExternal);
            
            TreeNode webtld = null;
            webtld = pu.parseXMLDocument(webXml.getSystemId(),
                    webXml.getInputSource());

            // Allow taglib to be an element of the root or jsp-config (JSP2.0)
            TreeNode jspConfig = webtld.findChild("jsp-config");
            if (jspConfig != null) {
                webtld = jspConfig;
            }
            Iterator<TreeNode> taglibs = webtld.findChildren("taglib");
            while (taglibs.hasNext()) {

                // Parse the next <taglib> element
                TreeNode taglib = taglibs.next();
                String tagUri = null;
                String tagLoc = null;
                TreeNode child = taglib.findChild("taglib-uri");
                if (child != null)
                    tagUri = child.getBody();
                child = taglib.findChild("taglib-location");
                if (child != null)
                    tagLoc = child.getBody();

                // Save this location if appropriate
                if (tagLoc == null)
                    continue;
                if (uriType(tagLoc) == NOROOT_REL_URI)
                    tagLoc = "/WEB-INF/" + tagLoc;
                TldLocation location;
                if (tagLoc.endsWith(JAR_EXT)) {
                    location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString());
                } else {
                    location = new TldLocation(tagLoc);
                }
                mappings.put(tagUri, location);
            }
        } finally {
            if (webXml != null) {
                webXml.close();
            }
        }
    }
 
Example #3
Source File: TldLocationsCache.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private void tldScanStream(String resourcePath, String entryName,
        InputStream stream) throws IOException {
    try {
        // Parse the tag library descriptor at the specified resource path
        String uri = null;

        boolean validate = Boolean.parseBoolean(
                ctxt.getInitParameter(
                        Constants.XML_VALIDATION_TLD_INIT_PARAM));
        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(validate, blockExternal); 
        TreeNode tld = pu.parseXMLDocument(resourcePath, stream);
        TreeNode uriNode = tld.findChild("uri");
        if (uriNode != null) {
            String body = uriNode.getBody();
            if (body != null)
                uri = body;
        }

        // Add implicit map entry only if its uri is not already
        // present in the map
        if (uri != null && mappings.get(uri) == null) {
            TldLocation location;
            if (entryName == null) {
                location = new TldLocation(resourcePath);
            } else {
                location = new TldLocation(entryName, resourcePath);
            }
            mappings.put(uri, location);
        }
    } catch (JasperException e) {
        // Hack - makes exception handling simpler
        throw new IOException(e);
    }
}
 
Example #4
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 #5
Source File: TldLocationsCache.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void tldScanWebXml() throws Exception {

        WebXml webXml = null;
        try {
            webXml = new WebXml(ctxt);
            if (webXml.getInputSource() == null) {
                return;
            }

            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);
            }
            
            // Parse the web application deployment descriptor
            ParserUtils pu = new ParserUtils(validate, blockExternal);
            
            TreeNode webtld = null;
            webtld = pu.parseXMLDocument(webXml.getSystemId(),
                    webXml.getInputSource());

            // Allow taglib to be an element of the root or jsp-config (JSP2.0)
            TreeNode jspConfig = webtld.findChild("jsp-config");
            if (jspConfig != null) {
                webtld = jspConfig;
            }
            Iterator<TreeNode> taglibs = webtld.findChildren("taglib");
            while (taglibs.hasNext()) {

                // Parse the next <taglib> element
                TreeNode taglib = taglibs.next();
                String tagUri = null;
                String tagLoc = null;
                TreeNode child = taglib.findChild("taglib-uri");
                if (child != null)
                    tagUri = child.getBody();
                child = taglib.findChild("taglib-location");
                if (child != null)
                    tagLoc = child.getBody();

                // Save this location if appropriate
                if (tagLoc == null)
                    continue;
                if (uriType(tagLoc) == NOROOT_REL_URI)
                    tagLoc = "/WEB-INF/" + tagLoc;
                TldLocation location;
                if (tagLoc.endsWith(JAR_EXT)) {
                    location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString());
                } else {
                    location = new TldLocation(tagLoc);
                }
                mappings.put(tagUri, location);
            }
        } finally {
            if (webXml != null) {
                webXml.close();
            }
        }
    }
 
Example #6
Source File: TldLocationsCache.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void tldScanStream(String resourcePath, String entryName,
        InputStream stream) throws IOException {
    try {
        // Parse the tag library descriptor at the specified resource path
        String uri = null;

        boolean validate = Boolean.parseBoolean(
                ctxt.getInitParameter(
                        Constants.XML_VALIDATION_TLD_INIT_PARAM));
        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(validate, blockExternal); 
        TreeNode tld = pu.parseXMLDocument(resourcePath, stream);
        TreeNode uriNode = tld.findChild("uri");
        if (uriNode != null) {
            String body = uriNode.getBody();
            if (body != null)
                uri = body;
        }

        // Add implicit map entry only if its uri is not already
        // present in the map
        if (uri != null && mappings.get(uri) == null) {
            TldLocation location;
            if (entryName == null) {
                location = new TldLocation(resourcePath);
            } else {
                location = new TldLocation(entryName, resourcePath);
            }
            mappings.put(uri, location);
        }
    } catch (JasperException e) {
        // Hack - makes exception handling simpler
        throw new IOException(e);
    }
}
 
Example #7
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 #8
Source File: JspC.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Sets the path prefix for .xsd resources
 */
public static void setSchemaResourcePrefix(String prefix) {
    ParserUtils.setSchemaResourcePrefix(prefix);
}
 
Example #9
Source File: JspC.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Sets the path prefix for .dtd resources
 */
public static void setDtdResourcePrefix(String prefix) {
    ParserUtils.setDtdResourcePrefix(prefix);
}
 
Example #10
Source File: TldScanner.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Scan the given TLD for uri and listeners elements.
 *
 * @param resourcePath the resource path for the jar file or the tld file.
 * @param entryName If the resource path is a jar file, then the name of
 *        the tld file in the jar, else should be null.
 * @param stream The input stream for the tld
 * @return The TldInfo for this tld
 */
private TldInfo scanTld(String resourcePath, String entryName,
                     InputStream stream)
            throws JasperException {
    try {
        // Parse the tag library descriptor at the specified resource path
        TreeNode tld = new ParserUtils().parseXMLDocument(
                            resourcePath, stream, isValidationEnabled);

        String uri = null;
        TreeNode uriNode = tld.findChild("uri");
        if (uriNode != null) {
            uri = uriNode.getBody();
        }

        ArrayList<String> listeners = new ArrayList<String>();

        Iterator<TreeNode>listenerNodes = tld.findChildren("listener");
        while (listenerNodes.hasNext()) {
            TreeNode listener = listenerNodes.next();
            TreeNode listenerClass = listener.findChild("listener-class");
            if (listenerClass != null) {
                String listenerClassName = listenerClass.getBody();
                if (listenerClassName != null) {
                    listeners.add(listenerClassName);
                }
            }
        }

        return new TldInfo(uri, entryName,
                           listeners.toArray(new String[listeners.size()]));

    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Throwable t) {
                // do nothing
            }
        }
    }
}
 
Example #11
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);
    }
}
 
Example #12
Source File: TagPluginManager.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void init(ErrorDispatcher err) throws JasperException {
if (initialized)
    return;

InputStream is = ctxt.getResourceAsStream(TAG_PLUGINS_XML);
if (is == null)
    return;

TreeNode root = (new ParserUtils()).parseXMLDocument(TAG_PLUGINS_XML,
						     is);
if (root == null) {
    return;
}

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 pluginList = root.findChildren("tag-plugin");
while (pluginList.hasNext()) {
    TreeNode pluginNode = (TreeNode) 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<? extends TagPlugin> pluginClass =
                   Class.forName(pluginClassStr).asSubclass(TagPlugin.class);
	tagPlugin =  pluginClass.newInstance();
    } catch (Exception e) {
	throw new JasperException(e);
    }
    if (tagPlugin == null) {
	return;
    }
    tagPlugins.put(tagClass, tagPlugin);
}
initialized = true;
   }