You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/11/30 21:21:00 UTC
svn commit: r1040756 -
/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
Author: mgrigorov
Date: Tue Nov 30 20:20:59 2010
New Revision: 1040756
URL: http://svn.apache.org/viewvc?rev=1040756&view=rev
Log:
Use JDK 1.5 Properties#loadFromXML() and remove the code used to support this in Wicket 1.3
Modified:
wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
Modified: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java?rev=1040756&r1=1040755&r2=1040756&view=diff
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java (original)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java Tue Nov 30 20:20:59 2010
@@ -23,23 +23,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
-import java.io.StringReader;
import java.util.Properties;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
/**
* Utilities methods for working with input and output streams.
*
@@ -56,7 +41,7 @@ public final class Streams
/**
* @deprecated
- *
+ *
* @see IOUtils#close(Closeable);
*/
@Deprecated
@@ -138,76 +123,7 @@ public final class Streams
throw new IllegalArgumentException("inputStream must not be null");
}
- // TODO in a Wicket version that supports Java 5 (Wicket 2.0?), we can
- // just use the loadFromXml method on java.util.Properties directly
- // rather than manual as we do here
-
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- documentBuilderFactory.setIgnoringElementContentWhitespace(true);
- documentBuilderFactory.setValidating(true);
- documentBuilderFactory.setCoalescing(true);
- documentBuilderFactory.setIgnoringComments(true);
- try
- {
- DocumentBuilder db = documentBuilderFactory.newDocumentBuilder();
- db.setEntityResolver(new EntityResolver()
- {
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException
- {
- if (systemId.equals("http://java.sun.com/dtd/properties.dtd"))
- {
- InputSource inputSource;
- inputSource = new InputSource(new StringReader(XML_PROPERTIES_DTD));
- inputSource.setSystemId("http://java.sun.com/dtd/properties.dtd");
- return inputSource;
- }
- else
- {
- throw new SAXException("Invalid system identifier: " + systemId);
- }
- }
- });
- db.setErrorHandler(new ErrorHandler()
- {
- public void error(SAXParseException e) throws SAXException
- {
- throw e;
- }
-
- public void fatalError(SAXParseException e) throws SAXException
- {
- throw e;
- }
-
- public void warning(SAXParseException e) throws SAXException
- {
- throw e;
- }
- });
- InputSource is = new InputSource(inputStream);
- Document doc = db.parse(is);
- NodeList entries = doc.getChildNodes().item(1).getChildNodes();
- int len = entries.getLength();
- for (int i = (len > 0 && entries.item(0).getNodeName().equals("comment")) ? 1 : 0; i < len; i++)
- {
- Element entry = (Element)entries.item(i);
- if (entry.hasAttribute("key"))
- {
- Node node = entry.getFirstChild();
- String val = (node == null) ? "" : node.getNodeValue();
- properties.setProperty(entry.getAttribute("key"), val);
- }
- }
- }
- catch (ParserConfigurationException e)
- {
- throw new RuntimeException(e);
- }
- catch (SAXException e)
- {
- throw new RuntimeException("invalid XML properties format", e);
- }
+ properties.loadFromXML(inputStream);
}
/**