Search in sources :

Example 1 with TagPlugin

use of org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin in project sling by apache.

the class TagPluginManager method init.

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();
    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 pluginClass = this.getClass().getClassLoader().loadClass(pluginClassStr);
            tagPlugin = (TagPlugin) pluginClass.newInstance();
        } catch (Exception e) {
            throw new JasperException(e);
        }
        if (tagPlugin == null) {
            return;
        }
        tagPlugins.put(tagClass, tagPlugin);
    }
    initialized = true;
}
Also used : HashMap(java.util.HashMap) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) InputStream(java.io.InputStream) TreeNode(org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode) Iterator(java.util.Iterator) TagPlugin(org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin) ParserUtils(org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 2 with TagPlugin

use of org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin in project sling 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) {
    TagPlugin 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.sling.scripting.jsp.jasper.compiler.tagplugin.TagPluginContext) TagPlugin(org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin)

Aggregations

TagPlugin (org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPlugin)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)1 TagPluginContext (org.apache.sling.scripting.jsp.jasper.compiler.tagplugin.TagPluginContext)1 ParserUtils (org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils)1 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)1