|
|
689285 |
diff --git a/standard/src/javax/servlet/jsp/jstl/tlv/PageParser.java b/standard/src/javax/servlet/jsp/jstl/tlv/PageParser.java
|
|
|
689285 |
new file mode 100644
|
|
|
689285 |
index 0000000..29d5f17
|
|
|
689285 |
--- /dev/null
|
|
|
689285 |
+++ b/standard/src/javax/servlet/jsp/jstl/tlv/PageParser.java
|
|
|
689285 |
@@ -0,0 +1,45 @@
|
|
|
689285 |
+package javax.servlet.jsp.jstl.tlv;
|
|
|
689285 |
+
|
|
|
689285 |
+import java.io.IOException;
|
|
|
689285 |
+import java.io.InputStream;
|
|
|
689285 |
+
|
|
|
689285 |
+import javax.servlet.jsp.tagext.PageData;
|
|
|
689285 |
+import javax.xml.XMLConstants;
|
|
|
689285 |
+import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
+import javax.xml.parsers.SAXParser;
|
|
|
689285 |
+import javax.xml.parsers.SAXParserFactory;
|
|
|
689285 |
+
|
|
|
689285 |
+import org.xml.sax.SAXException;
|
|
|
689285 |
+import org.xml.sax.SAXNotRecognizedException;
|
|
|
689285 |
+import org.xml.sax.SAXNotSupportedException;
|
|
|
689285 |
+import org.xml.sax.helpers.DefaultHandler;
|
|
|
689285 |
+
|
|
|
689285 |
+class PageParser {
|
|
|
689285 |
+ private final SAXParserFactory parserFactory;
|
|
|
689285 |
+
|
|
|
689285 |
+ PageParser(boolean namespaceAware) throws SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException {
|
|
|
689285 |
+ parserFactory = SAXParserFactory.newInstance();
|
|
|
689285 |
+
|
|
|
689285 |
+ parserFactory.setNamespaceAware(namespaceAware);
|
|
|
689285 |
+ parserFactory.setValidating(false);
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
|
689285 |
+ } catch (SAXNotSupportedException e) {
|
|
|
689285 |
+ // FSP is not supported, GCJ?
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ void parse(PageData pageData, DefaultHandler handler) throws ParserConfigurationException, SAXException, IOException {
|
|
|
689285 |
+ SAXParser parser = parserFactory.newSAXParser();
|
|
|
689285 |
+ InputStream is = pageData.getInputStream();
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ parser.parse(is, handler);
|
|
|
689285 |
+ } finally {
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ is.close();
|
|
|
689285 |
+ } catch (IOException e) {
|
|
|
689285 |
+ // Suppress.
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+}
|
|
|
689285 |
diff --git a/standard/src/javax/servlet/jsp/jstl/tlv/PermittedTaglibsTLV.java b/standard/src/javax/servlet/jsp/jstl/tlv/PermittedTaglibsTLV.java
|
|
|
689285 |
index 4ba23d1..8e42449 100644
|
|
|
689285 |
--- a/standard/src/javax/servlet/jsp/jstl/tlv/PermittedTaglibsTLV.java
|
|
|
689285 |
+++ b/standard/src/javax/servlet/jsp/jstl/tlv/PermittedTaglibsTLV.java
|
|
|
689285 |
@@ -25,8 +25,6 @@ import javax.servlet.jsp.tagext.PageData;
|
|
|
689285 |
import javax.servlet.jsp.tagext.TagLibraryValidator;
|
|
|
689285 |
import javax.servlet.jsp.tagext.ValidationMessage;
|
|
|
689285 |
import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
-import javax.xml.parsers.SAXParser;
|
|
|
689285 |
-import javax.xml.parsers.SAXParserFactory;
|
|
|
689285 |
|
|
|
689285 |
import org.xml.sax.Attributes;
|
|
|
689285 |
import org.xml.sax.SAXException;
|
|
|
689285 |
@@ -104,10 +102,8 @@ public class PermittedTaglibsTLV extends TagLibraryValidator {
|
|
|
689285 |
DefaultHandler h = new PermittedTaglibsHandler();
|
|
|
689285 |
|
|
|
689285 |
// parse the page
|
|
|
689285 |
- SAXParserFactory f = SAXParserFactory.newInstance();
|
|
|
689285 |
- f.setValidating(true);
|
|
|
689285 |
- SAXParser p = f.newSAXParser();
|
|
|
689285 |
- p.parse(page.getInputStream(), h);
|
|
|
689285 |
+ PageParser p = new PageParser(false);
|
|
|
689285 |
+ p.parse(page, h);
|
|
|
689285 |
|
|
|
689285 |
if (failed)
|
|
|
689285 |
return vmFromString(
|
|
|
689285 |
diff --git a/standard/src/javax/servlet/jsp/jstl/tlv/ScriptFreeTLV.java b/standard/src/javax/servlet/jsp/jstl/tlv/ScriptFreeTLV.java
|
|
|
689285 |
index d82b5c1..0bc4c11 100644
|
|
|
689285 |
--- a/standard/src/javax/servlet/jsp/jstl/tlv/ScriptFreeTLV.java
|
|
|
689285 |
+++ b/standard/src/javax/servlet/jsp/jstl/tlv/ScriptFreeTLV.java
|
|
|
689285 |
@@ -17,15 +17,12 @@
|
|
|
689285 |
package javax.servlet.jsp.jstl.tlv;
|
|
|
689285 |
|
|
|
689285 |
import java.io.IOException;
|
|
|
689285 |
-import java.io.InputStream;
|
|
|
689285 |
import java.util.Map;
|
|
|
689285 |
|
|
|
689285 |
import javax.servlet.jsp.tagext.PageData;
|
|
|
689285 |
import javax.servlet.jsp.tagext.TagLibraryValidator;
|
|
|
689285 |
import javax.servlet.jsp.tagext.ValidationMessage;
|
|
|
689285 |
import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
-import javax.xml.parsers.SAXParser;
|
|
|
689285 |
-import javax.xml.parsers.SAXParserFactory;
|
|
|
689285 |
|
|
|
689285 |
import org.xml.sax.Attributes;
|
|
|
689285 |
import org.xml.sax.SAXException;
|
|
|
689285 |
@@ -58,17 +55,12 @@ public class ScriptFreeTLV extends TagLibraryValidator {
|
|
|
689285 |
private boolean allowScriptlets = false;
|
|
|
689285 |
private boolean allowExpressions = false;
|
|
|
689285 |
private boolean allowRTExpressions = false;
|
|
|
689285 |
- private SAXParserFactory factory;
|
|
|
689285 |
+ private PageParser parser;
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
* Constructs a new validator instance.
|
|
|
689285 |
- * Initializes the parser factory to create non-validating, namespace-aware
|
|
|
689285 |
- * SAX parsers.
|
|
|
689285 |
*/
|
|
|
689285 |
public ScriptFreeTLV () {
|
|
|
689285 |
- factory = SAXParserFactory.newInstance();
|
|
|
689285 |
- factory.setValidating(false);
|
|
|
689285 |
- factory.setNamespaceAware(true);
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
@@ -102,15 +94,12 @@ public class ScriptFreeTLV extends TagLibraryValidator {
|
|
|
689285 |
*/
|
|
|
689285 |
public ValidationMessage[] validate
|
|
|
689285 |
(String prefix, String uri, PageData page) {
|
|
|
689285 |
- InputStream in = null;
|
|
|
689285 |
- SAXParser parser;
|
|
|
689285 |
MyContentHandler handler = new MyContentHandler();
|
|
|
689285 |
try {
|
|
|
689285 |
- synchronized (factory) {
|
|
|
689285 |
- parser = factory.newSAXParser();
|
|
|
689285 |
- }
|
|
|
689285 |
- in = page.getInputStream();
|
|
|
689285 |
- parser.parse(in, handler);
|
|
|
689285 |
+ // Initializes the parser factory to create non-validating, namespace-aware
|
|
|
689285 |
+ // SAX parsers.
|
|
|
689285 |
+ parser = new PageParser(true);
|
|
|
689285 |
+ parser.parse(page, handler);
|
|
|
689285 |
}
|
|
|
689285 |
catch (ParserConfigurationException e) {
|
|
|
689285 |
return vmFromString(e.toString());
|
|
|
689285 |
@@ -121,9 +110,7 @@ public class ScriptFreeTLV extends TagLibraryValidator {
|
|
|
689285 |
catch (IOException e) {
|
|
|
689285 |
return vmFromString(e.toString());
|
|
|
689285 |
}
|
|
|
689285 |
- finally {
|
|
|
689285 |
- if (in != null) try { in.close(); } catch (IOException e) {}
|
|
|
689285 |
- }
|
|
|
689285 |
+
|
|
|
689285 |
return handler.reportResults();
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/extra/spath/SPathFilter.java b/standard/src/org/apache/taglibs/standard/extra/spath/SPathFilter.java
|
|
|
689285 |
index bead698..c654ca9 100644
|
|
|
689285 |
--- a/standard/src/org/apache/taglibs/standard/extra/spath/SPathFilter.java
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/extra/spath/SPathFilter.java
|
|
|
689285 |
@@ -20,6 +20,9 @@ import java.io.IOException;
|
|
|
689285 |
import java.util.List;
|
|
|
689285 |
import java.util.Stack;
|
|
|
689285 |
|
|
|
689285 |
+import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
+
|
|
|
689285 |
+import org.apache.taglibs.standard.util.XmlUtil;
|
|
|
689285 |
import org.apache.xalan.serialize.Serializer;
|
|
|
689285 |
import org.apache.xalan.serialize.SerializerFactory;
|
|
|
689285 |
import org.apache.xalan.templates.OutputProperties;
|
|
|
689285 |
@@ -29,7 +32,6 @@ import org.xml.sax.SAXException;
|
|
|
689285 |
import org.xml.sax.XMLFilter;
|
|
|
689285 |
import org.xml.sax.XMLReader;
|
|
|
689285 |
import org.xml.sax.helpers.XMLFilterImpl;
|
|
|
689285 |
-import org.xml.sax.helpers.XMLReaderFactory;
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
* Filters a SAX stream based on a single supplied SPath
|
|
|
689285 |
@@ -70,7 +72,12 @@ System.setProperty("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");
|
|
|
689285 |
|
|
|
689285 |
// construct the appropriate SAX chain
|
|
|
689285 |
// (reader -> us -> serializer)
|
|
|
689285 |
- XMLReader r = XMLReaderFactory.createXMLReader();
|
|
|
689285 |
+ XMLReader r;
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ r = XmlUtil.newSAXParser().getXMLReader();
|
|
|
689285 |
+ } catch (ParserConfigurationException e) {
|
|
|
689285 |
+ throw new SAXException(e);
|
|
|
689285 |
+ }
|
|
|
689285 |
XMLFilter f1 = new SPathFilter(p);
|
|
|
689285 |
XMLFilter f2 = new XMLFilterImpl();
|
|
|
689285 |
f1.setParent(r);
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/tag/common/xml/ParseSupport.java b/standard/src/org/apache/taglibs/standard/tag/common/xml/ParseSupport.java
|
|
|
689285 |
index 3bc8a54..7118919 100644
|
|
|
689285 |
--- a/standard/src/org/apache/taglibs/standard/tag/common/xml/ParseSupport.java
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/tag/common/xml/ParseSupport.java
|
|
|
689285 |
@@ -28,24 +28,21 @@ import javax.servlet.jsp.JspTagException;
|
|
|
689285 |
import javax.servlet.jsp.PageContext;
|
|
|
689285 |
import javax.servlet.jsp.tagext.BodyTagSupport;
|
|
|
689285 |
import javax.xml.parsers.DocumentBuilder;
|
|
|
689285 |
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
689285 |
import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
import javax.xml.transform.TransformerConfigurationException;
|
|
|
689285 |
-import javax.xml.transform.TransformerFactory;
|
|
|
689285 |
import javax.xml.transform.dom.DOMResult;
|
|
|
689285 |
-import javax.xml.transform.sax.SAXTransformerFactory;
|
|
|
689285 |
import javax.xml.transform.sax.TransformerHandler;
|
|
|
689285 |
|
|
|
689285 |
import org.apache.taglibs.standard.resources.Resources;
|
|
|
689285 |
import org.apache.taglibs.standard.tag.common.core.ImportSupport;
|
|
|
689285 |
import org.apache.taglibs.standard.tag.common.core.Util;
|
|
|
689285 |
+import org.apache.taglibs.standard.util.XmlUtil;
|
|
|
689285 |
import org.w3c.dom.Document;
|
|
|
689285 |
import org.xml.sax.EntityResolver;
|
|
|
689285 |
import org.xml.sax.InputSource;
|
|
|
689285 |
import org.xml.sax.SAXException;
|
|
|
689285 |
import org.xml.sax.XMLFilter;
|
|
|
689285 |
import org.xml.sax.XMLReader;
|
|
|
689285 |
-import org.xml.sax.helpers.XMLReaderFactory;
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
* Support for tag handlers for <parse>, the XML parsing tag.
|
|
|
689285 |
@@ -70,9 +67,7 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
private int scopeDom; // processed 'scopeDom' attr
|
|
|
689285 |
|
|
|
689285 |
// state in support of XML parsing...
|
|
|
689285 |
- private DocumentBuilderFactory dbf;
|
|
|
689285 |
private DocumentBuilder db;
|
|
|
689285 |
- private TransformerFactory tf;
|
|
|
689285 |
private TransformerHandler th;
|
|
|
689285 |
|
|
|
689285 |
|
|
|
689285 |
@@ -89,9 +84,7 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
xml = null;
|
|
|
689285 |
systemId = null;
|
|
|
689285 |
filter = null;
|
|
|
689285 |
- dbf = null;
|
|
|
689285 |
db = null;
|
|
|
689285 |
- tf = null;
|
|
|
689285 |
th = null;
|
|
|
689285 |
scope = PageContext.PAGE_SCOPE;
|
|
|
689285 |
scopeDom = PageContext.PAGE_SCOPE;
|
|
|
689285 |
@@ -106,22 +99,13 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
try {
|
|
|
689285 |
|
|
|
689285 |
// set up our DocumentBuilder
|
|
|
689285 |
- if (dbf == null) {
|
|
|
689285 |
- dbf = DocumentBuilderFactory.newInstance();
|
|
|
689285 |
- dbf.setNamespaceAware(true);
|
|
|
689285 |
- dbf.setValidating(false);
|
|
|
689285 |
+ if (db == null) {
|
|
|
689285 |
+ db = XmlUtil.newDocumentBuilder();
|
|
|
689285 |
}
|
|
|
689285 |
- db = dbf.newDocumentBuilder();
|
|
|
689285 |
|
|
|
689285 |
// if we've gotten a filter, set up a transformer to support it
|
|
|
689285 |
if (filter != null) {
|
|
|
689285 |
- if (tf == null)
|
|
|
689285 |
- tf = TransformerFactory.newInstance();
|
|
|
689285 |
- if (!tf.getFeature(SAXTransformerFactory.FEATURE))
|
|
|
689285 |
- throw new JspTagException(
|
|
|
689285 |
- Resources.getMessage("PARSE_NO_SAXTRANSFORMER"));
|
|
|
689285 |
- SAXTransformerFactory stf = (SAXTransformerFactory) tf;
|
|
|
689285 |
- th = stf.newTransformerHandler();
|
|
|
689285 |
+ th = XmlUtil.newTransformerHandler();
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
// produce a Document by parsing whatever the attributes tell us to use
|
|
|
689285 |
@@ -172,15 +156,14 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
|
|
|
689285 |
/** Parses the given InputSource after, applying the given XMLFilter. */
|
|
|
689285 |
private Document parseInputSourceWithFilter(InputSource s, XMLFilter f)
|
|
|
689285 |
- throws SAXException, IOException {
|
|
|
689285 |
+ throws SAXException, IOException, ParserConfigurationException {
|
|
|
689285 |
if (f != null) {
|
|
|
689285 |
// prepare an output Document
|
|
|
689285 |
Document o = db.newDocument();
|
|
|
689285 |
|
|
|
689285 |
// use TrAX to adapt SAX events to a Document object
|
|
|
689285 |
th.setResult(new DOMResult(o));
|
|
|
689285 |
- XMLReader xr = XMLReaderFactory.createXMLReader();
|
|
|
689285 |
- xr.setEntityResolver(new JstlEntityResolver(pageContext));
|
|
|
689285 |
+ XMLReader xr = XmlUtil.newXMLReader(new JstlEntityResolver(pageContext));
|
|
|
689285 |
// (note that we overwrite the filter's parent. this seems
|
|
|
689285 |
// to be expected usage. we could cache and reset the old
|
|
|
689285 |
// parent, but you can't setParent(null), so this wouldn't
|
|
|
689285 |
@@ -195,20 +178,20 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
|
|
|
689285 |
/** Parses the given Reader after applying the given XMLFilter. */
|
|
|
689285 |
private Document parseReaderWithFilter(Reader r, XMLFilter f)
|
|
|
689285 |
- throws SAXException, IOException {
|
|
|
689285 |
+ throws SAXException, IOException, ParserConfigurationException {
|
|
|
689285 |
return parseInputSourceWithFilter(new InputSource(r), f);
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
/** Parses the given String after applying the given XMLFilter. */
|
|
|
689285 |
private Document parseStringWithFilter(String s, XMLFilter f)
|
|
|
689285 |
- throws SAXException, IOException {
|
|
|
689285 |
+ throws SAXException, IOException, ParserConfigurationException {
|
|
|
689285 |
StringReader r = new StringReader(s);
|
|
|
689285 |
return parseReaderWithFilter(r, f);
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
/** Parses the given Reader after applying the given XMLFilter. */
|
|
|
689285 |
private Document parseURLWithFilter(String url, XMLFilter f)
|
|
|
689285 |
- throws SAXException, IOException {
|
|
|
689285 |
+ throws SAXException, IOException, ParserConfigurationException {
|
|
|
689285 |
return parseInputSourceWithFilter(new InputSource(url), f);
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
@@ -264,8 +247,10 @@ public abstract class ParseSupport extends BodyTagSupport {
|
|
|
689285 |
systemId = systemId.substring(5);
|
|
|
689285 |
|
|
|
689285 |
// we're only concerned with relative URLs
|
|
|
689285 |
- if (ImportSupport.isAbsoluteUrl(systemId))
|
|
|
689285 |
- return null;
|
|
|
689285 |
+ if (ImportSupport.isAbsoluteUrl(systemId)) {
|
|
|
689285 |
+ XmlUtil.checkProtocol(XmlUtil.ALLOWED_PROTOCOLS, systemId);
|
|
|
689285 |
+ return null;
|
|
|
689285 |
+ }
|
|
|
689285 |
|
|
|
689285 |
// for relative URLs, load and wrap the resource.
|
|
|
689285 |
// don't bother checking for 'null' since we specifically want
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java b/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java
|
|
|
689285 |
index 65d56f5..4751887 100644
|
|
|
689285 |
--- a/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java
|
|
|
689285 |
@@ -29,14 +29,12 @@ import javax.servlet.jsp.JspTagException;
|
|
|
689285 |
import javax.servlet.jsp.PageContext;
|
|
|
689285 |
import javax.servlet.jsp.tagext.BodyTagSupport;
|
|
|
689285 |
import javax.xml.parsers.DocumentBuilder;
|
|
|
689285 |
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
689285 |
import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
import javax.xml.transform.Result;
|
|
|
689285 |
import javax.xml.transform.Source;
|
|
|
689285 |
import javax.xml.transform.Transformer;
|
|
|
689285 |
import javax.xml.transform.TransformerConfigurationException;
|
|
|
689285 |
import javax.xml.transform.TransformerException;
|
|
|
689285 |
-import javax.xml.transform.TransformerFactory;
|
|
|
689285 |
import javax.xml.transform.URIResolver;
|
|
|
689285 |
import javax.xml.transform.dom.DOMResult;
|
|
|
689285 |
import javax.xml.transform.dom.DOMSource;
|
|
|
689285 |
@@ -47,12 +45,12 @@ import javax.xml.transform.stream.StreamSource;
|
|
|
689285 |
import org.apache.taglibs.standard.resources.Resources;
|
|
|
689285 |
import org.apache.taglibs.standard.tag.common.core.ImportSupport;
|
|
|
689285 |
import org.apache.taglibs.standard.tag.common.core.Util;
|
|
|
689285 |
+import org.apache.taglibs.standard.util.XmlUtil;
|
|
|
689285 |
import org.w3c.dom.Document;
|
|
|
689285 |
import org.w3c.dom.Node;
|
|
|
689285 |
import org.xml.sax.InputSource;
|
|
|
689285 |
import org.xml.sax.SAXException;
|
|
|
689285 |
import org.xml.sax.XMLReader;
|
|
|
689285 |
-import org.xml.sax.helpers.XMLReaderFactory;
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
* Support for tag handlers for <transform>, the XML transformation
|
|
|
689285 |
@@ -77,9 +75,7 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
private String var; // 'var' attribute
|
|
|
689285 |
private int scope; // processed 'scope' attr
|
|
|
689285 |
private Transformer t; // actual Transformer
|
|
|
689285 |
- private TransformerFactory tf; // reusable factory
|
|
|
689285 |
private DocumentBuilder db; // reusable factory
|
|
|
689285 |
- private DocumentBuilderFactory dbf; // reusable factory
|
|
|
689285 |
|
|
|
689285 |
|
|
|
689285 |
//*********************************************************************
|
|
|
689285 |
@@ -95,7 +91,6 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
xmlSystemId = xsltSystemId = null;
|
|
|
689285 |
var = null;
|
|
|
689285 |
result = null;
|
|
|
689285 |
- tf = null;
|
|
|
689285 |
scope = PageContext.PAGE_SCOPE;
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
@@ -114,18 +109,8 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
//************************************
|
|
|
689285 |
// Initialize
|
|
|
689285 |
|
|
|
689285 |
- // set up our DocumentBuilderFactory if necessary
|
|
|
689285 |
- if (dbf == null) {
|
|
|
689285 |
- dbf = DocumentBuilderFactory.newInstance();
|
|
|
689285 |
- dbf.setNamespaceAware(true);
|
|
|
689285 |
- dbf.setValidating(false);
|
|
|
689285 |
- }
|
|
|
689285 |
if (db == null)
|
|
|
689285 |
- db = dbf.newDocumentBuilder();
|
|
|
689285 |
-
|
|
|
689285 |
- // set up the TransformerFactory if necessary
|
|
|
689285 |
- if (tf == null)
|
|
|
689285 |
- tf = TransformerFactory.newInstance();
|
|
|
689285 |
+ db = XmlUtil.newDocumentBuilder();
|
|
|
689285 |
|
|
|
689285 |
//************************************
|
|
|
689285 |
// Produce transformer
|
|
|
689285 |
@@ -141,8 +126,8 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
throw new JspTagException(
|
|
|
689285 |
Resources.getMessage("TRANSFORM_NO_TRANSFORMER"));
|
|
|
689285 |
}
|
|
|
689285 |
- tf.setURIResolver(new JstlUriResolver(pageContext));
|
|
|
689285 |
- t = tf.newTransformer(s);
|
|
|
689285 |
+ t = XmlUtil.newTransformer(s);
|
|
|
689285 |
+ t.setURIResolver(new JstlUriResolver(pageContext));
|
|
|
689285 |
|
|
|
689285 |
return EVAL_BODY_BUFFERED;
|
|
|
689285 |
|
|
|
689285 |
@@ -257,9 +242,7 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
} else if (o instanceof Reader) {
|
|
|
689285 |
// explicitly go through SAX to maintain control
|
|
|
689285 |
// over how relative external entities resolve
|
|
|
689285 |
- XMLReader xr = XMLReaderFactory.createXMLReader();
|
|
|
689285 |
- xr.setEntityResolver(
|
|
|
689285 |
- new ParseSupport.JstlEntityResolver(pageContext));
|
|
|
689285 |
+ XMLReader xr = XmlUtil.newXMLReader(new ParseSupport.JstlEntityResolver(pageContext));
|
|
|
689285 |
InputSource s = new InputSource((Reader) o);
|
|
|
689285 |
s.setSystemId(wrapSystemId(systemId));
|
|
|
689285 |
Source result = new SAXSource(xr, s);
|
|
|
689285 |
@@ -340,8 +323,10 @@ public abstract class TransformSupport extends BodyTagSupport {
|
|
|
689285 |
|
|
|
689285 |
// we're only concerned with relative URLs
|
|
|
689285 |
if (ImportSupport.isAbsoluteUrl(href)
|
|
|
689285 |
- || (base != null && ImportSupport.isAbsoluteUrl(base)))
|
|
|
689285 |
+ || (base != null && ImportSupport.isAbsoluteUrl(base))) {
|
|
|
689285 |
+ XmlUtil.checkProtocol(XmlUtil.ALLOWED_PROTOCOLS, base);
|
|
|
689285 |
return null;
|
|
|
689285 |
+ }
|
|
|
689285 |
|
|
|
689285 |
// base is relative; remove everything after trailing '/'
|
|
|
689285 |
if (base == null || base.lastIndexOf("/") == -1)
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java b/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java
|
|
|
689285 |
index 9b66d73..20a8c0b 100644
|
|
|
689285 |
--- a/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java
|
|
|
689285 |
@@ -28,10 +28,10 @@ import javax.servlet.jsp.PageContext;
|
|
|
689285 |
import javax.servlet.jsp.tagext.Tag;
|
|
|
689285 |
import javax.servlet.jsp.tagext.TagSupport;
|
|
|
689285 |
import javax.xml.parsers.DocumentBuilder;
|
|
|
689285 |
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
689285 |
import javax.xml.transform.TransformerException;
|
|
|
689285 |
|
|
|
689285 |
import org.apache.taglibs.standard.resources.Resources;
|
|
|
689285 |
+import org.apache.taglibs.standard.util.XmlUtil;
|
|
|
689285 |
import org.apache.xml.utils.QName;
|
|
|
689285 |
import org.apache.xpath.VariableStack;
|
|
|
689285 |
import org.apache.xpath.XPathContext;
|
|
|
689285 |
@@ -394,18 +394,14 @@ public class XPathUtil {
|
|
|
689285 |
}
|
|
|
689285 |
}
|
|
|
689285 |
|
|
|
689285 |
- static DocumentBuilderFactory dbf = null;
|
|
|
689285 |
static DocumentBuilder db = null;
|
|
|
689285 |
static Document d = null;
|
|
|
689285 |
|
|
|
689285 |
static Document getDummyDocument( ) {
|
|
|
689285 |
try {
|
|
|
689285 |
- if ( dbf == null ) {
|
|
|
689285 |
- dbf = DocumentBuilderFactory.newInstance();
|
|
|
689285 |
- dbf.setNamespaceAware( true );
|
|
|
689285 |
- dbf.setValidating( false );
|
|
|
689285 |
+ if ( db == null ) {
|
|
|
689285 |
+ db = XmlUtil.newDocumentBuilder();
|
|
|
689285 |
}
|
|
|
689285 |
- db = dbf.newDocumentBuilder();
|
|
|
689285 |
|
|
|
689285 |
DOMImplementation dim = db.getDOMImplementation();
|
|
|
689285 |
d = dim.createDocument("http://java.sun.com/jstl", "dummyroot", null);
|
|
|
689285 |
@@ -419,12 +415,9 @@ public class XPathUtil {
|
|
|
689285 |
|
|
|
689285 |
static Document getDummyDocumentWithoutRoot( ) {
|
|
|
689285 |
try {
|
|
|
689285 |
- if ( dbf == null ) {
|
|
|
689285 |
- dbf = DocumentBuilderFactory.newInstance();
|
|
|
689285 |
- dbf.setNamespaceAware( true );
|
|
|
689285 |
- dbf.setValidating( false );
|
|
|
689285 |
+ if ( db == null ) {
|
|
|
689285 |
+ db = XmlUtil.newDocumentBuilder();
|
|
|
689285 |
}
|
|
|
689285 |
- db = dbf.newDocumentBuilder();
|
|
|
689285 |
|
|
|
689285 |
d = db.newDocument();
|
|
|
689285 |
return d;
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/tlv/JstlBaseTLV.java b/standard/src/org/apache/taglibs/standard/tlv/JstlBaseTLV.java
|
|
|
689285 |
index e2d6092..6f81f89 100644
|
|
|
689285 |
--- a/standard/src/org/apache/taglibs/standard/tlv/JstlBaseTLV.java
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/tlv/JstlBaseTLV.java
|
|
|
689285 |
@@ -17,6 +17,7 @@
|
|
|
689285 |
package org.apache.taglibs.standard.tlv;
|
|
|
689285 |
|
|
|
689285 |
import java.io.IOException;
|
|
|
689285 |
+import java.io.InputStream;
|
|
|
689285 |
import java.util.HashMap;
|
|
|
689285 |
import java.util.HashSet;
|
|
|
689285 |
import java.util.Map;
|
|
|
689285 |
@@ -31,14 +32,15 @@ import javax.servlet.jsp.tagext.TagData;
|
|
|
689285 |
import javax.servlet.jsp.tagext.TagLibraryValidator;
|
|
|
689285 |
import javax.servlet.jsp.tagext.ValidationMessage;
|
|
|
689285 |
import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
-import javax.xml.parsers.SAXParser;
|
|
|
689285 |
-import javax.xml.parsers.SAXParserFactory;
|
|
|
689285 |
|
|
|
689285 |
import org.apache.taglibs.standard.lang.support.ExpressionEvaluator;
|
|
|
689285 |
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
|
|
|
689285 |
import org.apache.taglibs.standard.resources.Resources;
|
|
|
689285 |
+import org.apache.taglibs.standard.util.XmlUtil;
|
|
|
689285 |
import org.xml.sax.Attributes;
|
|
|
689285 |
+import org.xml.sax.InputSource;
|
|
|
689285 |
import org.xml.sax.SAXException;
|
|
|
689285 |
+import org.xml.sax.XMLReader;
|
|
|
689285 |
import org.xml.sax.helpers.DefaultHandler;
|
|
|
689285 |
|
|
|
689285 |
/**
|
|
|
689285 |
@@ -149,11 +151,18 @@ public abstract class JstlBaseTLV extends TagLibraryValidator {
|
|
|
689285 |
DefaultHandler h = getHandler();
|
|
|
689285 |
|
|
|
689285 |
// parse the page
|
|
|
689285 |
- SAXParserFactory f = SAXParserFactory.newInstance();
|
|
|
689285 |
- f.setValidating(false);
|
|
|
689285 |
- f.setNamespaceAware(true);
|
|
|
689285 |
- SAXParser p = f.newSAXParser();
|
|
|
689285 |
- p.parse(page.getInputStream(), h);
|
|
|
689285 |
+ XMLReader xmlReader = XmlUtil.newXMLReader(null);
|
|
|
689285 |
+ xmlReader.setContentHandler(h);
|
|
|
689285 |
+ InputStream inputStream = page.getInputStream();
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ xmlReader.parse(new InputSource(inputStream));
|
|
|
689285 |
+ } finally {
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ inputStream.close();
|
|
|
689285 |
+ } catch (IOException e) {
|
|
|
689285 |
+ // Suppressed.
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
|
|
|
689285 |
if (messageVector.size() == 0)
|
|
|
689285 |
return null;
|
|
|
689285 |
diff --git a/standard/src/org/apache/taglibs/standard/util/XmlUtil.java b/standard/src/org/apache/taglibs/standard/util/XmlUtil.java
|
|
|
689285 |
new file mode 100644
|
|
|
689285 |
index 0000000..13ec790
|
|
|
689285 |
--- /dev/null
|
|
|
689285 |
+++ b/standard/src/org/apache/taglibs/standard/util/XmlUtil.java
|
|
|
689285 |
@@ -0,0 +1,168 @@
|
|
|
689285 |
+package org.apache.taglibs.standard.util;
|
|
|
689285 |
+
|
|
|
689285 |
+import java.security.AccessControlException;
|
|
|
689285 |
+import java.security.AccessController;
|
|
|
689285 |
+import java.security.PrivilegedAction;
|
|
|
689285 |
+
|
|
|
689285 |
+import javax.xml.XMLConstants;
|
|
|
689285 |
+import javax.xml.parsers.DocumentBuilder;
|
|
|
689285 |
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
689285 |
+import javax.xml.parsers.ParserConfigurationException;
|
|
|
689285 |
+import javax.xml.parsers.SAXParser;
|
|
|
689285 |
+import javax.xml.parsers.SAXParserFactory;
|
|
|
689285 |
+import javax.xml.transform.Source;
|
|
|
689285 |
+import javax.xml.transform.Transformer;
|
|
|
689285 |
+import javax.xml.transform.TransformerConfigurationException;
|
|
|
689285 |
+import javax.xml.transform.TransformerFactory;
|
|
|
689285 |
+import javax.xml.transform.sax.SAXTransformerFactory;
|
|
|
689285 |
+import javax.xml.transform.sax.TransformerHandler;
|
|
|
689285 |
+
|
|
|
689285 |
+import org.apache.taglibs.standard.tag.common.xml.ParseSupport.JstlEntityResolver;
|
|
|
689285 |
+import org.xml.sax.SAXException;
|
|
|
689285 |
+import org.xml.sax.SAXNotSupportedException;
|
|
|
689285 |
+import org.xml.sax.XMLReader;
|
|
|
689285 |
+
|
|
|
689285 |
+/**
|
|
|
689285 |
+ * Utilities for working with JAXP and SAX.
|
|
|
689285 |
+ */
|
|
|
689285 |
+public class XmlUtil {
|
|
|
689285 |
+
|
|
|
689285 |
+ /**
|
|
|
689285 |
+ * Create a new DocumentBuilder configured for namespaces but not validating.
|
|
|
689285 |
+ *
|
|
|
689285 |
+ * @return a new, configured DocumentBuilder
|
|
|
689285 |
+ * @throws ParserConfigurationException
|
|
|
689285 |
+ */
|
|
|
689285 |
+ public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
|
|
|
689285 |
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
|
|
689285 |
+
|
|
|
689285 |
+ dbf.setNamespaceAware(true);
|
|
|
689285 |
+ dbf.setValidating(false);
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
|
689285 |
+ } catch (ParserConfigurationException e) {
|
|
|
689285 |
+ // FSP is not supported, GCJ?
|
|
|
689285 |
+ }
|
|
|
689285 |
+ return dbf.newDocumentBuilder();
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ private static SAXTransformerFactory newTransformerFactory() throws TransformerConfigurationException {
|
|
|
689285 |
+ TransformerFactory tf = TransformerFactory.newInstance();
|
|
|
689285 |
+ if (!(tf instanceof SAXTransformerFactory)) {
|
|
|
689285 |
+ throw new TransformerConfigurationException("TransformerFactory does not support SAX");
|
|
|
689285 |
+ }
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
|
689285 |
+ } catch (TransformerConfigurationException e) {
|
|
|
689285 |
+ // FSP is not supported, GCJ?
|
|
|
689285 |
+ }
|
|
|
689285 |
+ return (SAXTransformerFactory) tf;
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ /**
|
|
|
689285 |
+ * Create a new TransformerHandler.
|
|
|
689285 |
+ * @return a new TransformerHandler
|
|
|
689285 |
+ */
|
|
|
689285 |
+ public static TransformerHandler newTransformerHandler() throws TransformerConfigurationException {
|
|
|
689285 |
+ return newTransformerFactory().newTransformerHandler();
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ /**
|
|
|
689285 |
+ * Create a new Transformer from an XSLT.
|
|
|
689285 |
+ * @param source the source of the XSLT.
|
|
|
689285 |
+ * @return a new Transformer
|
|
|
689285 |
+ * @throws TransformerConfigurationException if there was a problem creating the Transformer from the XSLT
|
|
|
689285 |
+ */
|
|
|
689285 |
+ public static Transformer newTransformer(Source source) throws TransformerConfigurationException {
|
|
|
689285 |
+ Transformer transformer = newTransformerFactory().newTransformer(source);
|
|
|
689285 |
+ // Although newTansformer() is not allowed to return null, Xalan does.
|
|
|
689285 |
+ // Trap that here by throwing the expected TransformerConfigurationException.
|
|
|
689285 |
+ if (transformer == null) {
|
|
|
689285 |
+ throw new TransformerConfigurationException("newTransformer returned null. XSLT may be invalid.");
|
|
|
689285 |
+ }
|
|
|
689285 |
+ return transformer;
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ /**
|
|
|
689285 |
+ * Create an XMLReader that resolves entities using JSTL semantics.
|
|
|
689285 |
+ * @param entityResolver for resolving using JSTL semantics
|
|
|
689285 |
+ * @return a new XMLReader
|
|
|
689285 |
+ * @throws ParserConfigurationException if there was a configuration problem creating the reader
|
|
|
689285 |
+ * @throws SAXException if there was a problem creating the reader
|
|
|
689285 |
+ */
|
|
|
689285 |
+ public static XMLReader newXMLReader(JstlEntityResolver entityResolver)
|
|
|
689285 |
+ throws ParserConfigurationException, SAXException {
|
|
|
689285 |
+
|
|
|
689285 |
+ XMLReader xmlReader = newSAXParser().getXMLReader();
|
|
|
689285 |
+ xmlReader.setEntityResolver(entityResolver);
|
|
|
689285 |
+ return xmlReader;
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ /**
|
|
|
689285 |
+ * Create a new SAXParser.
|
|
|
689285 |
+ * @return a new SAXParser
|
|
|
689285 |
+ * @throws ParserConfigurationException if there was a configuration problem creating the reader
|
|
|
689285 |
+ * @throws SAXException if there was a problem creating the reader
|
|
|
689285 |
+ */
|
|
|
689285 |
+ public static SAXParser newSAXParser() throws ParserConfigurationException, SAXException {
|
|
|
689285 |
+ SAXParserFactory spf = SAXParserFactory.newInstance();
|
|
|
689285 |
+
|
|
|
689285 |
+ spf.setNamespaceAware(true);
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
|
689285 |
+ } catch (SAXNotSupportedException e) {
|
|
|
689285 |
+ // FSP is not supported, GCJ?
|
|
|
689285 |
+ }
|
|
|
689285 |
+ return spf.newSAXParser();
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ private static final String SP_ALLOWED_PROTOCOLS = "org.apache.taglibs.standard.xml.accessExternalEntity";
|
|
|
689285 |
+ public static final String ALLOWED_PROTOCOLS = initAllowedProtocols();
|
|
|
689285 |
+
|
|
|
689285 |
+ private static String initAllowedProtocols() {
|
|
|
689285 |
+ if (System.getSecurityManager() == null) {
|
|
|
689285 |
+ return System.getProperty(SP_ALLOWED_PROTOCOLS, "all");
|
|
|
689285 |
+ } else {
|
|
|
689285 |
+ final String defaultProtocols = "";
|
|
|
689285 |
+ try {
|
|
|
689285 |
+ return (String) AccessController.doPrivileged(new PrivilegedAction() {
|
|
|
689285 |
+ public Object run() {
|
|
|
689285 |
+ return System.getProperty(SP_ALLOWED_PROTOCOLS, defaultProtocols);
|
|
|
689285 |
+ }
|
|
|
689285 |
+ });
|
|
|
689285 |
+ } catch (AccessControlException e) {
|
|
|
689285 |
+ // Fall back to the default i.e. none.
|
|
|
689285 |
+ return defaultProtocols;
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ public static void checkProtocol(String allowedProtocols, String uri) {
|
|
|
689285 |
+ if ("all".equalsIgnoreCase(allowedProtocols)) {
|
|
|
689285 |
+ return;
|
|
|
689285 |
+ }
|
|
|
689285 |
+ String protocol = getScheme(uri);
|
|
|
689285 |
+ String[] allowed = allowedProtocols.split(",");
|
|
|
689285 |
+ for (int i = 0; i < allowed.length; i++) {
|
|
|
689285 |
+ if (allowed[i].trim().equalsIgnoreCase(protocol)) {
|
|
|
689285 |
+ return;
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+ throw new AccessControlException("Access to external URI not allowed: " + uri);
|
|
|
689285 |
+ }
|
|
|
689285 |
+
|
|
|
689285 |
+ private static String getScheme(CharSequence url) {
|
|
|
689285 |
+ StringBuilder scheme = new StringBuilder();
|
|
|
689285 |
+ for (int i = 0; i < url.length(); i++) {
|
|
|
689285 |
+ char ch = url.charAt(i);
|
|
|
689285 |
+ if (ch == ':') {
|
|
|
689285 |
+ String result = scheme.toString();
|
|
|
689285 |
+ if (!"jar".equals(result)) {
|
|
|
689285 |
+ return result;
|
|
|
689285 |
+ }
|
|
|
689285 |
+ }
|
|
|
689285 |
+ scheme.append(ch);
|
|
|
689285 |
+ }
|
|
|
689285 |
+ throw new IllegalArgumentException("No scheme found: " + url);
|
|
|
689285 |
+ }
|
|
|
689285 |
+}
|