View | Details | Raw Unified | Return to bug 34034
Collapse All | Expand All

(-)org/apache/jasper/compiler/JspConfig.java (-1 / +10 lines)
Lines 27-32 Link Here
27
import org.apache.jasper.JasperException;
27
import org.apache.jasper.JasperException;
28
import org.apache.jasper.xmlparser.ParserUtils;
28
import org.apache.jasper.xmlparser.ParserUtils;
29
import org.apache.jasper.xmlparser.TreeNode;
29
import org.apache.jasper.xmlparser.TreeNode;
30
import org.xml.sax.InputSource;
30
31
31
/**
32
/**
32
 * Handles the jsp-config element in WEB_INF/web.xml.  This is used
33
 * Handles the jsp-config element in WEB_INF/web.xml.  This is used
Lines 66-73 Link Here
66
	        return;
67
	        return;
67
	    }
68
	    }
68
69
70
	    InputSource ip = new InputSource(is);
71
72
	    // Set a SystemId, base is /WEB-INF/, avoid parser being stuck when
73
	    // trying to find relative references
74
	    ip.setSystemId("/WEB-INF/");
75
69
	    ParserUtils pu = new ParserUtils();
76
	    ParserUtils pu = new ParserUtils();
70
	    TreeNode webApp = pu.parseXMLDocument(WEB_XML, is);
77
	    // Set the ServletContext so parser could get external entities located in webapp
78
	    pu.setServletContext(ctxt);
79
	    TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip);
71
	    if (webApp == null
80
	    if (webApp == null
72
                    || !"2.4".equals(webApp.findAttribute("version"))) {
81
                    || !"2.4".equals(webApp.findAttribute("version"))) {
73
	        defaultIsELIgnored = "true";
82
	        defaultIsELIgnored = "true";
(-)org/apache/jasper/xmlparser/ParserUtils.java (-3 / +45 lines)
Lines 19-24 Link Here
19
import java.io.IOException;
19
import java.io.IOException;
20
import java.io.InputStream;
20
import java.io.InputStream;
21
21
22
import javax.servlet.ServletContext;
22
import javax.xml.parsers.DocumentBuilder;
23
import javax.xml.parsers.DocumentBuilder;
23
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.ParserConfigurationException;
25
import javax.xml.parsers.ParserConfigurationException;
Lines 65-87 Link Here
65
     */
66
     */
66
    static EntityResolver entityResolver = new MyEntityResolver();
67
    static EntityResolver entityResolver = new MyEntityResolver();
67
68
69
    /**
70
     * A ServletContext used to resolv external entites
71
     */
72
    private ServletContext ctxt;
73
    
68
    // Turn off for JSP 2.0 until switch over to using xschema.
74
    // Turn off for JSP 2.0 until switch over to using xschema.
69
    public static boolean validating = false;
75
    public static boolean validating = false;
70
76
71
77
72
    // --------------------------------------------------------- Public Methods
78
    // --------------------------------------------------------- Public Methods
73
79
80
    public void setServletContext(ServletContext pctxt) {
81
        ctxt = pctxt;	
82
    }
74
    /**
83
    /**
75
     * Parse the specified XML document, and return a <code>TreeNode</code>
84
     * Parse the specified XML document, and return a <code>TreeNode</code>
76
     * that corresponds to the root node of the document tree.
85
     * that corresponds to the root node of the document tree.
77
     *
86
     *
78
     * @param uri URI of the XML document being parsed
87
     * @param uri URI of the XML document being parsed
79
     * @param is Input stream containing the deployment descriptor
88
     * @param is Input source containing the deployment descriptor
80
     *
89
     *
81
     * @exception JasperException if an input/output error occurs
90
     * @exception JasperException if an input/output error occurs
82
     * @exception JasperException if a parsing error occurs
91
     * @exception JasperException if a parsing error occurs
83
     */
92
     */
84
    public TreeNode parseXMLDocument(String uri, InputStream is)
93
    public TreeNode parseXMLDocument(String uri, InputSource is)
85
        throws JasperException {
94
        throws JasperException {
86
95
87
        Document document = null;
96
        Document document = null;
Lines 93-99 Link Here
93
            factory.setNamespaceAware(true);
102
            factory.setNamespaceAware(true);
94
            factory.setValidating(validating);
103
            factory.setValidating(validating);
95
            DocumentBuilder builder = factory.newDocumentBuilder();
104
            DocumentBuilder builder = factory.newDocumentBuilder();
96
            builder.setEntityResolver(entityResolver);
105
            
106
            // If we have ServletContext, pass it to EntityResolver which
107
            // will try to grab external entities via getResourceAsStream
108
            if (ctxt != null) {
109
            	MyEntityResolver mer = new MyEntityResolver();
110
            	mer.ctxt = ctxt;
111
                builder.setEntityResolver(mer);                
112
            }
113
            else     
114
                builder.setEntityResolver(entityResolver);
97
            builder.setErrorHandler(errorHandler);
115
            builder.setErrorHandler(errorHandler);
98
            document = builder.parse(is);
116
            document = builder.parse(is);
99
	} catch (ParserConfigurationException ex) {
117
	} catch (ParserConfigurationException ex) {
Lines 119-124 Link Here
119
    }
137
    }
120
138
121
139
140
    /**
141
     * Parse the specified XML document, and return a <code>TreeNode</code>
142
     * that corresponds to the root node of the document tree.
143
     *
144
     * @param uri URI of the XML document being parsed
145
     * @param is Input stream containing the deployment descriptor
146
     *
147
     * @exception JasperException if an input/output error occurs
148
     * @exception JasperException if a parsing error occurs
149
     */
150
    public TreeNode parseXMLDocument(String uri, InputStream is)
151
        throws JasperException {
152
    	return (parseXMLDocument(uri, new InputSource(is)));
153
    }
122
    // ------------------------------------------------------ Protected Methods
154
    // ------------------------------------------------------ Protected Methods
123
155
124
156
Lines 176-181 Link Here
176
208
177
class MyEntityResolver implements EntityResolver {
209
class MyEntityResolver implements EntityResolver {
178
    
210
    
211
    ServletContext ctxt = null;
212
	
179
    public InputSource resolveEntity(String publicId, String systemId)
213
    public InputSource resolveEntity(String publicId, String systemId)
180
	throws SAXException
214
	throws SAXException
181
    {
215
    {
Lines 194-199 Link Here
194
		return isrc;
228
		return isrc;
195
	    }
229
	    }
196
	}
230
	}
231
	    // a ServletContext was defined, use it and resolve entities located in /WEB-INF
232
	    if (ctxt != null) {
233
             if ((systemId != null) && (publicId == null)) {	    		
234
                 if (systemId.startsWith("file:///WEB-INF/"))
235
                     return new InputSource(ctxt.getResourceAsStream(systemId.substring(7)));
236
             }	    	
237
	    }
238
	    
197
        if (ParserUtils.log.isDebugEnabled())
239
        if (ParserUtils.log.isDebugEnabled())
198
            ParserUtils.log.debug("Resolve entity failed"  + publicId + " "
240
            ParserUtils.log.debug("Resolve entity failed"  + publicId + " "
199
			   + systemId );
241
			   + systemId );

Return to bug 34034