annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/App.java @ 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
children e91996b46e3c
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*");
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 if (kv.length < 2) {
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 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 if ((kv[0] = kv[0].trim()).length() > 0) {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 map.put(kv[0], kv[1]);
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 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return map;
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
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 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
55
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 DataCage dc = new DataCage(
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 DataCage.createBuilder(new File(template)));
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 final Document result = XMLUtils.newDocument();
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 final Builder builder = dc.getBuilder();
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 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
62
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 Session session = SessionFactoryProvider
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 .createSessionFactory()
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 .openSession();
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 try {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 session.doWork(new Work() {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 @Override
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 public void execute(Connection connection)
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 throws SQLException
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 builder.build(connection, result, parameters);
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 });
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 finally {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 session.close();
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 OutputStream out;
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 if (OUTPUT == null) {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 out = System.out;
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 else {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 try {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 out = new FileOutputStream(OUTPUT);
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 catch (IOException ioe) {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 log.error(ioe);
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 return;
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
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
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 try {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 XMLUtils.toStream(result, out);
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 finally {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 if (OUTPUT != null) {
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 out.close();
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 catch (IOException ioe) {
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 log.error(ioe);
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
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 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
9686e1132a81 Added standalone app to debug the datacage template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org