Search in sources :

Example 1 with TagPlugin

use of org.apache.jasper.compiler.tagplugin.TagPlugin in project tomcat70 by apache.

the class TagPluginManager method init.

private void init(ErrorDispatcher err) throws JasperException {
    if (initialized)
        return;
    tagPlugins = new HashMap<String, TagPlugin>();
    Enumeration<URL> urls = null;
    try {
        urls = ctxt.getClassLoader().getResources(META_INF_JASPER_TAG_PLUGINS_XML);
    } catch (IOException ioe) {
        throw new JasperException(ioe);
    }
    while (urls.hasMoreElements()) {
        URL url = urls.nextElement();
        InputStream is = null;
        try {
            is = url.openStream();
            loadTagPlugins(err, is);
        } catch (IOException ioe) {
            throw new JasperException(ioe);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ioe) {
                    throw new JasperException(ioe);
                }
            }
        }
    }
    InputStream is = null;
    try {
        is = ctxt.getResourceAsStream(TAG_PLUGINS_XML);
        if (is != null) {
            loadTagPlugins(err, is);
        }
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException ioe) {
            throw new JasperException(ioe);
        }
    }
    initialized = true;
}
Also used : JasperException(org.apache.jasper.JasperException) InputStream(java.io.InputStream) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with TagPlugin

use of org.apache.jasper.compiler.tagplugin.TagPlugin 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 3 with TagPlugin

use of org.apache.jasper.compiler.tagplugin.TagPlugin in project tomcat by apache.

the class TagPluginManager method invokePlugin.

/**
 * Invoke tag plugin for the given custom tag, if a plugin exists for
 * the custom tag's tag handler.
 * <p/>
 * The given custom tag node will be manipulated by the plugin.
 */
private void invokePlugin(Node.CustomTag n, PageInfo pageInfo) {
    TagPlugin tagPlugin = tagPlugins.get(n.getTagHandlerClass().getName());
    if (tagPlugin == null) {
        return;
    }
    TagPluginContext tagPluginContext = new TagPluginContextImpl(n, pageInfo);
    n.setTagPluginContext(tagPluginContext);
    tagPlugin.doTag(tagPluginContext);
}
Also used : TagPluginContext(org.apache.jasper.compiler.tagplugin.TagPluginContext) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin)

Example 4 with TagPlugin

use of org.apache.jasper.compiler.tagplugin.TagPlugin in project tomcat by apache.

the class TagPluginManager method init.

private void init(ErrorDispatcher err) throws JasperException {
    if (initialized) {
        return;
    }
    String blockExternalString = ctxt.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
    boolean blockExternal;
    if (blockExternalString == null) {
        blockExternal = true;
    } else {
        blockExternal = Boolean.parseBoolean(blockExternalString);
    }
    TagPluginParser parser;
    ClassLoader original;
    if (Constants.IS_SECURITY_ENABLED) {
        PrivilegedGetTccl pa = new PrivilegedGetTccl();
        original = AccessController.doPrivileged(pa);
    } else {
        original = Thread.currentThread().getContextClassLoader();
    }
    try {
        if (Constants.IS_SECURITY_ENABLED) {
            PrivilegedSetTccl pa = new PrivilegedSetTccl(TagPluginManager.class.getClassLoader());
            AccessController.doPrivileged(pa);
        } else {
            Thread.currentThread().setContextClassLoader(TagPluginManager.class.getClassLoader());
        }
        parser = new TagPluginParser(ctxt, blockExternal);
        Enumeration<URL> urls = ctxt.getClassLoader().getResources(META_INF_JASPER_TAG_PLUGINS_XML);
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            parser.parse(url);
        }
        URL url = ctxt.getResource(TAG_PLUGINS_XML);
        if (url != null) {
            parser.parse(url);
        }
    } catch (IOException | SAXException e) {
        throw new JasperException(e);
    } finally {
        if (Constants.IS_SECURITY_ENABLED) {
            PrivilegedSetTccl pa = new PrivilegedSetTccl(original);
            AccessController.doPrivileged(pa);
        } else {
            Thread.currentThread().setContextClassLoader(original);
        }
    }
    Map<String, String> plugins = parser.getPlugins();
    tagPlugins = new HashMap<>(plugins.size());
    for (Map.Entry<String, String> entry : plugins.entrySet()) {
        try {
            String tagClass = entry.getKey();
            String pluginName = entry.getValue();
            Class<?> pluginClass = ctxt.getClassLoader().loadClass(pluginName);
            TagPlugin plugin = (TagPlugin) pluginClass.getConstructor().newInstance();
            tagPlugins.put(tagClass, plugin);
        } catch (Exception e) {
            err.jspError(e);
        }
    }
    initialized = true;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) JasperException(org.apache.jasper.JasperException) SAXException(org.xml.sax.SAXException) JasperException(org.apache.jasper.JasperException) PrivilegedGetTccl(org.apache.tomcat.util.security.PrivilegedGetTccl) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin) TagPluginParser(org.apache.tomcat.util.descriptor.tagplugin.TagPluginParser) HashMap(java.util.HashMap) Map(java.util.Map) PrivilegedSetTccl(org.apache.tomcat.util.security.PrivilegedSetTccl)

Example 5 with TagPlugin

use of org.apache.jasper.compiler.tagplugin.TagPlugin in project tomcat70 by apache.

the class TagPluginManager method invokePlugin.

/**
 * Invoke tag plugin for the given custom tag, if a plugin exists for
 * the custom tag's tag handler.
 *
 * The given custom tag node will be manipulated by the plugin.
 */
private void invokePlugin(Node.CustomTag n, PageInfo pageInfo) {
    TagPlugin tagPlugin = tagPlugins.get(n.getTagHandlerClass().getName());
    if (tagPlugin == null) {
        return;
    }
    TagPluginContext tagPluginContext = new TagPluginContextImpl(n, pageInfo);
    n.setTagPluginContext(tagPluginContext);
    tagPlugin.doTag(tagPluginContext);
}
Also used : TagPluginContext(org.apache.jasper.compiler.tagplugin.TagPluginContext) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin)

Aggregations

TagPlugin (org.apache.jasper.compiler.tagplugin.TagPlugin)5 IOException (java.io.IOException)3 JasperException (org.apache.jasper.JasperException)3 URL (java.net.URL)2 TagPluginContext (org.apache.jasper.compiler.tagplugin.TagPluginContext)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParserUtils (org.apache.jasper.xmlparser.ParserUtils)1 TreeNode (org.apache.jasper.xmlparser.TreeNode)1 TagPluginParser (org.apache.tomcat.util.descriptor.tagplugin.TagPluginParser)1 PrivilegedGetTccl (org.apache.tomcat.util.security.PrivilegedGetTccl)1 PrivilegedSetTccl (org.apache.tomcat.util.security.PrivilegedSetTccl)1 SAXException (org.xml.sax.SAXException)1