[jboss-svn-commits] JBoss Common SVN: r1928 - trunk/src/main/org/jboss/util/xml
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 10 10:10:26 EDT 2006
Author: thomas.diesler at jboss.com
Date: 2006-08-10 10:10:24 -0400 (Thu, 10 Aug 2006)
New Revision: 1928
Modified:
trunk/src/main/org/jboss/util/xml/DOMUtils.java
Log:
Replace DOMUtils.parse(Reader) -> DOMUtils.pase(InputSource)
Modified: trunk/src/main/org/jboss/util/xml/DOMUtils.java
===================================================================
--- trunk/src/main/org/jboss/util/xml/DOMUtils.java 2006-08-10 13:33:20 UTC (rev 1927)
+++ trunk/src/main/org/jboss/util/xml/DOMUtils.java 2006-08-10 14:10:24 UTC (rev 1928)
@@ -25,6 +25,7 @@
import org.jboss.logging.Logger;
import org.w3c.dom.*;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
@@ -114,32 +115,22 @@
}
}
- /** Parse the given XML reader and return the root Element
+ /** Parse the given input source and return the root Element
*/
- public static Element parse(Reader xmlReader) throws IOException
+ public static Element parse(InputSource source) throws IOException
{
- return DOMUtils.parse(transformReader(xmlReader));
+ try
+ {
+ Document doc = getDocumentBuilder().parse(source);
+ Element root = doc.getDocumentElement();
+ return root;
+ }
+ catch (SAXException e)
+ {
+ throw new IOException(e.toString());
+ }
}
- /**
- * Transform a Reader to an InputStream
- * Background is that DocumentBuilder.parse() cannot take the Reader directly
- */
- private static InputStream transformReader(Reader reader) throws IOException
- {
- int capacity = 1024;
- char[] charBuffer = new char[capacity];
- StringBuffer strBuffer = new StringBuffer(capacity);
-
- int len = reader.read(charBuffer, 0, capacity);
- while (len > 0)
- {
- strBuffer.append(charBuffer, 0, len);
- len = reader.read(charBuffer, 0, capacity);
- }
- return new ByteArrayInputStream(strBuffer.toString().getBytes());
- }
-
/** Create an Element for a given name
*/
public static Element createElement(String localPart)
More information about the jboss-svn-commits
mailing list