From 51043a0701953cd3469dabeec7757c0251b3f24d Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 8 Dec 2006 10:31:49 +0000 Subject: 2006-12-06 Ben Konrath Fixes PR 29853. * gnu/xml/dom/DomAttr.java: Don't report mutation if oldValue and newValue are the same. * gnu/xml/dom/DomNode.java: Set parent if null during mutation. 2006-12-06 Chris Burdess Fixes PR 29272. * javax/xml/parsers/DocumentBuilderFactory.java: Fix broken Javadoc. * gnu/xml/stream/SAXParser.java: Fix file descriptor leak. 2006-12-06 Chris Burdess Fixes PR 29264. * gnu/xml/stream/XMLStreamWriterImpl.java: Allow arbitrary text in writeDTD method. 2006-12-056 Chris Burdess Fixes PR 28816. * javax/xml/validation/SchemaFactory.java: Use correct algorithm to discover schema factory implementation class. --- ChangeLog | 25 +++++++ gnu/xml/dom/DomAttr.java | 2 +- gnu/xml/dom/DomNode.java | 2 +- gnu/xml/stream/SAXParser.java | 15 +++- gnu/xml/stream/XMLStreamWriterImpl.java | 6 +- javax/xml/parsers/DocumentBuilderFactory.java | 2 +- javax/xml/validation/SchemaFactory.java | 101 ++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e932117e7..db3fe40bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2006-12-06 Ben Konrath + + Fixes PR 29853. + * gnu/xml/dom/DomAttr.java: Don't report mutation if oldValue and + newValue are the same. + * gnu/xml/dom/DomNode.java: Set parent if null during mutation. + +2006-12-06 Chris Burdess + + Fixes PR 29272. + * javax/xml/parsers/DocumentBuilderFactory.java: Fix broken Javadoc. + * gnu/xml/stream/SAXParser.java: Fix file descriptor leak. + +2006-12-06 Chris Burdess + + Fixes PR 29264. + * gnu/xml/stream/XMLStreamWriterImpl.java: Allow arbitrary text in + writeDTD method. + +2006-12-056 Chris Burdess + + Fixes PR 28816. + * javax/xml/validation/SchemaFactory.java: Use correct algorithm to + discover schema factory implementation class. + 2006-12-05 Roman Kennke (paintComponent): Include paint area from event. diff --git a/gnu/xml/dom/DomAttr.java b/gnu/xml/dom/DomAttr.java index 8673a7961..31d7af2d2 100644 --- a/gnu/xml/dom/DomAttr.java +++ b/gnu/xml/dom/DomAttr.java @@ -316,7 +316,7 @@ public class DomAttr private void mutating(String oldValue, String newValue, short why) { - if (!reportMutations || parent == null) + if (!reportMutations || parent == null || equal(newValue, oldValue)) { return; } diff --git a/gnu/xml/dom/DomNode.java b/gnu/xml/dom/DomNode.java index 269038aa7..9af3f3e54 100644 --- a/gnu/xml/dom/DomNode.java +++ b/gnu/xml/dom/DomNode.java @@ -1562,7 +1562,7 @@ public abstract class DomNode // Climb to the top of this subtree and handle capture, letting // each node (from the top down) capture until one stops it or // until we get to this one. - current = parent; + current = (parent == null) ? this : parent; if (current.depth >= ANCESTORS_INIT) { DomNode[] newants = new DomNode[current.depth + 1]; diff --git a/gnu/xml/stream/SAXParser.java b/gnu/xml/stream/SAXParser.java index e58d5fb52..1329ab297 100644 --- a/gnu/xml/stream/SAXParser.java +++ b/gnu/xml/stream/SAXParser.java @@ -1021,9 +1021,18 @@ public class SAXParser SAXParser parser = new SAXParser(validating, namespaceAware, xIncludeAware); InputSource input = new InputSource(args[pos]); - XMLReader reader = parser.getXMLReader(); - reader.setContentHandler(handler); - reader.parse(input); + java.io.FileReader fr = new java.io.FileReader(args[pos]); + input.setCharacterStream(fr); + try + { + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(handler); + reader.parse(input); + } + finally + { + fr.close(); + } pos++; } } diff --git a/gnu/xml/stream/XMLStreamWriterImpl.java b/gnu/xml/stream/XMLStreamWriterImpl.java index 291016e67..4be9992a7 100644 --- a/gnu/xml/stream/XMLStreamWriterImpl.java +++ b/gnu/xml/stream/XMLStreamWriterImpl.java @@ -664,12 +664,10 @@ public class XMLStreamWriterImpl public void writeDTD(String dtd) throws XMLStreamException { - // Really thoroughly pointless method... try { - if (!isName(dtd)) - throw new IllegalArgumentException("illegal Name: " + dtd); - + // XXX: Should we parse the doctypedecl at this point to ensure + // wellformedness? writer.write("'); diff --git a/javax/xml/parsers/DocumentBuilderFactory.java b/javax/xml/parsers/DocumentBuilderFactory.java index 0dc574e65..9312e65e0 100644 --- a/javax/xml/parsers/DocumentBuilderFactory.java +++ b/javax/xml/parsers/DocumentBuilderFactory.java @@ -50,7 +50,7 @@ import javax.xml.validation.Schema; * Factory for obtaining document builders. * Instances of this class are not guaranteed to be thread safe. * - * @author (a href='mailto:dog@gnu.org'>Chris BurdessChris Burdess */ public abstract class DocumentBuilderFactory { diff --git a/javax/xml/validation/SchemaFactory.java b/javax/xml/validation/SchemaFactory.java index 0042ea323..0c2410444 100644 --- a/javax/xml/validation/SchemaFactory.java +++ b/javax/xml/validation/SchemaFactory.java @@ -37,8 +37,14 @@ exception statement from your version. */ package javax.xml.validation; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; import java.net.URL; +import java.util.Properties; import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; @@ -68,6 +74,71 @@ public abstract class SchemaFactory */ public static final SchemaFactory newInstance(String schemaLanguage) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) + { + loader = SchemaFactory.class.getClassLoader(); + } + final String factoryClassName = "javax.xml.validation.SchemaFactory"; + String className = null; + int count = 0; + do + { + className = getFactoryClassName(loader, schemaLanguage, count++); + if (className != null) + { + try + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + return (SchemaFactory) t.newInstance(); + } + catch (Exception e) + { + // Ignore any errors and continue algorithm. + // This method doesn't have a means of propagating + // class instantiation errors. + className = null; + } + } + } + while (className == null && count < 2); + try + { + String serviceKey = "/META-INF/services/" + factoryClassName; + InputStream in = (loader != null) ? + loader.getResourceAsStream(serviceKey) : + SchemaFactory.class.getResourceAsStream(serviceKey); + if (in != null) + { + BufferedReader r = + new BufferedReader(new InputStreamReader(in)); + try + { + for (String line = r.readLine(); line != null; + line = r.readLine()) + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + SchemaFactory ret = (SchemaFactory) t.newInstance(); + if (ret.isSchemaLanguageSupported(schemaLanguage)) + return ret; + } + } + catch (Exception e) + { + // Fall through. See above. + } + finally + { + r.close(); + } + } + } + catch (IOException e) + { + } + // Default schema factories for Classpath if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schemaLanguage)) return new gnu.xml.validation.xmlschema.XMLSchemaSchemaFactory(); if (XMLConstants.RELAXNG_NS_URI.equals(schemaLanguage)) @@ -75,6 +146,36 @@ public abstract class SchemaFactory throw new IllegalArgumentException(schemaLanguage); } + private static String getFactoryClassName(ClassLoader loader, + String schemaLanguage, int attempt) + { + final String factoryClassName = "javax.xml.validation.SchemaFactory"; + final String propertyName = factoryClassName + ":" + schemaLanguage; + switch (attempt) + { + case 0: + return System.getProperty(propertyName); + case 1: + try + { + File file = new File(System.getProperty("java.home")); + file = new File(file, "lib"); + file = new File(file, "jaxp.properties"); + InputStream in = new FileInputStream(file); + Properties props = new Properties(); + props.load(in); + in.close(); + return props.getProperty(propertyName); + } + catch (IOException e) + { + return null; + } + default: + return null; + } + } + /** * Indicates whether the specified schema language is supported. * @param schemaLanguage the URI of a schema language (see -- cgit v1.2.1