comparison 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
comparison
equal deleted inserted replaced
950:22bc87a42a0d 951:9686e1132a81
1 package de.intevation.flys.artifacts.services.meta;
2
3 import java.sql.Connection;
4 import java.sql.SQLException;
5
6 import java.util.Map;
7 import java.util.HashMap;
8
9 import java.io.IOException;
10 import java.io.OutputStream;
11 import java.io.File;
12 import java.io.FileOutputStream;
13
14 import de.intevation.flys.backend.SessionFactoryProvider;
15
16 import org.hibernate.Session;
17
18 import org.hibernate.jdbc.Work;
19
20 import org.w3c.dom.Document;
21
22 import org.apache.log4j.Logger;
23
24 import de.intevation.artifacts.common.utils.XMLUtils;
25
26 public class App
27 {
28 private static Logger log = Logger.getLogger(App.class);
29
30 public static final String template =
31 System.getProperty("meta.data.template", "meta-data-template.xml");
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) {
45 continue;
46 }
47 if ((kv[0] = kv[0].trim()).length() > 0) {
48 map.put(kv[0], kv[1]);
49 }
50 }
51 return map;
52 }
53
54 public static void main(String [] args) {
55
56 DataCage dc = new DataCage(
57 DataCage.createBuilder(new File(template)));
58
59 final Document result = XMLUtils.newDocument();
60 final Builder builder = dc.getBuilder();
61 final Map<String, Object> parameters = getParameters();
62
63 Session session = SessionFactoryProvider
64 .createSessionFactory()
65 .openSession();
66
67 try {
68 session.doWork(new Work() {
69 @Override
70 public void execute(Connection connection)
71 throws SQLException
72 {
73 builder.build(connection, result, parameters);
74 }
75
76 });
77 }
78 finally {
79 session.close();
80 }
81
82 OutputStream out;
83
84 if (OUTPUT == null) {
85 out = System.out;
86 }
87 else {
88 try {
89 out = new FileOutputStream(OUTPUT);
90 }
91 catch (IOException ioe) {
92 log.error(ioe);
93 return;
94 }
95 }
96
97 try {
98 XMLUtils.toStream(result, out);
99 }
100 finally {
101 if (OUTPUT != null) {
102 try {
103 out.close();
104 }
105 catch (IOException ioe) {
106 log.error(ioe);
107 }
108 }
109 }
110 }
111 }
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org