comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 415:7c018f466d6d

Datacage: Added river parameter to meta data services. flys-artifacts/trunk@1879 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 10 May 2011 12:43:12 +0000
parents df02137b3b28
children c09c9e05ecfa
comparison
equal deleted inserted replaced
414:0385bcc4229a 415:7c018f466d6d
24 private static Logger log = Logger.getLogger(Builder.class); 24 private static Logger log = Logger.getLogger(Builder.class);
25 25
26 public static final String DC_NAMESPACE_URI = 26 public static final String DC_NAMESPACE_URI =
27 "http://www.intevation.org/2011/Datacage"; 27 "http://www.intevation.org/2011/Datacage";
28 28
29 protected Document template; 29 protected Document template;
30 30
31 public class BuildHelper 31 public class BuildHelper
32 { 32 {
33 protected Document output; 33 protected Document output;
34 protected StackFrames frames; 34 protected StackFrames frames;
35 protected Connection connection; 35 protected Connection connection;
36 protected Map<String, CompiledStatement> statements; 36 protected Map<String, CompiledStatement> statements;
37 37
38 public BuildHelper() { 38 public BuildHelper(
39 frames = new StackFrames(); 39 Document output,
40 statements = new HashMap<String, CompiledStatement>(); 40 Connection connection,
41 } 41 Map<String, Object> parameters
42 42 ) {
43 public BuildHelper(Document output, Connection connection) {
44 this();
45 this.output = output; 43 this.output = output;
46 this.connection = connection; 44 this.connection = connection;
45 frames = new StackFrames(parameters);
46 statements = new HashMap<String, CompiledStatement>();
47 } 47 }
48 48
49 public void build(List<Node> elements) throws SQLException { 49 public void build(List<Node> elements) throws SQLException {
50 try { 50 try {
51 for (Node current: elements) { 51 for (Node current: elements) {
87 return; 87 return;
88 } 88 }
89 89
90 String stmntText = stmntNode.item(0).getTextContent(); 90 String stmntText = stmntNode.item(0).getTextContent();
91 91
92 if (stmntText == null) { 92 if (stmntText == null
93 log.warn("dc:context: no sql statement found"); 93 || (stmntText = stmntText.trim()).length() == 0) {
94 log.warn("dc:context: no sql statement found -> ignored");
95 return;
94 } 96 }
95 97
96 CompiledStatement cs = statements.get(stmntText); 98 CompiledStatement cs = statements.get(stmntText);
97 99
98 if (cs == null) { 100 if (cs == null) {
165 Element element = (Element)parent; 167 Element element = (Element)parent;
166 168
167 element.setAttribute(name, value); 169 element.setAttribute(name, value);
168 } 170 }
169 171
172 protected void convert(Node parent, Element current) {
173
174 String variable = expand(current.getAttribute("var"));
175 String type = expand(current.getAttribute("type"));
176
177 if (frames.containsKey(variable)) {
178 Object object = TypeConverter.convert(
179 frames.get(variable),
180 type);
181 frames.put(variable, object);
182 }
183 }
184
170 protected String expand(String s) { 185 protected String expand(String s) {
171 Matcher m = CompiledStatement.VAR.matcher(s); 186 Matcher m = CompiledStatement.VAR.matcher(s);
172 187
173 StringBuffer sb = new StringBuffer(); 188 StringBuffer sb = new StringBuffer();
174 while (m.find()) { 189 while (m.find()) {
200 element(parent, (Element)current); 215 element(parent, (Element)current);
201 } 216 }
202 else if ("text".equals(localName)) { 217 else if ("text".equals(localName)) {
203 text(parent, (Element)current); 218 text(parent, (Element)current);
204 } 219 }
220 else if ("convert".equals(localName)) {
221 convert(parent, (Element)current);
222 }
205 else { 223 else {
206 log.warn("unknown '" + localName + "' -> ignore"); 224 log.warn("unknown '" + localName + "' -> ignore");
207 } 225 }
208 } 226 }
209 return; 227 return;
235 } 253 }
236 254
237 public Document build(Connection connection) 255 public Document build(Connection connection)
238 throws SQLException 256 throws SQLException
239 { 257 {
240 return build(connection, XMLUtils.newDocument()); 258 return build(connection, XMLUtils.newDocument(), null);
241 } 259 }
242 260
243 public Document build(Connection connection, Document output) 261 public Document build(
262 Connection connection,
263 Document output,
264 Map<String, Object> parameters
265 )
244 throws SQLException 266 throws SQLException
245 { 267 {
246 NodeList roots = template.getElementsByTagNameNS( 268 NodeList roots = template.getElementsByTagNameNS(
247 DC_NAMESPACE_URI, "template"); 269 DC_NAMESPACE_URI, "template");
248 270
249 BuildHelper helper = new BuildHelper(output, connection); 271 BuildHelper helper = new BuildHelper(output, connection, parameters);
250 272
251 List<Node> elements = new ArrayList<Node>(); 273 List<Node> elements = new ArrayList<Node>();
252 274
253 for (int i = 0, N = roots.getLength(); i < N; ++i) { 275 for (int i = 0, N = roots.getLength(); i < N; ++i) {
254 NodeList rootChildren = roots.item(i).getChildNodes(); 276 NodeList rootChildren = roots.item(i).getChildNodes();

http://dive4elements.wald.intevation.org