morgand 2002/10/17 11:23:48
Modified: jelly/src/java/org/apache/commons/jelly Jelly.java
jelly/src/java/org/apache/commons/jelly/parser
XMLParser.java
Log:
Added XMLParser.parse(URL), changed XMLParser.parse(File) so that
the XML parser will be able to resolve relative paths inside a DTD.
Changed Jelly.compileScript() to pass a URL to the XMLParser
instead of a stream, so that the XML parser will be able to resolve relative
paths in a DTD.
Revision Changes Path
1.23 +6 -6
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java
Index: Jelly.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Jelly.java 16 Oct 2002 22:58:19 -0000 1.22
+++ Jelly.java 17 Oct 2002 18:23:48 -0000 1.23
@@ -158,7 +158,7 @@
parser.setContext(getJellyContext());
parser.setDefaultNamespaceURI(this.defaultNamespaceURI);
parser.setValidating(this.validateXML);
- Script script = parser.parse(getUrl().openStream());
+ Script script = parser.parse(getUrl());
script = script.compile();
if (log.isDebugEnabled()) {
log.debug("Compiled script: " + getUrl());
1.35 +42 -17
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
Index: XMLParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- XMLParser.java 16 Oct 2002 16:18:42 -0000 1.34
+++ XMLParser.java 17 Oct 2002 18:23:48 -0000 1.35
@@ -62,7 +62,6 @@
package org.apache.commons.jelly.parser;
import java.io.File;
-import java.io.FileReader;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
@@ -264,9 +263,25 @@
* @exception SAXException if a parsing exception occurs
*/
public Script parse(File file) throws IOException, SAXException {
+ return parse(file.toURL());
+ }
+
+ /**
+ * Parse the content of the specified file using this XMLParser. Returns
+ * the root element from the object stack (if any).
+ *
+ * @param file URL containing the XML data to be parsed
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception SAXException if a parsing exception occurs
+ */
+ public Script parse(URL url) throws IOException, SAXException {
ensureConfigured();
- this.fileName = file.toString();
- getXMLReader().parse(new InputSource(new FileReader(file)));
+ this.fileName = url.toString();
+
+ InputSource source = new InputSource(url.toString());
+
+ getXMLReader().parse(source);
return script;
}
@@ -289,11 +304,16 @@
/**
* Parse the content of the specified input stream using this XMLParser.
* Returns the root element from the object stack (if any).
- *
- * @param input Input stream containing the XML data to be parsed
- *
- * @exception IOException if an input/output error occurs
- * @exception SAXException if a parsing exception occurs
+ * (Note: if reading a File or URL, use one of the URL-based
+ * parse methods instead. This method will not be able
+ * to resolve any relative paths inside a DTD.)
+ *
+ * @param input Input stream containing the XML data to be parsed
+ * @return
+ * @exception IOException
+ * if an input/output error occurs
+ * @exception SAXException
+ * if a parsing exception occurs
*/
public Script parse(InputStream input) throws IOException, SAXException {
ensureConfigured();
@@ -305,11 +325,16 @@
/**
* Parse the content of the specified reader using this XMLParser.
* Returns the root element from the object stack (if any).
- *
+ * (Note: if reading a File or URL, use one of the URL-based
+ * parse methods instead. This method will not be able
+ * to resolve any relative paths inside a DTD.)
+ *
* @param reader Reader containing the XML data to be parsed
- *
- * @exception IOException if an input/output error occurs
- * @exception SAXException if a parsing exception occurs
+ * @return
+ * @exception IOException
+ * if an input/output error occurs
+ * @exception SAXException
+ * if a parsing exception occurs
*/
public Script parse(Reader reader) throws IOException, SAXException {
ensureConfigured();
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>