diff flys-aft/src/main/java/de/intevation/utils/XML.java @ 4083:44dc38ca8492

Added an optional XSL transformation to fix the raw DIPS files. flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 14:56:29 +0000
parents 88f801888d85
children da9df3641578
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/utils/XML.java	Tue Dec 20 14:36:36 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/utils/XML.java	Wed Dec 21 14:56:29 2011 +0000
@@ -26,6 +26,16 @@
 import javax.xml.xpath.XPathFactory;
 import javax.xml.xpath.XPathVariableResolver;
 
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import javax.xml.transform.stream.StreamSource;
+
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.dom.DOMResult;
+
 public final class XML
 {
     /** Logger for this class. */
@@ -217,5 +227,32 @@
 
         return null;
     }
+
+    public static Document transform(
+        Document           document,
+        File               xformFile
+    ) {
+        try {
+            Transformer transformer =
+                TransformerFactory
+                    .newInstance()
+                    .newTransformer(
+                        new StreamSource(xformFile));
+
+            DOMResult result = new DOMResult();
+
+            transformer.transform(new DOMSource(document), result);
+
+            return (Document)result.getNode();
+        }
+        catch (TransformerConfigurationException tce) {
+            log.error(tce, tce);
+        }
+        catch (TransformerException te) {
+            log.error(te, te);
+        }
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org