changeset 951:9686e1132a81

Added standalone app to debug the datacage template. flys-artifacts/trunk@2368 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jul 2011 10:39:27 +0000
parents 22bc87a42a0d
children 7399401f728c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/App.java
diffstat 2 files changed, 125 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jul 20 09:56:39 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jul 20 10:39:27 2011 +0000
@@ -1,3 +1,16 @@
+2011-07-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/meta/App.java: New.
+	  Standalone app to debug the datacage template. To use in a maven environment:
+
+	  -Dmeta.data.template=PATH_TO_META_DATA-TEMPLATE.XML \
+	  -Dmeta.data.parameters=river:Mosel \
+	  -Dmeta.data.output=OUTPUT.XML \
+	  -Dflys.backend.user=DB_USER \
+	  -Dflys.backend.password=DB_PASSWORD \
+	  -Dflys.backend.url=DB_CONNECTION_URL \
+	  -Dexec.mainClass=de.intevation.flys.artifacts.services.meta.App
+
 2011-07-20  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/App.java	Wed Jul 20 10:39:27 2011 +0000
@@ -0,0 +1,112 @@
+package de.intevation.flys.artifacts.services.meta;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+
+import de.intevation.flys.backend.SessionFactoryProvider;
+
+import org.hibernate.Session;
+
+import org.hibernate.jdbc.Work;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+public class App
+{
+    private static Logger log = Logger.getLogger(App.class);
+
+    public static final String template =
+        System.getProperty("meta.data.template", "meta-data-template.xml");
+
+    public static final String PARAMETERS =
+        System.getProperty("meta.data.parameters", "");
+
+    public static final String OUTPUT =
+        System.getProperty("meta.data.output");
+
+    public static Map<String, Object> getParameters() {
+        HashMap<String, Object> map = new HashMap<String, Object>();
+        String [] parts = PARAMETERS.split("\\s*;\\s*");
+        for (String part: parts) {
+            String [] kv = part.split("\\s*:\\s*");
+            if (kv.length < 2) {
+                continue;
+            }
+            if ((kv[0] = kv[0].trim()).length() > 0) {
+                map.put(kv[0], kv[1]);
+            }
+        }
+        return map;
+    }
+
+    public static void main(String [] args) {
+
+        DataCage dc = new DataCage(
+            DataCage.createBuilder(new File(template)));
+
+        final Document result = XMLUtils.newDocument();
+        final Builder builder = dc.getBuilder();
+        final Map<String, Object> parameters = getParameters();
+
+        Session session = SessionFactoryProvider
+            .createSessionFactory()
+            .openSession();
+
+        try {
+            session.doWork(new Work() {
+                @Override
+                public void execute(Connection connection)
+                throws SQLException
+                {
+                    builder.build(connection, result, parameters);
+                }
+
+            });
+        }
+        finally {
+            session.close();
+        }
+
+        OutputStream out;
+
+        if (OUTPUT == null) {
+            out = System.out;
+        }
+        else {
+            try {
+                out = new FileOutputStream(OUTPUT);
+            }
+            catch (IOException ioe) {
+                log.error(ioe);
+                return;
+            }
+        }
+
+        try {
+            XMLUtils.toStream(result, out);
+        }
+        finally {
+            if (OUTPUT != null) {
+                try {
+                    out.close();
+                }
+                catch (IOException ioe) {
+                    log.error(ioe);
+                }
+            }
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org