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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations