comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java @ 972:0c8aca463bd4

Added caching support for the static part of the datacage. flys-artifacts/trunk@2398 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 22 Jul 2011 16:55:36 +0000
parents f48cef242e7f
children c30ada285d45
comparison
equal deleted inserted replaced
971:d0c9a5f32c30 972:0c8aca463bd4
1 package de.intevation.flys.artifacts.services.meta; 1 package de.intevation.flys.artifacts.services.meta;
2 2
3 import java.util.regex.Pattern;
3 import java.util.regex.Matcher; 4 import java.util.regex.Matcher;
4 5
5 import java.util.ArrayList; 6 import java.util.ArrayList;
6 import java.util.List; 7 import java.util.List;
7 import java.util.HashMap; 8 import java.util.HashMap;
26 27
27 public class Builder 28 public class Builder
28 { 29 {
29 private static Logger log = Logger.getLogger(Builder.class); 30 private static Logger log = Logger.getLogger(Builder.class);
30 31
32 public static final Pattern STRIP_LINE_INDENT =
33 Pattern.compile("\\s*\\r?\\n\\s*");
34
31 public static final String DC_NAMESPACE_URI = 35 public static final String DC_NAMESPACE_URI =
32 "http://www.intevation.org/2011/Datacage"; 36 "http://www.intevation.org/2011/Datacage";
33 37
34 private static final Document EVAL_DOCUMENT = 38 private static final Document EVAL_DOCUMENT =
35 XMLUtils.newDocument(); 39 XMLUtils.newDocument();
36 40
37 private static final XPathFactory XPATH_FACTORY = 41 private static final XPathFactory XPATH_FACTORY =
38 XPathFactory.newInstance(); 42 XPathFactory.newInstance();
39 43
40 protected Document template; 44 protected Document template;
41
42 protected static Document getOwnerDocument(Node node) {
43 Document document = node.getOwnerDocument();
44 return document != null ? document : (Document)node;
45 }
46 45
47 46
48 public class BuildHelper 47 public class BuildHelper
49 { 48 {
50 protected Node output; 49 protected Node output;
107 } 106 }
108 107
109 String stmntText = stmntNode.item(0).getTextContent(); 108 String stmntText = stmntNode.item(0).getTextContent();
110 109
111 if (stmntText == null 110 if (stmntText == null
112 || (stmntText = stmntText.trim()).length() == 0) { 111 || (stmntText = trimStatement(stmntText)).length() == 0) {
113 log.warn("dc:context: no sql statement found -> ignored"); 112 log.warn("dc:context: no sql statement found -> ignored");
114 return; 113 return;
115 } 114 }
116 115
117 CompiledStatement cs = statements.get(stmntText); 116 CompiledStatement cs = statements.get(stmntText);
333 if (current.getNodeType() != Node.ELEMENT_NODE) { 332 if (current.getNodeType() != Node.ELEMENT_NODE) {
334 log.warn("need elements here"); 333 log.warn("need elements here");
335 } 334 }
336 else { 335 else {
337 String localName = current.getLocalName(); 336 String localName = current.getLocalName();
338 if ("context".equals(localName)) { 337 if ("attribute".equals(localName)) {
338 attribute(parent, (Element)current);
339 }
340 else if ("context".equals(localName)) {
339 context(parent, (Element)current); 341 context(parent, (Element)current);
342 }
343 else if ("if".equals(localName)) {
344 ifClause(parent, (Element)current);
340 } 345 }
341 else if ("choose".equals(localName)) { 346 else if ("choose".equals(localName)) {
342 choose(parent, (Element)current); 347 choose(parent, (Element)current);
343 } 348 }
344 else if ("if".equals(localName)) { 349 else if ("call-macro".equals(localName)) {
345 ifClause(parent, (Element)current); 350 callMacro(parent, (Element)current);
346 } 351 }
347 else if ("attribute".equals(localName)) { 352 else if ("macro".equals(localName)) {
348 attribute(parent, (Element)current); 353 // simply ignore the definition.
349 } 354 }
350 else if ("element".equals(localName)) { 355 else if ("element".equals(localName)) {
351 element(parent, (Element)current); 356 element(parent, (Element)current);
352 } 357 }
353 else if ("text".equals(localName)) { 358 else if ("text".equals(localName)) {
354 text(parent, (Element)current); 359 text(parent, (Element)current);
355 } 360 }
356 else if ("convert".equals(localName)) { 361 else if ("convert".equals(localName)) {
357 convert(parent, (Element)current); 362 convert(parent, (Element)current);
358 }
359 else if ("call-macro".equals(localName)) {
360 callMacro(parent, (Element)current);
361 }
362 else if ("macro".equals(localName)) {
363 // simply ignore the definition.
364 } 363 }
365 else { 364 else {
366 log.warn("unknown '" + localName + "' -> ignore"); 365 log.warn("unknown '" + localName + "' -> ignore");
367 } 366 }
368 } 367 }
407 } 406 }
408 } 407 }
409 } 408 }
410 409
411 return elements; 410 return elements;
411 }
412
413 protected static final String trimStatement(String stmnt) {
414 //XXX: Maybe a bit to radical for multiline strings?
415 return STRIP_LINE_INDENT.matcher(stmnt.trim()).replaceAll(" ");
416 }
417
418 protected static Document getOwnerDocument(Node node) {
419 Document document = node.getOwnerDocument();
420 return document != null ? document : (Document)node;
412 } 421 }
413 422
414 public void build( 423 public void build(
415 Connection connection, 424 Connection connection,
416 Node output, 425 Node output,

http://dive4elements.wald.intevation.org