aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorChris Burdess <dog@gnu.org>2007-02-07 18:22:26 +0000
committerTom Tromey <tromey@gcc.gnu.org>2007-02-07 18:22:26 +0000
commit08452f45531ca2ec479e61b9f7e37d3fadd95a7b (patch)
tree6dc3be85930294202aea5c41b9800414ba213f20 /libjava
parent74372bdfc63ac2ba2eaf540f0993b457dca69144 (diff)
downloadgcc-08452f45531ca2ec479e61b9f7e37d3fadd95a7b.zip
gcc-08452f45531ca2ec479e61b9f7e37d3fadd95a7b.tar.gz
gcc-08452f45531ca2ec479e61b9f7e37d3fadd95a7b.tar.bz2
re PR classpath/30718 (TransformerException in XSLURIResolver)
2007-02-07 Chris Burdess <dog@gnu.org> Fixes PR 30718. * gnu/xml/dom/ls/SAXEventSink.java: Add public accessor/mutators. * gnu/xml/transform/XSLURIResolver.java: Add support for custom SAXSources without a backing URL or stream. Fixes PR 27710. * gnu/xml/dom/DomDocumentBuilderFactory.java: Fall back to synchronous LSParser if implementation does not support asynchronous. * gnu/xml/stream/XMLParser.java, gnu/xml/stream/XIncludeFilter.java: Use custom code instead of java.net.URL to resolve to an an absolute URI, to avoid nonexistent protocol handler problems. From-SVN: r121694
Diffstat (limited to 'libjava')
-rw-r--r--libjava/classpath/ChangeLog15
-rw-r--r--libjava/classpath/gnu/xml/dom/DomDocumentBuilderFactory.java35
-rw-r--r--libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java7
-rw-r--r--libjava/classpath/gnu/xml/stream/XIncludeFilter.java13
-rw-r--r--libjava/classpath/gnu/xml/stream/XMLParser.java56
-rw-r--r--libjava/classpath/gnu/xml/transform/XSLURIResolver.java42
-rw-r--r--libjava/classpath/lib/gnu/xml/dom/DomDocumentBuilderFactory.classbin3710 -> 4109 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/dom/ls/SAXEventSink.classbin12805 -> 12922 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XIncludeFilter.classbin17712 -> 17452 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$AnyContentModel.classbin594 -> 594 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$Attribute.classbin1789 -> 1789 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$AttributeDecl.classbin897 -> 897 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentModel.classbin787 -> 787 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentParticle.classbin595 -> 595 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$Doctype.classbin5857 -> 5857 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$ElementContentModel.classbin964 -> 964 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$EmptyContentModel.classbin600 -> 600 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$ExternalIds.classbin556 -> 556 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$Input.classbin6256 -> 6256 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser$MixedContentModel.classbin965 -> 965 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/stream/XMLParser.classbin67379 -> 67815 bytes
-rw-r--r--libjava/classpath/lib/gnu/xml/transform/XSLURIResolver.classbin6144 -> 7205 bytes
-rw-r--r--libjava/gnu/xml/dom/ls/SAXEventSink.h4
-rw-r--r--libjava/gnu/xml/transform/XSLURIResolver.h12
24 files changed, 155 insertions, 29 deletions
diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog
index efc1512..a9a3449 100644
--- a/libjava/classpath/ChangeLog
+++ b/libjava/classpath/ChangeLog
@@ -1,3 +1,18 @@
+2007-02-07 Chris Burdess <dog@gnu.org>
+
+ Fixes PR 30718.
+ * gnu/xml/dom/ls/SAXEventSink.java: Add public accessor/mutators.
+ * gnu/xml/transform/XSLURIResolver.java: Add support for custom
+ SAXSources without a backing URL or stream.
+
+ Fixes PR 27710.
+ * gnu/xml/dom/DomDocumentBuilderFactory.java: Fall back to synchronous
+ LSParser if implementation does not support asynchronous.
+ * gnu/xml/stream/XMLParser.java,
+ gnu/xml/stream/XIncludeFilter.java: Use custom code instead of
+ java.net.URL to resolve to an an absolute URI, to avoid nonexistent
+ protocol handler problems.
+
2007-02-06 Tom Tromey <tromey@redhat.com>
PR libgcj/30707:
diff --git a/libjava/classpath/gnu/xml/dom/DomDocumentBuilderFactory.java b/libjava/classpath/gnu/xml/dom/DomDocumentBuilderFactory.java
index 0234785..4d2828a 100644
--- a/libjava/classpath/gnu/xml/dom/DomDocumentBuilderFactory.java
+++ b/libjava/classpath/gnu/xml/dom/DomDocumentBuilderFactory.java
@@ -43,6 +43,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
@@ -84,8 +85,38 @@ public class DomDocumentBuilderFactory
public DocumentBuilder newDocumentBuilder()
throws ParserConfigurationException
{
- LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
- "http://www.w3.org/TR/REC-xml");
+ LSParser parser = null;
+ try
+ {
+ parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
+ "http://www.w3.org/TR/REC-xml");
+ }
+ catch (DOMException e)
+ {
+ if (e.code == DOMException.NOT_SUPPORTED_ERR)
+ {
+ // Fall back to synchronous parser
+ try
+ {
+ parser = ls.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
+ "http://www.w3.org/TR/REC-xml");
+ }
+ catch (DOMException e2)
+ {
+ ParserConfigurationException pce =
+ new ParserConfigurationException();
+ pce.initCause(e2);
+ throw pce;
+ }
+ }
+ else
+ {
+ ParserConfigurationException pce =
+ new ParserConfigurationException();
+ pce.initCause(e);
+ throw pce;
+ }
+ }
DOMConfiguration config = parser.getDomConfig();
setParameter(config, "namespaces",
isNamespaceAware() ? Boolean.TRUE : Boolean.FALSE);
diff --git a/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java b/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
index 8c5b104..2855400 100644
--- a/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
+++ b/libjava/classpath/gnu/xml/dom/ls/SAXEventSink.java
@@ -111,11 +111,16 @@ public class SAXEventSink
interrupted = true;
}
- protected Document getDocument()
+ public Document getDocument()
{
return doc;
}
+ public void setReader(XMLReader reader)
+ {
+ this.reader = reader;
+ }
+
// -- ContentHandler2 --
public void setDocumentLocator(Locator locator)
diff --git a/libjava/classpath/gnu/xml/stream/XIncludeFilter.java b/libjava/classpath/gnu/xml/stream/XIncludeFilter.java
index 7e70782..86961fa 100644
--- a/libjava/classpath/gnu/xml/stream/XIncludeFilter.java
+++ b/libjava/classpath/gnu/xml/stream/XIncludeFilter.java
@@ -42,7 +42,6 @@ import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashSet;
@@ -122,17 +121,7 @@ class XIncludeFilter
boolean expandERefs)
{
super(reader);
- try
- {
- this.systemId = XMLParser.absolutize(null, systemId);
- }
- catch (MalformedURLException e)
- {
- RuntimeException e2 = new RuntimeException("unsupported URL: " +
- systemId);
- e2.initCause(e);
- throw e2;
- }
+ this.systemId = XMLParser.absolutize(null, systemId);
this.namespaceAware = namespaceAware;
this.validating = validating;
this.expandERefs = expandERefs;
diff --git a/libjava/classpath/gnu/xml/stream/XMLParser.java b/libjava/classpath/gnu/xml/stream/XMLParser.java
index ef37799..663a300 100644
--- a/libjava/classpath/gnu/xml/stream/XMLParser.java
+++ b/libjava/classpath/gnu/xml/stream/XMLParser.java
@@ -1592,7 +1592,6 @@ public class XMLParser
* @param href the (absolute or relative) URL to resolve
*/
public static String absolutize(String base, String href)
- throws MalformedURLException
{
if (href == null)
return null;
@@ -1622,7 +1621,60 @@ public class XMLParser
if (!base.endsWith("/"))
base += "/";
}
- return new URL(new URL(base), href).toString();
+ // We can't use java.net.URL here to do the parsing, as it searches for
+ // a protocol handler. A protocol handler may not be registered for the
+ // URL scheme here. Do it manually.
+ //
+ // Set aside scheme and host portion of base URL
+ String basePrefix = null;
+ ci = base.indexOf(':');
+ if (ci > 1 && isURLScheme(base.substring(0, ci)))
+ {
+ if (base.length() > (ci + 3) &&
+ base.charAt(ci + 1) == '/' &&
+ base.charAt(ci + 2) == '/')
+ {
+ int si = base.indexOf('/', ci + 3);
+ if (si == -1)
+ base = null;
+ else
+ {
+ basePrefix = base.substring(0, si);
+ base = base.substring(si);
+ }
+ }
+ else
+ base = null;
+ }
+ if (base == null) // unknown or malformed base URL, use href
+ return href;
+ if (href.startsWith("/")) // absolute href pathname
+ return (basePrefix == null) ? href : basePrefix + href;
+ // relative href pathname
+ if (!base.endsWith("/"))
+ {
+ int lsi = base.lastIndexOf('/');
+ if (lsi == -1)
+ base = "/";
+ else
+ base = base.substring(0, lsi + 1);
+ }
+ while (href.startsWith("../") || href.startsWith("./"))
+ {
+ if (href.startsWith("../"))
+ {
+ // strip last path component from base
+ int lsi = base.lastIndexOf('/', base.length() - 2);
+ if (lsi > -1)
+ base = base.substring(0, lsi + 1);
+ href = href.substring(3); // strip ../ prefix
+ }
+ else
+ {
+ href = href.substring(2); // strip ./ prefix
+ }
+ }
+ return (basePrefix == null) ? base + href : basePrefix + base + href;
}
/**
diff --git a/libjava/classpath/gnu/xml/transform/XSLURIResolver.java b/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
index 8d7e3fc..8bb8977 100644
--- a/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
+++ b/libjava/classpath/gnu/xml/transform/XSLURIResolver.java
@@ -55,9 +55,13 @@ import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
+import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import gnu.xml.dom.DomDocument;
+import gnu.xml.dom.ls.SAXEventSink;
import gnu.xml.dom.ls.ReaderInputStream;
/**
@@ -137,17 +141,14 @@ class XSLURIResolver
else if (source != null && source instanceof SAXSource)
{
SAXSource ss = (SAXSource) source;
- if (ss.getInputSource() != null)
+ InputSource input = ss.getInputSource();
+ if (input != null)
{
- in = ss.getInputSource().getByteStream();
- if (in == null)
- {
- Reader reader = ss.getInputSource().getCharacterStream();
- if (reader != null)
- {
- in = new ReaderInputStream(reader);
- }
- }
+ if (systemId == null)
+ systemId = input.getSystemId();
+ XMLReader reader = ss.getXMLReader();
+ if (reader != null)
+ return parse(input, reader);
}
}
if (in == null)
@@ -294,6 +295,27 @@ class XSLURIResolver
throw new TransformerException(e);
}
}
+
+ DOMSource parse(InputSource source, XMLReader reader)
+ throws SAXException, IOException
+ {
+ SAXEventSink eventSink = new SAXEventSink();
+ eventSink.setReader(reader);
+ reader.setContentHandler(eventSink);
+ reader.setDTDHandler(eventSink);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler",
+ eventSink);
+ reader.setProperty("http://xml.org/sax/properties/declaration-handler",
+ eventSink);
+ // XXX entityResolver
+ // XXX errorHandler
+ reader.parse(source);
+ Document doc = eventSink.getDocument();
+ String systemId = source.getSystemId();
+ if (systemId != null && doc instanceof DomDocument)
+ ((DomDocument) doc).setDocumentURI(systemId);
+ return new DOMSource(doc, systemId);
+ }
}
diff --git a/libjava/classpath/lib/gnu/xml/dom/DomDocumentBuilderFactory.class b/libjava/classpath/lib/gnu/xml/dom/DomDocumentBuilderFactory.class
index 4e082d1..69733b6 100644
--- a/libjava/classpath/lib/gnu/xml/dom/DomDocumentBuilderFactory.class
+++ b/libjava/classpath/lib/gnu/xml/dom/DomDocumentBuilderFactory.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/dom/ls/SAXEventSink.class b/libjava/classpath/lib/gnu/xml/dom/ls/SAXEventSink.class
index f5f281e..d0caa3b 100644
--- a/libjava/classpath/lib/gnu/xml/dom/ls/SAXEventSink.class
+++ b/libjava/classpath/lib/gnu/xml/dom/ls/SAXEventSink.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XIncludeFilter.class b/libjava/classpath/lib/gnu/xml/stream/XIncludeFilter.class
index f659aa6..afd44e4 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XIncludeFilter.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XIncludeFilter.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$AnyContentModel.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$AnyContentModel.class
index df7b43b..9be3b14 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$AnyContentModel.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$AnyContentModel.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Attribute.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Attribute.class
index b3457c5..a529f6d 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Attribute.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Attribute.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$AttributeDecl.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$AttributeDecl.class
index 8ca9de3..86380a6 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$AttributeDecl.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$AttributeDecl.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentModel.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentModel.class
index 95921cf..c8e3969 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentModel.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentModel.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentParticle.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentParticle.class
index d6189eb..5341444 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentParticle.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ContentParticle.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Doctype.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Doctype.class
index 405545d..e935c74 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Doctype.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Doctype.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ElementContentModel.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ElementContentModel.class
index 30d2626..71e6334 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ElementContentModel.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ElementContentModel.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$EmptyContentModel.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$EmptyContentModel.class
index fcfaca7..e74252e 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$EmptyContentModel.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$EmptyContentModel.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ExternalIds.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ExternalIds.class
index e1a134f..8a6def1 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$ExternalIds.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$ExternalIds.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Input.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Input.class
index ddd6c4c..74a7e79 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$Input.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$Input.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser$MixedContentModel.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser$MixedContentModel.class
index 63bc30f..eded8c5 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser$MixedContentModel.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser$MixedContentModel.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/stream/XMLParser.class b/libjava/classpath/lib/gnu/xml/stream/XMLParser.class
index 54792a1..f125098 100644
--- a/libjava/classpath/lib/gnu/xml/stream/XMLParser.class
+++ b/libjava/classpath/lib/gnu/xml/stream/XMLParser.class
Binary files differ
diff --git a/libjava/classpath/lib/gnu/xml/transform/XSLURIResolver.class b/libjava/classpath/lib/gnu/xml/transform/XSLURIResolver.class
index 5fc53be..064742c 100644
--- a/libjava/classpath/lib/gnu/xml/transform/XSLURIResolver.class
+++ b/libjava/classpath/lib/gnu/xml/transform/XSLURIResolver.class
Binary files differ
diff --git a/libjava/gnu/xml/dom/ls/SAXEventSink.h b/libjava/gnu/xml/dom/ls/SAXEventSink.h
index ec35c66..54f4e5f 100644
--- a/libjava/gnu/xml/dom/ls/SAXEventSink.h
+++ b/libjava/gnu/xml/dom/ls/SAXEventSink.h
@@ -57,9 +57,9 @@ public:
SAXEventSink();
public: // actually package-private
virtual void interrupt();
-public: // actually protected
- virtual ::org::w3c::dom::Document * getDocument();
public:
+ virtual ::org::w3c::dom::Document * getDocument();
+ virtual void setReader(::org::xml::sax::XMLReader *);
virtual void setDocumentLocator(::org::xml::sax::Locator *);
virtual void startDocument();
virtual void endDocument();
diff --git a/libjava/gnu/xml/transform/XSLURIResolver.h b/libjava/gnu/xml/transform/XSLURIResolver.h
index a7e0aea..394c4c7 100644
--- a/libjava/gnu/xml/transform/XSLURIResolver.h
+++ b/libjava/gnu/xml/transform/XSLURIResolver.h
@@ -46,6 +46,17 @@ extern "Java"
}
}
}
+ namespace org
+ {
+ namespace xml
+ {
+ namespace sax
+ {
+ class InputSource;
+ class XMLReader;
+ }
+ }
+ }
}
class gnu::xml::transform::XSLURIResolver : public ::java::lang::Object
@@ -62,6 +73,7 @@ public: // actually package-private
virtual ::javax::xml::transform::dom::DOMSource * resolveDOM(::javax::xml::transform::Source *, ::java::lang::String *, ::java::lang::String *);
virtual ::java::net::URL * resolveURL(::java::lang::String *, ::java::lang::String *, ::java::lang::String *);
virtual ::javax::xml::parsers::DocumentBuilder * getDocumentBuilder();
+ virtual ::javax::xml::transform::dom::DOMSource * parse(::org::xml::sax::InputSource *, ::org::xml::sax::XMLReader *);
::java::util::Map * __attribute__((aligned(__alignof__( ::java::lang::Object)))) lastModifiedCache;
::java::util::Map * nodeCache;
::javax::xml::parsers::DocumentBuilder * builder;