User: starksm 
  Date: 01/06/09 20:20:54

  Modified:    tomcat/src/main/org/jboss/tomcat/naming
                        JbossWebXmlReader.java
  Log:
  Add local entity resolver for web.dtd and jboss-web.dtd
  
  Revision  Changes    Path
  1.5       +77 -34    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JbossWebXmlReader.java    2001/05/23 18:26:33     1.4
  +++ JbossWebXmlReader.java    2001/06/10 03:20:54     1.5
  @@ -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,83 @@
   
   @author <a href="mailto:[EMAIL PROTECTED]";>Kevin Lewis</a>
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.4 $
  +@version $Revision: 1.5 $
   */
  -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();
  +
  +        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");
  +        }
   
  -     }
  -      catch(Exception e)
  -      {
  -         e.printStackTrace();
  -      }
  -   }
  +        public InputSource resolveEntity(String publicId, String systemId)
  +        {
  +            String dtd = (String) dtds.get(publicId);
  +            InputStream 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 null;
  +        }
  +    }
   
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to