Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/App.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/App.java@0a5eff5511b1 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.datacage.templating; | |
2 | |
3 import java.util.Map; | |
4 import java.util.HashMap; | |
5 | |
6 import java.io.IOException; | |
7 import java.io.OutputStream; | |
8 import java.io.File; | |
9 import java.io.FileOutputStream; | |
10 | |
11 import org.dive4elements.river.backend.SessionFactoryProvider; | |
12 | |
13 import org.hibernate.Session; | |
14 | |
15 import org.w3c.dom.Document; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
20 | |
21 import org.dive4elements.river.artifacts.datacage.Recommendations; | |
22 | |
23 public class App | |
24 { | |
25 private static Logger log = Logger.getLogger(App.class); | |
26 | |
27 public static final String template = | |
28 System.getProperty("meta.data.template", "meta-data.xml"); | |
29 | |
30 public static final String userId = | |
31 System.getProperty("user.id"); | |
32 | |
33 public static final String PARAMETERS = | |
34 System.getProperty("meta.data.parameters", ""); | |
35 | |
36 public static final String OUTPUT = | |
37 System.getProperty("meta.data.output"); | |
38 | |
39 public static Map<String, Object> getParameters() { | |
40 HashMap<String, Object> map = new HashMap<String, Object>(); | |
41 String [] parts = PARAMETERS.split("\\s*;\\s*"); | |
42 for (String part: parts) { | |
43 String [] kv = part.split("\\s*:\\s*"); | |
44 if (kv.length < 2 || (kv[0] = kv[0].trim()).length() == 0) { | |
45 continue; | |
46 } | |
47 String [] values = kv[1].split("\\s*,\\s*"); | |
48 map.put(kv[0], values.length == 1 ? values[0] : values); | |
49 } | |
50 return map; | |
51 } | |
52 | |
53 public static void main(String [] args) { | |
54 | |
55 Recommendations rec = Recommendations.createRecommendations( | |
56 new File(template)); | |
57 | |
58 if (rec == null) { | |
59 System.err.println("No recommendations created"); | |
60 return; | |
61 } | |
62 | |
63 final Document result = XMLUtils.newDocument(); | |
64 | |
65 final Map<String, Object> parameters = getParameters(); | |
66 | |
67 Session session = SessionFactoryProvider | |
68 .createSessionFactory() | |
69 .openSession(); | |
70 | |
71 try { | |
72 rec.recommend(parameters, userId, result, session); | |
73 } | |
74 finally { | |
75 session.close(); | |
76 } | |
77 | |
78 OutputStream out; | |
79 | |
80 if (OUTPUT == null) { | |
81 out = System.out; | |
82 } | |
83 else { | |
84 try { | |
85 out = new FileOutputStream(OUTPUT); | |
86 } | |
87 catch (IOException ioe) { | |
88 log.error(ioe); | |
89 return; | |
90 } | |
91 } | |
92 | |
93 try { | |
94 XMLUtils.toStream(result, out); | |
95 } | |
96 finally { | |
97 if (OUTPUT != null) { | |
98 try { | |
99 out.close(); | |
100 } | |
101 catch (IOException ioe) { | |
102 log.error(ioe); | |
103 } | |
104 } | |
105 } | |
106 System.exit(0); | |
107 } | |
108 } | |
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |