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

The following examples show how to use org.apache.jasper.xmlparser.TreeNode#findChild() . 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: 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 2
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 3
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 4
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 5
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 6
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;
   }