geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1051781 - in /geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src: main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java
Date Wed, 22 Dec 2010 07:42:56 GMT
Author: xuhaihong
Date: Wed Dec 22 07:42:56 2010
New Revision: 1051781

URL: http://svn.apache.org/viewvc?rev=1051781&view=rev
Log:
GERONIMO-5726 Still use JAXB for TLD parsing

Modified:
    geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java
    geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java

Modified: geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java?rev=1051781&r1=1051780&r2=1051781&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java
(original)
+++ geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/main/java/org/apache/geronimo/jasper/deployment/JspModuleBuilderExtension.java
Wed Dec 22 07:42:56 2010
@@ -17,7 +17,6 @@
 
 package org.apache.geronimo.jasper.deployment;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -39,7 +38,6 @@ import org.apache.geronimo.deployment.De
 import org.apache.geronimo.deployment.DeployableJarFile;
 import org.apache.geronimo.deployment.ModuleIDBuilder;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
-import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
@@ -65,13 +63,15 @@ import org.apache.geronimo.web.info.Serv
 import org.apache.geronimo.web.info.WebAppInfo;
 import org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder;
 import org.apache.geronimo.web25.deployment.WebAppInfoBuilder;
+import org.apache.openejb.jee.JaxbJavaee;
 import org.apache.openejb.jee.JspConfig;
 import org.apache.openejb.jee.JspPropertyGroup;
+import org.apache.openejb.jee.Listener;
+import org.apache.openejb.jee.Tag;
 import org.apache.openejb.jee.Taglib;
+import org.apache.openejb.jee.TldTaglib;
 import org.apache.openejb.jee.WebApp;
 import org.apache.xbean.finder.ClassFinder;
-import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -343,84 +343,54 @@ public class JspModuleBuilderExtension i
         if (log.isDebugEnabled()) {
             log.debug("parseTLDFile( " + url.toString() + " ): Entry");
         }
