Manages tag plugin optimizations.
| 35 | * Manages tag plugin optimizations. |
| 36 | */ |
| 37 | public class TagPluginManager { |
| 38 | |
| 39 | private static final String META_INF_JASPER_TAG_PLUGINS_XML = "META-INF/org.apache.jasper/tagPlugins.xml"; |
| 40 | private static final String TAG_PLUGINS_XML = "/WEB-INF/tagPlugins.xml"; |
| 41 | private final ServletContext ctxt; |
| 42 | private HashMap<String,TagPlugin> tagPlugins; |
| 43 | private volatile boolean initialized = false; |
| 44 | |
| 45 | /** |
| 46 | * Creates a new TagPluginManager for the given servlet context. |
| 47 | * |
| 48 | * @param ctxt the servlet context |
| 49 | */ |
| 50 | public TagPluginManager(ServletContext ctxt) { |
| 51 | this.ctxt = ctxt; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Applies tag plugin optimizations to the given page. |
| 56 | * |
| 57 | * @param page the page node tree |
| 58 | * @param err the error dispatcher |
| 59 | * @param pageInfo page information |
| 60 | * @throws JasperException if an error occurs during optimization |
| 61 | */ |
| 62 | public void apply(Node.Nodes page, ErrorDispatcher err, PageInfo pageInfo) throws JasperException { |
| 63 | |
| 64 | if (!initialized) { |
| 65 | init(err); |
| 66 | } |
| 67 | if (!tagPlugins.isEmpty()) { |
| 68 | page.visit(new NodeVisitor(this, pageInfo)); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | private synchronized void init(ErrorDispatcher err) throws JasperException { |
| 73 | if (initialized) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | String blockExternalString = ctxt.getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM); |
| 78 | boolean blockExternal; |
| 79 | if (blockExternalString == null) { |
| 80 | blockExternal = true; |
| 81 | } else { |
| 82 | blockExternal = Boolean.parseBoolean(blockExternalString); |
| 83 | } |
| 84 | |
| 85 | TagPluginParser parser; |
| 86 | Thread currentThread = Thread.currentThread(); |
| 87 | ClassLoader original = currentThread.getContextClassLoader(); |
| 88 | try { |
| 89 | currentThread.setContextClassLoader(TagPluginManager.class.getClassLoader()); |
| 90 | |
| 91 | parser = new TagPluginParser(ctxt, blockExternal); |
| 92 | |
| 93 | Enumeration<URL> urls = ctxt.getClassLoader().getResources(META_INF_JASPER_TAG_PLUGINS_XML); |
| 94 | while (urls.hasMoreElements()) { |
nothing calls this directly
no outgoing calls
no test coverage detected