Author: markt Date: Thu Jan 10 09:22:11 2013 New Revision: 1431221 URL: http://svn.apache.org/viewvc?rev=1431221&view=rev Log: Add support for auto-detection and configuration of JARs on the classpath that provide Tag Plugin implementations. Based on a patch by Sheldon Shao.
Added: tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java (with props) tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java (with props) tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java (with props) tomcat/trunk/test/webapp-3.0/WEB-INF/classes/ tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/ tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/ tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml (with props) Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java?rev=1431221&r1=1431220&r2=1431221&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java Thu Jan 10 09:22:11 2013 @@ -14,10 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.jasper.compiler; +import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -33,9 +35,10 @@ import org.apache.jasper.xmlparser.TreeN * Manages tag plugin optimizations. * @author Kin-man Chung */ - public class TagPluginManager { + private static final String META_INF_JASPER_TAG_PLUGINS_XML = + "META-INF/org.apache.jasper/tagPlugins.xml"; private static final String TAG_PLUGINS_XML = "/WEB-INF/tagPlugins.xml"; private static final String TAG_PLUGINS_ROOT_ELEM = "tag-plugins"; @@ -73,12 +76,44 @@ public class TagPluginManager { if (initialized) return; - InputStream is = ctxt.getResourceAsStream(TAG_PLUGINS_XML); - if (is == null) - return; + tagPlugins = new HashMap<>(); + + Enumeration<URL> urls = null; + try { + urls = ctxt.getClassLoader().getResources( + META_INF_JASPER_TAG_PLUGINS_XML); + } catch (IOException ioe) { + throw new JasperException(ioe); + } + + if (urls != null) { + while(urls.hasMoreElements()) { + URL url = urls.nextElement(); + try (InputStream is = url.openStream()){ + loadTagPlugins(err, is); + } catch(IOException ioe) { + throw new JasperException(ioe); + } + } + } + + try (InputStream is = ctxt.getResourceAsStream(TAG_PLUGINS_XML)) { + if (is != null) { + loadTagPlugins(err, is); + } + } catch (IOException ioe) { + throw new JasperException(ioe); + } + + initialized = true; + } + + + private void loadTagPlugins(ErrorDispatcher err, InputStream is) + throws JasperException { - TreeNode root = (new ParserUtils()).parseXMLDocument(TAG_PLUGINS_XML, - is); + TreeNode root = + (new ParserUtils()).parseXMLDocument(TAG_PLUGINS_XML, is); if (root == null) { return; } Added: tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java?rev=1431221&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java (added) +++ tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java Thu Jan 10 09:22:11 2013 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jasper.compiler; + +import java.io.File; + +import javax.servlet.ServletContext; +import javax.servlet.jsp.tagext.TagFileInfo; +import javax.servlet.jsp.tagext.TagInfo; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; + +/** + * Test case for {@link TagPluginManager}. + */ +public class TestTagPluginManager extends TomcatBaseTest { + + private static TagInfo tagInfo = new TagInfo("ATag", + "org.apache.jasper.compiler.ATagSupport", "", "", null, null, null); + + @Test + public void testBug54240() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + tomcat.start(); + + ServletContext context = ctx.getServletContext(); + + TagPluginManager manager = new TagPluginManager(context); + + Node.Nodes nodes = new Node.Nodes(); + Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag", + "http://tomcat.apache.org/jasper", null, null, null, null, null, + new TagFileInfo("ATag", "http://tomcat.apache.org/jasper", + tagInfo)); + c.setTagHandlerClass(TesterTag.class); + nodes.add(c); + manager.apply(nodes, null, null); + + Node n = nodes.getNode(0); + Assert.assertNotNull(n); + Assert.assertTrue(n instanceof Node.CustomTag); + + Node.CustomTag t = (Node.CustomTag)n; + Assert.assertNotNull(t.getAtSTag()); + + Node.Nodes sTag = c.getAtSTag(); + Node scriptlet = sTag.getNode(0); + Assert.assertNotNull(scriptlet); + Assert.assertTrue(scriptlet instanceof Node.Scriptlet); + Node.Scriptlet s = (Node.Scriptlet)scriptlet; + Assert.assertEquals("//Just a comment", s.getText()); + } +} Propchange: tomcat/trunk/test/org/apache/jasper/compiler/TestTagPluginManager.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java?rev=1431221&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java (added) +++ tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java Thu Jan 10 09:22:11 2013 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jasper.compiler; + +import javax.servlet.jsp.tagext.TagSupport; + +/** + * A tag for test purpose + */ +public class TesterTag extends TagSupport { + + private static final long serialVersionUID = 1L; +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/jasper/compiler/TesterTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java?rev=1431221&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java (added) +++ tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java Thu Jan 10 09:22:11 2013 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jasper.compiler; + +import org.apache.jasper.compiler.tagplugin.TagPlugin; +import org.apache.jasper.compiler.tagplugin.TagPluginContext; + +/** + * Plug-in for {@link TesterTag}. + */ +public class TesterTagPlugin implements TagPlugin { + + @Override + public void doTag(TagPluginContext ctxt) { + ctxt.generateJavaSource("//Just a comment"); + } +} \ No newline at end of file Propchange: tomcat/trunk/test/org/apache/jasper/compiler/TesterTagPlugin.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml?rev=1431221&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml (added) +++ tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml Thu Jan 10 09:22:11 2013 @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<tag-plugins> + <tag-plugin> + <tag-class>org.apache.jasper.compiler.TesterTag</tag-class> + <plugin-class>org.apache.jasper.compiler.TesterTagPlugin</plugin-class> + </tag-plugin> +</tag-plugins> \ No newline at end of file Propchange: tomcat/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/org.apache.jasper/tagPlugins.xml ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org