-        List<String> listenerClassNames = new ArrayList<String>();
-        List<String> tagClassNames = new ArrayList<String>();
-        parseTldFile(url, listenerClassNames, tagClassNames);
-
-        // Get all the listeners from the TLD file
-        for (String className : listenerClassNames) {
-            if (!excludedListenerNames.contains(className)) {
+        try {
+            InputStream in = null;
+            TldTaglib tl;
+            try {
+                in = url.openStream();
+                tl = (TldTaglib) JaxbJavaee.unmarshalTaglib(TldTaglib.class, in);
+            } finally {
+                IOUtils.close(in);
+            }
+
+            // Get all the listeners from the TLD file
+            for (Listener listener : tl.getListener()) {
+                String className = listener.getListenerClass();
+                if (!excludedListenerNames.contains(className)) {
+                    try {
+                        Class<?> clas = bundle.loadClass(className);
+                        while (clas != null) {
+                            classes.add(clas);
+                            clas = clas.getSuperclass();
+                        }
+                        listenerNames.add(className);
+                    } catch (ClassNotFoundException e) {
+                        log.warn("JspModuleBuilderExtension: Could not load listener class:
" + className + " mentioned in TLD file at " + url.toString());
+                    }
+                }
+            }
+
+            // Get all the tags from the TLD file
+            for (Tag tag : tl.getTag()) {
+                String className = tag.getTagClass();
                 try {
                     Class<?> clas = bundle.loadClass(className);
                     while (clas != null) {
                         classes.add(clas);
                         clas = clas.getSuperclass();
                     }
-                    listenerNames.add(className);
                 } catch (ClassNotFoundException e) {
-                    log.warn("JspModuleBuilderExtension: Could not load listener class: "
+ className + " mentioned in TLD file at " + url.toString());
-                }
-            }
-        }
-
-        // Get all the tags from the TLD file
-        for (String className : tagClassNames) {
-            try {
-                Class<?> clas = bundle.loadClass(className);
-                while (clas != null) {
-                    classes.add(clas);
-                    clas = clas.getSuperclass();
+                    log.warn("JspModuleBuilderExtension: Could not load tag class: " + className
+ " mentioned in TLD file at " + url.toString());
                 }
-            } catch (ClassNotFoundException e) {
-                log.warn("JspModuleBuilderExtension: Could not load tag class: " + className
+ " mentioned in TLD file at " + url.toString());
             }
+        } catch (Exception ioe) {
+            throw new DeploymentException("Could not find TLD file at " + url.toString(),
ioe);
         }
         if (log.isDebugEnabled()) {
             log.debug("parseTLDFile(): Exit");
         }
     }
 
-    protected void parseTldFile(URL url, List<String> listenerClassNames, List<String>
tagClassNames)
-            throws DeploymentException {
-        InputStream in = null;
-        XmlCursor cursor = null;
-        try {
-            in = url.openStream();
-            XmlObject xmlObject = XmlBeansUtil.parse(in);
-            cursor = xmlObject.newCursor();
-            cursor.toStartDoc();
-            cursor.toFirstChild();
-            String namespaceURI = cursor.getName().getNamespaceURI();
-            cursor.toStartDoc();
-            cursor.toChild(namespaceURI, "taglib");
-            if (!cursor.toFirstChild()) {
-                return;
-            }
-            do {
-                String name = cursor.getName().getLocalPart();
-                if ("tag".equals(name)) {
-                    cursor.push();
-                    if (cursor.toChild(namespaceURI, "tag-class") || cursor.toChild(namespaceURI,
"tagclass")) {
-                        tagClassNames.add(cursor.getTextValue());
-                    }
-                    cursor.pop();
-                } else if ("listener".equals(name)) {
-                    cursor.push();
-                    if (cursor.toChild(namespaceURI, "listener-class")) {
-                        listenerClassNames.add(cursor.getTextValue());
-                    }
-                    cursor.pop();
-                }
-            } while (cursor.toNextSibling());
-        } catch (IOException e) {
-            throw new DeploymentException("JspModuleBuilderExtension: Could not parse tld
file " + url, e);
-        } catch (XmlException e) {
-            throw new DeploymentException("JspModuleBuilderExtension: Could not parse tld
file " + url, e);
-        } finally {
-            IOUtils.close(in);
-        }
-    }
-
     private URI createURI(String path) throws URISyntaxException {
         path = path.replaceAll(" ", "%20");
         return new URI(path);

Modified: geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java?rev=1051781&r1=1051780&r2=1051781&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java
(original)
+++ geronimo/server/trunk/plugins/jasper/geronimo-jasper-builder/src/test/java/org/apache/geronimo/jasper/deployment/SchemaParseTest.java
Wed Dec 22 07:42:56 2010
@@ -17,20 +17,20 @@
 
 package org.apache.geronimo.jasper.deployment;
 
+import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.geronimo.common.DeploymentException;
-import org.apache.geronimo.j2ee.deployment.NamingBuilder;
-import org.apache.geronimo.kernel.repository.Environment;
-import org.apache.geronimo.web.info.ServletInfo;
-import org.apache.geronimo.web.info.WebAppInfo;
+import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.openejb.jee.JaxbJavaee;
+import org.apache.openejb.jee.Listener;
+import org.apache.openejb.jee.Tag;
+import org.apache.openejb.jee.TldTaglib;
 import org.junit.Assert;
 
 /**
@@ -38,97 +38,74 @@ import org.junit.Assert;
  */
 public class SchemaParseTest extends TestCase {
 
-    private TestJspModuleBuilderExtension jspModuleBuilderExtension;
-
     private ClassLoader classLoader = SchemaParseTest.class.getClassLoader();
 
-    @Override
-    public void setUp() {
-        //webAppInfo is used to prevent the NPE in JspModuleBuilderExtension constructor
-        WebAppInfo webAppInfo = new WebAppInfo();
-        webAppInfo.servlets.add(new ServletInfo());
-        jspModuleBuilderExtension = new TestJspModuleBuilderExtension(null, null, webAppInfo,
null);
-    }
-
     public void testParse11DTD() throws Exception {
         URL url = classLoader.getResource("1_1_dtd/taglib-tag-listener.tld");
-        List<String> expectedTagClassNames = Arrays.asList("org.apache.struts.taglib.nested.NestedPropertyTag",
-                "org.apache.struts.taglib.nested.NestedWriteNestingTag",
-                "org.apache.struts.taglib.nested.NestedRootTag",
-                "org.apache.struts.taglib.nested.bean.NestedDefineTag",
-                "org.apache.struts.taglib.nested.bean.NestedMessageTag",
-                "org.apache.struts.taglib.nested.bean.NestedSizeTag",
-                "org.apache.struts.taglib.nested.bean.NestedWriteTag",
-                "org.apache.struts.taglib.nested.html.NestedCheckboxTag",
-                "org.apache.struts.taglib.nested.html.NestedErrorsTag",
-                "org.apache.struts.taglib.nested.html.NestedFileTag");
+        List<String> expectedTagClassNames = Arrays.asList("org.apache.struts.taglib.nested.NestedPropertyTag",
"org.apache.struts.taglib.nested.NestedWriteNestingTag",
+                "org.apache.struts.taglib.nested.NestedRootTag", "org.apache.struts.taglib.nested.bean.NestedDefineTag",
"org.apache.struts.taglib.nested.bean.NestedMessageTag",
+                "org.apache.struts.taglib.nested.bean.NestedSizeTag", "org.apache.struts.taglib.nested.bean.NestedWriteTag",
"org.apache.struts.taglib.nested.html.NestedCheckboxTag",
+                "org.apache.struts.taglib.nested.html.NestedErrorsTag", "org.apache.struts.taglib.nested.html.NestedFileTag");
         List<String> expectedListenerClassNames = Collections.<String> emptyList();
-        jspModuleBuilderExtension.testParse(url, expectedListenerClassNames, expectedTagClassNames);
+        parseTldFile(url, expectedListenerClassNames, expectedTagClassNames);
     }
 
     public void testParse12DTD() throws Exception {
         URL url = classLoader.getResource("1_2_dtd/taglib-tag-listener.tld");
         List<String> expectedTagClassNames = Arrays.asList("examples.LogTag");
         List<String> expectedListenerClassNames = Arrays.asList("TestListenerClassName");
-        jspModuleBuilderExtension.testParse(url, expectedListenerClassNames, expectedTagClassNames);
+        parseTldFile(url, expectedListenerClassNames, expectedTagClassNames);
     }
 
     public void testParse20XSD() throws Exception {
         URL url = classLoader.getResource("2_0_xsd/taglib-tag-listener.tld");
-        List<String> expectedTagClassNames = Arrays.asList("org.apache.taglibs.standard.tag.rt.fmt.RequestEncodingTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetLocaleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.TimeZoneTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetTimeZoneTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.BundleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetBundleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.MessageTag", "org.apache.taglibs.standard.tag.rt.fmt.ParamTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.FormatNumberTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.ParseNumberTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.FormatDateTag",
+        List<String> expectedTagClassNames = Arrays.asList("org.apache.taglibs.standard.tag.rt.fmt.RequestEncodingTag",
"org.apache.taglibs.standard.tag.rt.fmt.SetLocaleTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.TimeZoneTag", "org.apache.taglibs.standard.tag.rt.fmt.SetTimeZoneTag",
"org.apache.taglibs.standard.tag.rt.fmt.BundleTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.SetBundleTag", "org.apache.taglibs.standard.tag.rt.fmt.MessageTag",
"org.apache.taglibs.standard.tag.rt.fmt.ParamTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.FormatNumberTag", "org.apache.taglibs.standard.tag.rt.fmt.ParseNumberTag",
"org.apache.taglibs.standard.tag.rt.fmt.FormatDateTag",
                 "org.apache.taglibs.standard.tag.rt.fmt.ParseDateTag");
         List<String> expectedListenerClassNames = Arrays.asList("TestListenerA", "TestListenerB");
-        jspModuleBuilderExtension.testParse(url, expectedListenerClassNames, expectedTagClassNames);
+        parseTldFile(url, expectedListenerClassNames, expectedTagClassNames);
     }
 
     public void testParse21XSD() throws Exception {
         URL url = classLoader.getResource("2_1_xsd/taglib-tag-listener.tld");
-        List<String> expectedTagClassNames = Arrays.asList("org.apache.taglibs.standard.tag.rt.fmt.RequestEncodingTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetLocaleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.TimeZoneTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetTimeZoneTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.BundleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.SetBundleTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.MessageTag", "org.apache.taglibs.standard.tag.rt.fmt.ParamTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.FormatNumberTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.ParseNumberTag",
-                "org.apache.taglibs.standard.tag.rt.fmt.FormatDateTag",
+        List<String> expectedTagClassNames = Arrays.asList("org.apache.taglibs.standard.tag.rt.fmt.RequestEncodingTag",
"org.apache.taglibs.standard.tag.rt.fmt.SetLocaleTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.TimeZoneTag", "org.apache.taglibs.standard.tag.rt.fmt.SetTimeZoneTag",
"org.apache.taglibs.standard.tag.rt.fmt.BundleTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.SetBundleTag", "org.apache.taglibs.standard.tag.rt.fmt.MessageTag",
"org.apache.taglibs.standard.tag.rt.fmt.ParamTag",
+                "org.apache.taglibs.standard.tag.rt.fmt.FormatNumberTag", "org.apache.taglibs.standard.tag.rt.fmt.ParseNumberTag",
"org.apache.taglibs.standard.tag.rt.fmt.FormatDateTag",
                 "org.apache.taglibs.standard.tag.rt.fmt.ParseDateTag");
         List<String> expectedListenerClassNames = Arrays.asList("TestListenerA", "TestListenerB");
-        jspModuleBuilderExtension.testParse(url, expectedListenerClassNames, expectedTagClassNames);
+        parseTldFile(url, expectedListenerClassNames, expectedTagClassNames);
     }
 
-    static class TestJspModuleBuilderExtension extends JspModuleBuilderExtension {
+    private void parseTldFile(URL url, List<String> expectedListenerClassNames, List<String>
expectedTagClassNames) throws Exception {
+        InputStream in = null;
+        TldTaglib tl;
+        try {
+            in = url.openStream();
+            tl = (TldTaglib) JaxbJavaee.unmarshalTaglib(TldTaglib.class, in);
+        } finally {
+            IOUtils.close(in);
+        }
+        List<String> listenerClassNames = new ArrayList<String>();
 
-        public TestJspModuleBuilderExtension(Environment defaultEnvironment, Collection<String>
excludedListenerNames,
-                WebAppInfo defaultJspServlet, NamingBuilder namingBuilders) {
-            super(defaultEnvironment, excludedListenerNames, defaultJspServlet, namingBuilders);
+        for (Listener listener : tl.getListener()) {
+            listenerClassNames.add(listener.getListenerClass());
+        }
+        List<String> tagClassNames = new ArrayList<String>();
+        // Get all the tags from the TLD file
+        for (Tag tag : tl.getTag()) {
+            tagClassNames.add(tag.getTagClass());
         }
 
-        public void testParse(URL url, List<String> expectedListenerClassNames, List<String>
expectedTagClassNames)
-                throws DeploymentException {
-            List<String> listenerClassNames = new ArrayList<String>();
-            List<String> tagClassNames = new ArrayList<String>();
-            parseTldFile(url, listenerClassNames, tagClassNames);
-            Assert.assertEquals(expectedListenerClassNames.size(), listenerClassNames.size());
-            for (String expectedListenerClassName : expectedListenerClassNames) {
-                Assert.assertTrue("expected class name " + expectedListenerClassName + "is
not found in the result"
-                        + listenerClassNames, listenerClassNames.contains(expectedListenerClassName));
-            }
-            Assert.assertEquals(expectedTagClassNames.size(), tagClassNames.size());
-            for (String expectedTagClassName : expectedTagClassNames) {
-                Assert.assertTrue("expected class name " + expectedTagClassName + "is not
found in the result"
-                        + listenerClassNames, tagClassNames.contains(expectedTagClassName));
-            }
+        Assert.assertEquals(expectedListenerClassNames.size(), listenerClassNames.size());
+        for (String expectedListenerClassName : expectedListenerClassNames) {
+            Assert.assertTrue("expected class name " + expectedListenerClassName + "is not
found in the result" + listenerClassNames, listenerClassNames.contains(expectedListenerClassName));
+        }
+        Assert.assertEquals(expectedTagClassNames.size(), tagClassNames.size());
+        for (String expectedTagClassName : expectedTagClassNames) {
+            Assert.assertTrue("expected class name " + expectedTagClassName + "is not found
in the result" + listenerClassNames, tagClassNames.contains(expectedTagClassName));
         }
     }
 }



Mime
View raw message