X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=sidebyside;f=libjava%2Fclasspath%2Fjava%2Futil%2FProperties.java;h=eb208f5a93d5a44122b98c484031b11c25bb44dd;hb=2d8cf20d0d5ca6b1fbdefc22229d4b7cf1497ede;hp=7c468da8b4f3ee504ea5d296780dcc6b9fa7545c;hpb=a3ef37ddfeddcc5b0f1c5068d8fdeb25a302d5cd;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/classpath/java/util/Properties.java b/libjava/classpath/java/util/Properties.java index 7c468da8b4f..eb208f5a93d 100644 --- a/libjava/classpath/java/util/Properties.java +++ b/libjava/classpath/java/util/Properties.java @@ -47,15 +47,10 @@ import java.io.OutputStreamWriter; import java.io.PrintStream; import java.io.PrintWriter; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.ext.DefaultHandler2; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; @@ -743,173 +738,64 @@ label = Name:\\u0020 throw new NullPointerException("Null input stream supplied."); try { - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setValidating(false); /* Don't use the URI */ - XMLReader parser = factory.newSAXParser().getXMLReader(); - PropertiesHandler handler = new PropertiesHandler(); - parser.setContentHandler(handler); - parser.setProperty("http://xml.org/sax/properties/lexical-handler", - handler); - parser.parse(new InputSource(in)); + XMLInputFactory factory = XMLInputFactory.newInstance(); + // Don't resolve external entity references + factory.setProperty("javax.xml.stream.isSupportingExternalEntities", + Boolean.FALSE); + XMLStreamReader reader = factory.createXMLStreamReader(in); + String name, key = null; + StringBuffer buf = null; + while (reader.hasNext()) + { + switch (reader.next()) + { + case XMLStreamConstants.START_ELEMENT: + name = reader.getLocalName(); + if (buf == null && "entry".equals(name)) + { + key = reader.getAttributeValue(null, "key"); + if (key == null) + { + String msg = "missing 'key' attribute"; + throw new InvalidPropertiesFormatException(msg); + } + buf = new StringBuffer(); + } + else if (!"properties".equals(name) && !"comment".equals(name)) + { + String msg = "unexpected element name '" + name + "'"; + throw new InvalidPropertiesFormatException(msg); + } + break; + case XMLStreamConstants.END_ELEMENT: + name = reader.getLocalName(); + if (buf != null && "entry".equals(name)) + { + put(key, buf.toString()); + buf = null; + } + else if (!"properties".equals(name) && !"comment".equals(name)) + { + String msg = "unexpected element name '" + name + "'"; + throw new InvalidPropertiesFormatException(msg); + } + break; + case XMLStreamConstants.CHARACTERS: + case XMLStreamConstants.SPACE: + case XMLStreamConstants.CDATA: + if (buf != null) + buf.append(reader.getText()); + break; + } + } + reader.close(); } - catch (SAXException e) + catch (XMLStreamException e) { throw (InvalidPropertiesFormatException) new InvalidPropertiesFormatException("Error in parsing XML."). initCause(e); } - catch (ParserConfigurationException e) - { - throw (IOException) - new IOException("An XML parser could not be found."). - initCause(e); - } } - /** - * This class deals with the parsing of XML using - * - * http://java.sun.com/dtd/properties.dtd. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - * @since 1.5 - */ - private class PropertiesHandler - extends DefaultHandler2 - { - - /** - * The current key. - */ - private String key; - - /** - * The current value. - */ - private String value; - - /** - * A flag to check whether a valid DTD declaration has been seen. - */ - private boolean dtdDeclSeen; - - /** - * Constructs a new Properties handler. - */ - public PropertiesHandler() - { - key = null; - value = null; - dtdDeclSeen = false; - } - - /** - *
- * Captures the start of the DTD declarations, if they exist. - * A valid properties file must declare the following doctype: - *
- *
- * !DOCTYPE properties SYSTEM
- * "http://java.sun.com/dtd/properties.dtd"
- *