User: starksm
Date: 01/06/09 17:34:00
Modified: tomcat/src/main/org/jboss/tomcat/naming Tag: Branch_2_2
JbossWebXmlReader.java
Log:
Add EntityResolver for jboss-web.dtd and web.dtd
Revision Changes Path
No revision
No revision
1.3.2.2 +77 -33
contrib/tomcat/src/main/org/jboss/tomcat/naming/JbossWebXmlReader.java
Index: JbossWebXmlReader.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/tomcat/src/main/org/jboss/tomcat/naming/JbossWebXmlReader.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- JbossWebXmlReader.java 2001/05/24 15:36:40 1.3.2.1
+++ JbossWebXmlReader.java 2001/06/10 00:34:00 1.3.2.2
@@ -7,12 +7,16 @@
package org.jboss.tomcat.naming;
import java.io.File;
+import java.io.InputStream;
import java.io.IOException;
+import java.util.HashMap;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
import org.apache.tomcat.core.BaseInterceptor;
import org.apache.tomcat.core.ContextManager;
@@ -27,44 +31,84 @@
@author <a href="mailto:[EMAIL PROTECTED]">Kevin Lewis</a>
@author [EMAIL PROTECTED]
-@version $Revision: 1.3.2.1 $
+@version $Revision: 1.3.2.2 $
*/
-public class JbossWebXmlReader
- extends BaseInterceptor
+public class JbossWebXmlReader extends BaseInterceptor
{
- public void contextInit(org.apache.tomcat.core.Context context)
- throws TomcatException
- {
- try
- {
- WebDescriptorParser webAppParser = (WebDescriptorParser)
context.getAttribute("org.jboss.web.AbstractWebContainer.WebDescriptorParser");
- if( webAppParser == null )
- return;
-
- ContextManager contextManager = context.getContextManager();
- // Get the servlet class loader
- ClassLoader scl = (ClassLoader) context.getServletLoader().getClassLoader();
- // Get the web-app.xml and jboss-web.xml deployment descriptors
- File webXml = contextManager.getAbsolute(new File(context.getDocBase() +
"/WEB-INF/web.xml"));
- File jbossWebXml = contextManager.getAbsolute(new File(context.getDocBase()
+ "/WEB-INF/jboss-web.xml"));
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = factory.newDocumentBuilder();
- Document webDoc = parser.parse(webXml);
- Element web = webDoc.getDocumentElement();
- Element jbossWeb = null;
- if( jbossWebXml.exists() == true )
+ public void contextInit(org.apache.tomcat.core.Context context) throws
TomcatException
+ {
+ try
{
- Document jbossWebDoc = parser.parse(jbossWebXml);
- jbossWeb = jbossWebDoc.getDocumentElement();
+ WebDescriptorParser webAppParser = (WebDescriptorParser)
context.getAttribute("org.jboss.web.AbstractWebContainer.WebDescriptorParser");
+ if( webAppParser == null )
+ return;
+
+ ContextManager contextManager = context.getContextManager();
+ // Get the servlet class loader
+ ClassLoader scl = (ClassLoader)
context.getServletLoader().getClassLoader();
+ // Get the web-app.xml and jboss-web.xml deployment descriptors
+ File webXml = contextManager.getAbsolute(new File(context.getDocBase()
+ "/WEB-INF/web.xml"));
+ File jbossWebXml = contextManager.getAbsolute(new
File(context.getDocBase() + "/WEB-INF/jboss-web.xml"));
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ parser.setEntityResolver(new LocalResolver());
+ Document webDoc = parser.parse(webXml);
+ Element web = webDoc.getDocumentElement();
+ Element jbossWeb = null;
+ if( jbossWebXml.exists() == true )
+ {
+ Document jbossWebDoc = parser.parse(jbossWebXml);
+ jbossWeb = jbossWebDoc.getDocumentElement();
+ }
+ // Setup the wep app JNDI java:comp/env namespace
+ webAppParser.parseWebAppDescriptors(scl, web, jbossWeb);
+ // Pass the web descriptors back to the mbean via the context
+ context.setAttribute("web-app.xml", web);
+ if( jbossWeb != null )
+ context.setAttribute("jboss-web.xml", jbossWeb);
}
- // Setup the wep app JNDI java:comp/env namespace
- webAppParser.parseWebAppDescriptors(scl, web, jbossWeb);
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /** An implementation of EntityResolver for the web.dtd and jboss-web.dtd
+ */
+ private static class LocalResolver implements EntityResolver
+ {
+ private HashMap dtds = new HashMap();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
+ public LocalResolver()
+ {
+ dtds.put("-//jBoss//DTD Web Application 2.2//EN",
"org/jboss/metadata/jboss-web.dtd");
+ dtds.put("-//JBoss//DTD Web Application 2.2//EN",
"org/jboss/metadata/jboss-web.dtd");
+ dtds.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
"org/apache/tomcat/resources/web.dtd");
+ }
+ public InputSource resolveEntity(String publicId, String systemId)
+ {
+ String dtd = (String) dtds.get(publicId);
+ InputSource is = null;
+ if (dtd != null)
+ {
+ try
+ {
+ ClassLoader loader =
Thread.currentThread().getContextClassLoader();
+ InputStream dtdStream = loader.getResourceAsStream(dtd);
+ if( dtdStream == null )
+ System.out.println("Failed to find local dtd: "+dtd);
+ else
+ is = new InputSource(dtdStream);
+ }
+ catch( Exception ex )
+ {
+ // ignore
+ }
+ }
+ return is;
+ }
+ }
+
}
+
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development