Index: org/apache/jasper/compiler/JspConfig.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspConfig.java,v
retrieving revision 1.16
diff -u -r1.16 JspConfig.java
--- org/apache/jasper/compiler/JspConfig.java 17 Mar 2004 19:23:03 -0000 1.16
+++ org/apache/jasper/compiler/JspConfig.java 18 Mar 2005 09:31:46 -0000
@@ -27,6 +27,7 @@
import org.apache.jasper.JasperException;
import org.apache.jasper.xmlparser.ParserUtils;
import org.apache.jasper.xmlparser.TreeNode;
+import org.xml.sax.InputSource;
/**
* Handles the jsp-config element in WEB_INF/web.xml. This is used
@@ -66,8 +67,16 @@
return;
}
+ InputSource ip = new InputSource(is);
+
+ // Set a SystemId, base is /WEB-INF/, avoid parser being stuck when
+ // trying to find relative references
+ ip.setSystemId("/WEB-INF/");
+
ParserUtils pu = new ParserUtils();
- TreeNode webApp = pu.parseXMLDocument(WEB_XML, is);
+ // Set the ServletContext so parser could get external entities located in webapp
+ pu.setServletContext(ctxt);
+ TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip);
if (webApp == null
|| !"2.4".equals(webApp.findAttribute("version"))) {
defaultIsELIgnored = "true";
Index: org/apache/jasper/xmlparser/ParserUtils.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/xmlparser/ParserUtils.java,v
retrieving revision 1.11
diff -u -r1.11 ParserUtils.java
--- org/apache/jasper/xmlparser/ParserUtils.java 17 Sep 2004 21:02:34 -0000 1.11
+++ org/apache/jasper/xmlparser/ParserUtils.java 18 Mar 2005 09:31:46 -0000
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
+import javax.servlet.ServletContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -65,23 +66,31 @@
*/
static EntityResolver entityResolver = new MyEntityResolver();
+ /**
+ * A ServletContext used to resolv external entites
+ */
+ private ServletContext ctxt;
+
// Turn off for JSP 2.0 until switch over to using xschema.
public static boolean validating = false;
// --------------------------------------------------------- Public Methods
+ public void setServletContext(ServletContext pctxt) {
+ ctxt = pctxt;
+ }
/**
* Parse the specified XML document, and return a TreeNode
* that corresponds to the root node of the document tree.
*
* @param uri URI of the XML document being parsed
- * @param is Input stream containing the deployment descriptor
+ * @param is Input source containing the deployment descriptor
*
* @exception JasperException if an input/output error occurs
* @exception JasperException if a parsing error occurs
*/
- public TreeNode parseXMLDocument(String uri, InputStream is)
+ public TreeNode parseXMLDocument(String uri, InputSource is)
throws JasperException {
Document document = null;
@@ -93,7 +102,16 @@
factory.setNamespaceAware(true);
factory.setValidating(validating);
DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver(entityResolver);
+
+ // If we have ServletContext, pass it to EntityResolver which
+ // will try to grab external entities via getResourceAsStream
+ if (ctxt != null) {
+ MyEntityResolver mer = new MyEntityResolver();
+ mer.ctxt = ctxt;
+ builder.setEntityResolver(mer);
+ }
+ else
+ builder.setEntityResolver(entityResolver);
builder.setErrorHandler(errorHandler);
document = builder.parse(is);
} catch (ParserConfigurationException ex) {
@@ -119,6 +137,20 @@
}
+ /**
+ * Parse the specified XML document, and return a TreeNode
+ * that corresponds to the root node of the document tree.
+ *
+ * @param uri URI of the XML document being parsed
+ * @param is Input stream containing the deployment descriptor
+ *
+ * @exception JasperException if an input/output error occurs
+ * @exception JasperException if a parsing error occurs
+ */
+ public TreeNode parseXMLDocument(String uri, InputStream is)
+ throws JasperException {
+ return (parseXMLDocument(uri, new InputSource(is)));
+ }
// ------------------------------------------------------ Protected Methods
@@ -176,6 +208,8 @@
class MyEntityResolver implements EntityResolver {
+ ServletContext ctxt = null;
+
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException
{
@@ -194,6 +228,14 @@
return isrc;
}
}
+ // a ServletContext was defined, use it and resolve entities located in /WEB-INF
+ if (ctxt != null) {
+ if ((systemId != null) && (publicId == null)) {
+ if (systemId.startsWith("file:///WEB-INF/"))
+ return new InputSource(ctxt.getResourceAsStream(systemId.substring(7)));
+ }
+ }
+
if (ParserUtils.log.isDebugEnabled())
ParserUtils.log.debug("Resolve entity failed" + publicId + " "
+ systemId );