Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/App.java @ 965:79251b1d47da
Modified the CollectionMonitor to recommend artifacts for the current state's outputs only.
flys-artifacts/trunk@2385 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Jul 2011 14:00:09 +0000 |
parents | a2b20ed3d3b4 |
children | 0c8aca463bd4 |
rev | line source |
---|---|
951
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services.meta; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.sql.Connection; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.sql.SQLException; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.util.Map; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.HashMap; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.io.IOException; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.io.OutputStream; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.File; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.io.FileOutputStream; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.backend.SessionFactoryProvider; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.hibernate.Session; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import org.hibernate.jdbc.Work; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.w3c.dom.Document; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.apache.log4j.Logger; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.artifacts.common.utils.XMLUtils; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public class App |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 private static Logger log = Logger.getLogger(App.class); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public static final String template = |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 System.getProperty("meta.data.template", "meta-data-template.xml"); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public static final String PARAMETERS = |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 System.getProperty("meta.data.parameters", ""); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public static final String OUTPUT = |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 System.getProperty("meta.data.output"); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public static Map<String, Object> getParameters() { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 HashMap<String, Object> map = new HashMap<String, Object>(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 String [] parts = PARAMETERS.split("\\s*;\\s*"); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 for (String part: parts) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 String [] kv = part.split("\\s*:\\s*"); |
959
a2b20ed3d3b4
Datacage: Added custom provider for XPath functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
957
diff
changeset
|
44 if (kv.length < 2 || (kv[0] = kv[0].trim()).length() == 0) { |
951
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 continue; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
959
a2b20ed3d3b4
Datacage: Added custom provider for XPath functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
957
diff
changeset
|
47 String [] values = kv[1].split("\\s*,\\s*"); |
a2b20ed3d3b4
Datacage: Added custom provider for XPath functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
957
diff
changeset
|
48 map.put(kv[0], values.length == 1 ? values[0] : values); |
951
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 return map; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public static void main(String [] args) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 DataCage dc = new DataCage( |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 DataCage.createBuilder(new File(template))); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 final Document result = XMLUtils.newDocument(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 final Builder builder = dc.getBuilder(); |
957
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
60 |
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
61 if (builder == null) { |
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
62 System.err.println("No builder created"); |
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
63 return; |
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
64 } |
e91996b46e3c
Meta data template: Added new choose/when/otherwise construct similiar to XSLT
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
65 |
951
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 final Map<String, Object> parameters = getParameters(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 Session session = SessionFactoryProvider |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 .createSessionFactory() |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 .openSession(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 try { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 session.doWork(new Work() { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 @Override |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 public void execute(Connection connection) |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 throws SQLException |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 builder.build(connection, result, parameters); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 }); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 finally { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 session.close(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 OutputStream out; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 if (OUTPUT == null) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 out = System.out; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 else { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 try { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 out = new FileOutputStream(OUTPUT); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 catch (IOException ioe) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 log.error(ioe); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 return; |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 try { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 XMLUtils.toStream(result, out); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 finally { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 if (OUTPUT != null) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 try { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 out.close(); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 catch (IOException ioe) { |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 log.error(ioe); |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
9686e1132a81
Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |