[PATCH 2 of 5] Minor changes to helper App so it works

Wald Commits scm-commit at wald.intevation.org
Thu Feb 22 18:42:47 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1519319676 -3600
# Node ID 7de3837b204cd1f99da6bf3ee027d1321e0975ab
# Parent  be0220889e1faf3359ce191e2b8443799e182c56
Minor changes to helper App so it works

diff -r be0220889e1f -r 7de3837b204c artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java	Tue Feb 20 18:43:32 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java	Thu Feb 22 18:14:36 2018 +0100
@@ -13,17 +13,19 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.MalformedURLException;
 import java.io.File;
 import java.io.FileOutputStream;
 
 import org.dive4elements.river.backend.SessionFactoryProvider;
 
 import org.hibernate.Session;
-
+import org.slf4j.bridge.SLF4JBridgeHandler;
 import org.w3c.dom.Document;
 
 import org.apache.log4j.Logger;
-
+import org.apache.log4j.PropertyConfigurator;
+import org.dive4elements.artifacts.common.utils.Config;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 
 import org.dive4elements.river.artifacts.datacage.Recommendations;
@@ -32,6 +34,12 @@
 {
     private static Logger log = Logger.getLogger(App.class);
 
+    /**
+     * The logging is done via Log4j. To configure the logging
+     * a file 'log4j.properties' is search in the configuration directory.
+     */
+    private static final String LOG4J_PROPERTIES = "log4j.properties";
+    
     public static final String template =
         System.getProperty("meta.data.template", "meta-data.xml");
 
@@ -58,8 +66,28 @@
         return map;
     }
 
+    /**
+     * Trys to load the Log4j configuration from ${config.dir}/log4j.properties.
+     */
+    private static final void configureLogging() {
+        File configDir = Config.getConfigDirectory();
+        File propFile = new File(configDir, LOG4J_PROPERTIES);
+
+        if (propFile.isFile() && propFile.canRead()) {
+            try {
+                PropertyConfigurator.configure(propFile.toURI().toURL());
+                SLF4JBridgeHandler.install();
+            }
+            catch (MalformedURLException mue) {
+                mue.printStackTrace(System.err);
+            }
+        }
+    }
+    
     public static void main(String [] args) {
 
+        configureLogging();
+        
         Recommendations rec = Recommendations.createRecommendations(
             new File(template));
 
@@ -71,6 +99,9 @@
         final Document result = XMLUtils.newDocument();
 
         final Map<String, Object> parameters = getParameters();
+        parameters.put("ARTIFACT-OUTS", new String[] { "LONGITUDINAL_SECTION" });
+        parameters.put("PARAMETERS", parameters);
+        parameters.put("USER-ID", userId);
 
         Session session = SessionFactoryProvider
             .createSessionFactory()
@@ -99,7 +130,12 @@
         }
 
         try {
+            out.write('\n');
             XMLUtils.toStream(result, out);
+            out.write('\n');
+        }
+        catch (IOException e) {
+            log.error(e);
         }
         finally {
             if (OUTPUT != null) {


More information about the Dive4Elements-commits mailing list