diff artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 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 00596a591a2f
children 83a059c204f8
line wrap: on
line diff
--- 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:

http://dive4elements.wald.intevation.org