[Schmitzm-commits] r2424 - trunk/schmitzm-core/src/main/java/de/schmitzm/xml

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 17 13:17:16 CET 2016


Author: mojays
Date: 2016-11-17 13:17:16 +0100 (Thu, 17 Nov 2016)
New Revision: 2424

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java
Log:
XMLUtil: new utility method buildSaxDocumentUTF8(.)

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java	2016-07-14 18:50:48 UTC (rev 2423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java	2016-11-17 12:17:16 UTC (rev 2424)
@@ -31,6 +31,11 @@
 
 import java.awt.Color;
 import java.awt.Font;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -41,11 +46,14 @@
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
+import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
 import org.jdom.adapters.JAXPDOMAdapter;
 import org.jdom.input.SAXBuilder;
 import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
+import org.xml.sax.InputSource;
 
 import de.schmitzm.i18n.Translation;
 import de.schmitzm.lang.LangUtil;
@@ -71,7 +79,21 @@
   /** A builder to read an XML file. */
   public static final SAXBuilder SAX_BUILDER = new SAXBuilder();
   
+  /**
+   * Builds an XML document from given URL using UTF-8 for input stream.
+   * @param url Document URL
+   */
+  public static Document buildSaxDocumentUTF8(URL url) throws IOException, JDOMException {
+    InputStream inputStream= url.openStream();
+    Reader reader = new InputStreamReader(inputStream,"UTF-8");
+    InputSource is = new InputSource(reader);
+    is.setEncoding("UTF-8");
+    Document d = XMLUtil.SAX_BUILDER.build(is);
+    
+    return d;
+  }
   
+  
   /**
    * Returns the content of i-th sub-child of an element or {@code null} if the
    * path can not be tracked because a child does not exist.



More information about the Schmitzm-commits mailing list