Mercurial > dive4elements > framework
diff 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 |
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Fri Sep 04 16:06:44 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Sun Sep 06 12:00:56 2009 +0000 @@ -20,6 +20,9 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathConstants; +/** + * @author Sascha L. Teichmann + */ public final class Config { public static final String CONFIG_PROPERTY = "artifact.database.config"; @@ -71,6 +74,38 @@ return null; } + public static final Object getXPath( + Object root, String query, QName returnType + ) { + if (root == null) { + return null; + } + + XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath(); + + try { + return xpath.evaluate(query, root, returnType); + } + catch (XPathExpressionException xpee) { + xpee.printStackTrace(System.err); + } + + return null; + } + + public static final Object getXPath(String query, QName returnType) { + return getXPath(getConfig(), query, returnType); + } + + public static final NodeList getNodeSetXPath(String query) { + return (NodeList)getXPath(query, XPathConstants.NODESET); + } + + public static final Node getNodeXPath(String query) { + return (Node)getXPath(query, XPathConstants.NODE); + } + public static final String getStringXPath(String xpath) { return getStringXPath(xpath, null); } @@ -82,31 +117,25 @@ : s; } - public static final Object getXPath(String query, QName returnType) { - Document document = getConfig(); - if (document == null) { - return null; - } - - XPathFactory factory = XPathFactory.newInstance(); - XPath xpath = factory.newXPath(); - - try { - return xpath.evaluate(query, document, returnType); - } - catch (XPathExpressionException xpee) { - xpee.printStackTrace(System.err); - } - - return null; + public static final NodeList getNodeSetXPath(Object root, String query) { + return (NodeList)getXPath(root, query, XPathConstants.NODESET); } - public static final NodeList getNodeSetXPath(String query) { - return (NodeList)getXPath(query, XPathConstants.NODESET); + public static final Node getNodeXPath(Object root, String query) { + return (Node)getXPath(root, query, XPathConstants.NODE); } - public static final Node getNodeXPath(String query) { - return (Node)getXPath(query, XPathConstants.NODE); + public static final String getStringXPath(Object root, String xpath) { + return getStringXPath(root, xpath, null); + } + + public static final String getStringXPath( + Object root, String query, String def + ) { + String s = (String)getXPath(root, query, XPathConstants.STRING); + return s == null || s.length() == 0 + ? def + : s; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: