From ea993d0e259bf29c71a1307492bccfccf180293d Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 15 Sep 2009 20:37:43 +0000 Subject: Add methods to DOMHelper to deal with namespace/prefix lookups git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@815472 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/common/xml/dom/DOMHelper.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'java/sca/modules') diff --git a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java index 3c3a2f2097..f2f63e80c6 100644 --- a/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java +++ b/java/sca/modules/common-xml/src/main/java/org/apache/tuscany/sca/common/xml/dom/DOMHelper.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -207,6 +208,20 @@ public class DOMHelper { } return doc; } + + public static String getPrefix(Element element, String namespace) { + if (element.isDefaultNamespace(namespace)) { + return XMLConstants.DEFAULT_NS_PREFIX; + } + return element.lookupPrefix(namespace); + } + + public static String getNamespaceURI(Element element, String prefix) { + if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { + prefix = null; + } + return element.lookupNamespaceURI(prefix); + } public static interface NodeContentHandler extends ContentHandler, LexicalHandler { Node getNode(); -- cgit v1.2.3