comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java @ 10:e8626caac353

* Made Artifact life cycle symmetric: setup/endOfLife. * Implement defaults for Artifact and ArtifactFactory. * Added connection pooling from apache commons dbcp * Made sql schema of artifact database more compatible. * Improve example config. * Made artifactdb start with 'mvn exec:exec' * minor fixes. artifacts/trunk@25 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 06 Sep 2009 12:00:56 +0000
parents a5a279a0ee35
children 0d6badf6af42
comparison
equal deleted inserted replaced
9:a5a279a0ee35 10:e8626caac353
18 import javax.xml.xpath.XPathFactory; 18 import javax.xml.xpath.XPathFactory;
19 import javax.xml.xpath.XPath; 19 import javax.xml.xpath.XPath;
20 import javax.xml.xpath.XPathExpressionException; 20 import javax.xml.xpath.XPathExpressionException;
21 import javax.xml.xpath.XPathConstants; 21 import javax.xml.xpath.XPathConstants;
22 22
23 /**
24 * @author Sascha L. Teichmann
25 */
23 public final class Config 26 public final class Config
24 { 27 {
25 public static final String CONFIG_PROPERTY = "artifact.database.config"; 28 public static final String CONFIG_PROPERTY = "artifact.database.config";
26 29
27 public static final String CONFIG_DEFAULT = "artifactdb-conf.xml"; 30 public static final String CONFIG_DEFAULT = "artifactdb-conf.xml";
69 } 72 }
70 73
71 return null; 74 return null;
72 } 75 }
73 76
77 public static final Object getXPath(
78 Object root, String query, QName returnType
79 ) {
80 if (root == null) {
81 return null;
82 }
83
84 XPathFactory factory = XPathFactory.newInstance();
85 XPath xpath = factory.newXPath();
86
87 try {
88 return xpath.evaluate(query, root, returnType);
89 }
90 catch (XPathExpressionException xpee) {
91 xpee.printStackTrace(System.err);
92 }
93
94 return null;
95 }
96
97 public static final Object getXPath(String query, QName returnType) {
98 return getXPath(getConfig(), query, returnType);
99 }
100
101 public static final NodeList getNodeSetXPath(String query) {
102 return (NodeList)getXPath(query, XPathConstants.NODESET);
103 }
104
105 public static final Node getNodeXPath(String query) {
106 return (Node)getXPath(query, XPathConstants.NODE);
107 }
108
74 public static final String getStringXPath(String xpath) { 109 public static final String getStringXPath(String xpath) {
75 return getStringXPath(xpath, null); 110 return getStringXPath(xpath, null);
76 } 111 }
77 112
78 public static final String getStringXPath(String query, String def) { 113 public static final String getStringXPath(String query, String def) {
80 return s == null || s.length() == 0 115 return s == null || s.length() == 0
81 ? def 116 ? def
82 : s; 117 : s;
83 } 118 }
84 119
85 public static final Object getXPath(String query, QName returnType) { 120 public static final NodeList getNodeSetXPath(Object root, String query) {
86 Document document = getConfig(); 121 return (NodeList)getXPath(root, query, XPathConstants.NODESET);
87 if (document == null) {
88 return null;
89 }
90
91 XPathFactory factory = XPathFactory.newInstance();
92 XPath xpath = factory.newXPath();
93
94 try {
95 return xpath.evaluate(query, document, returnType);
96 }
97 catch (XPathExpressionException xpee) {
98 xpee.printStackTrace(System.err);
99 }
100
101 return null;
102 } 122 }
103 123
104 public static final NodeList getNodeSetXPath(String query) { 124 public static final Node getNodeXPath(Object root, String query) {
105 return (NodeList)getXPath(query, XPathConstants.NODESET); 125 return (Node)getXPath(root, query, XPathConstants.NODE);
106 } 126 }
107 127
108 public static final Node getNodeXPath(String query) { 128 public static final String getStringXPath(Object root, String xpath) {
109 return (Node)getXPath(query, XPathConstants.NODE); 129 return getStringXPath(root, xpath, null);
130 }
131
132 public static final String getStringXPath(
133 Object root, String query, String def
134 ) {
135 String s = (String)getXPath(root, query, XPathConstants.STRING);
136 return s == null || s.length() == 0
137 ? def
138 : s;
110 } 139 }
111 } 140 }
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
113 142

http://dive4elements.wald.intevation.org