changeset 25:ccc6aae25585

Moved some XPath stuff from Config into XMLUtils. artifacts/trunk@59 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Sep 2009 09:23:53 +0000
parents d5dc2900392f
children 83a059c204f8
files Changelog artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java
diffstat 4 files changed, 40 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Thu Sep 10 08:57:09 2009 +0000
+++ b/Changelog	Thu Sep 10 09:23:53 2009 +0000
@@ -1,3 +1,12 @@
+2009-09-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java:
+	Removed needless import.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java,
+	artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java:
+	Moved some XPath stuff from Config into XMLUtils.
+
 2009-09-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifacts/src/main/java/de/intevation/artifacts/Artifact.java(setup): Added
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java	Thu Sep 10 08:57:09 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java	Thu Sep 10 09:23:53 2009 +0000
@@ -10,12 +10,10 @@
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.DocumentBuilderFactory;
-
 import javax.xml.parsers.ParserConfigurationException;
 
 import javax.xml.namespace.QName;
 
-import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
@@ -95,22 +93,11 @@
     public static final Object getXPath(
         Object root, String query, QName returnType
     ) {
-        if (root == null) {
-            return null;
-        }
-
-        try {
-            return XMLUtils.newXPath().evaluate(query, root, returnType);
-        }
-        catch (XPathExpressionException xpee) {
-            logger.error(xpee.getLocalizedMessage(), xpee);
-        }
-
-        return null;
+        return XMLUtils.xpath(root, query, returnType);
     }
 
     public static final Object getXPath(String query, QName returnType) {
-        return getXPath(getConfig(), query, returnType);
+        return XMLUtils.xpath(getConfig(), query, returnType);
     }
 
     public static final NodeList getNodeSetXPath(String query) {
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java	Thu Sep 10 08:57:09 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java	Thu Sep 10 09:23:53 2009 +0000
@@ -12,9 +12,10 @@
 
 import javax.xml.xpath.XPathFactory;
 import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
 
 import javax.xml.namespace.NamespaceContext;
-
+import javax.xml.namespace.QName;
 
 /**
  *  @author Sascha L. Teichmann
@@ -77,5 +78,32 @@
         }
         return xpath;
     }
+
+    public static final Object xpath(Object root, String query, QName returnTyp) {
+        return xpath(root, query, returnTyp, null);
+    }
+
+    public static final Object xpath(
+        Object           root,
+        String           query,
+        QName            returnType,
+        NamespaceContext namespaceContext
+    ) {
+        if (root == null) {
+            return null;
+        }
+
+        try {
+            XPath xpath = newXPath(namespaceContext);
+            if (xpath != null) {
+                return xpath.evaluate(query, root, returnType);
+            }
+        }
+        catch (XPathExpressionException xpee) {
+            logger.error(xpee.getLocalizedMessage(), xpee);
+        }        
+
+        return null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java	Thu Sep 10 08:57:09 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java	Thu Sep 10 09:23:53 2009 +0000
@@ -15,8 +15,6 @@
 import de.intevation.artifactdatabase.XMLUtils;
 import de.intevation.artifactdatabase.XMLUtils.ElementCreator;
 
-import de.intevation.artifactdatabase.DefaultArtifact;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 

http://dive4elements.wald.intevation.org