comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java @ 8903:7de3837b204c

Minor changes to helper App so it works
author gernotbelger
date Thu, 22 Feb 2018 18:14:36 +0100
parents af13ceeba52a
children 04ad2cfce559
comparison
equal deleted inserted replaced
8902:be0220889e1f 8903:7de3837b204c
11 import java.util.Map; 11 import java.util.Map;
12 import java.util.HashMap; 12 import java.util.HashMap;
13 13
14 import java.io.IOException; 14 import java.io.IOException;
15 import java.io.OutputStream; 15 import java.io.OutputStream;
16 import java.net.MalformedURLException;
16 import java.io.File; 17 import java.io.File;
17 import java.io.FileOutputStream; 18 import java.io.FileOutputStream;
18 19
19 import org.dive4elements.river.backend.SessionFactoryProvider; 20 import org.dive4elements.river.backend.SessionFactoryProvider;
20 21
21 import org.hibernate.Session; 22 import org.hibernate.Session;
22 23 import org.slf4j.bridge.SLF4JBridgeHandler;
23 import org.w3c.dom.Document; 24 import org.w3c.dom.Document;
24 25
25 import org.apache.log4j.Logger; 26 import org.apache.log4j.Logger;
26 27 import org.apache.log4j.PropertyConfigurator;
28 import org.dive4elements.artifacts.common.utils.Config;
27 import org.dive4elements.artifacts.common.utils.XMLUtils; 29 import org.dive4elements.artifacts.common.utils.XMLUtils;
28 30
29 import org.dive4elements.river.artifacts.datacage.Recommendations; 31 import org.dive4elements.river.artifacts.datacage.Recommendations;
30 32
31 public class App 33 public class App
32 { 34 {
33 private static Logger log = Logger.getLogger(App.class); 35 private static Logger log = Logger.getLogger(App.class);
34 36
37 /**
38 * The logging is done via Log4j. To configure the logging
39 * a file 'log4j.properties' is search in the configuration directory.
40 */
41 private static final String LOG4J_PROPERTIES = "log4j.properties";
42
35 public static final String template = 43 public static final String template =
36 System.getProperty("meta.data.template", "meta-data.xml"); 44 System.getProperty("meta.data.template", "meta-data.xml");
37 45
38 public static final String userId = 46 public static final String userId =
39 System.getProperty("user.id"); 47 System.getProperty("user.id");
56 map.put(kv[0], values.length == 1 ? values[0] : values); 64 map.put(kv[0], values.length == 1 ? values[0] : values);
57 } 65 }
58 return map; 66 return map;
59 } 67 }
60 68
69 /**
70 * Trys to load the Log4j configuration from ${config.dir}/log4j.properties.
71 */
72 private static final void configureLogging() {
73 File configDir = Config.getConfigDirectory();
74 File propFile = new File(configDir, LOG4J_PROPERTIES);
75
76 if (propFile.isFile() && propFile.canRead()) {
77 try {
78 PropertyConfigurator.configure(propFile.toURI().toURL());
79 SLF4JBridgeHandler.install();
80 }
81 catch (MalformedURLException mue) {
82 mue.printStackTrace(System.err);
83 }
84 }
85 }
86
61 public static void main(String [] args) { 87 public static void main(String [] args) {
62 88
89 configureLogging();
90
63 Recommendations rec = Recommendations.createRecommendations( 91 Recommendations rec = Recommendations.createRecommendations(
64 new File(template)); 92 new File(template));
65 93
66 if (rec == null) { 94 if (rec == null) {
67 System.err.println("No recommendations created"); 95 System.err.println("No recommendations created");
69 } 97 }
70 98
71 final Document result = XMLUtils.newDocument(); 99 final Document result = XMLUtils.newDocument();
72 100
73 final Map<String, Object> parameters = getParameters(); 101 final Map<String, Object> parameters = getParameters();
102 parameters.put("ARTIFACT-OUTS", new String[] { "LONGITUDINAL_SECTION" });
103 parameters.put("PARAMETERS", parameters);
104 parameters.put("USER-ID", userId);
74 105
75 Session session = SessionFactoryProvider 106 Session session = SessionFactoryProvider
76 .createSessionFactory() 107 .createSessionFactory()
77 .openSession(); 108 .openSession();
78 109
97 return; 128 return;
98 } 129 }
99 } 130 }
100 131
101 try { 132 try {
133 out.write('\n');
102 XMLUtils.toStream(result, out); 134 XMLUtils.toStream(result, out);
135 out.write('\n');
136 }
137 catch (IOException e) {
138 log.error(e);
103 } 139 }
104 finally { 140 finally {
105 if (OUTPUT != null) { 141 if (OUTPUT != null) {
106 try { 142 try {
107 out.close(); 143 out.close();

http://dive4elements.wald.intevation.org