# HG changeset patch # User Sascha L. Teichmann # Date 1311237154 0 # Node ID a5e6d1923c956adcf9d7631157c518c040dca606 # Parent 694d818e99b20a61e5fcb35bd25c0cc03914a08d Made namespace resolution more compatible. artifacts/trunk@2383 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 694d818e99b2 -r a5e6d1923c95 ChangeLog --- a/ChangeLog Wed Jul 20 12:30:57 2011 +0000 +++ b/ChangeLog Thu Jul 21 08:32:34 2011 +0000 @@ -1,3 +1,13 @@ +2011-07-21 Sascha L. Teichmann + + * artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java: + Made it more compatible with mixed namespaces and mixtures of namespaces + and no namespaces. + + * artifacts/pom.xml: Set Java compatibility to 1.5. Why isn't this inherited + from main pom.xml? The artifact-database module uses 1.5 features but does + not need any extra configuration. + 2011-07-20 Ingo Weinzierl * artifacts/src/main/java/de/intevation/artifacts/Artifact.java, diff -r 694d818e99b2 -r a5e6d1923c95 artifacts/pom.xml --- a/artifacts/pom.xml Wed Jul 20 12:30:57 2011 +0000 +++ b/artifacts/pom.xml Thu Jul 21 08:32:34 2011 +0000 @@ -18,6 +18,15 @@ + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + org.codehaus.mojo buildnumber-maven-plugin diff -r 694d818e99b2 -r a5e6d1923c95 artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java --- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java Wed Jul 20 12:30:57 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java Thu Jul 21 08:32:34 2011 +0000 @@ -9,6 +9,9 @@ package de.intevation.artifacts; import java.util.Iterator; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; import javax.xml.XMLConstants; @@ -39,10 +42,25 @@ public static final ArtifactNamespaceContext INSTANCE = new ArtifactNamespaceContext(); + protected Map map; + /** * The default constructor. */ public ArtifactNamespaceContext() { + map = new HashMap(); + map.put( + XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); + map.put( + XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.DEFAULT_NS_PREFIX); + map.put( + XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI); + map.put( + NAMESPACE_PREFIX, NAMESPACE_URI); + } + + public void add(String prefix, String uri) { + map.put(prefix, uri); } /** @@ -53,38 +71,45 @@ public String getNamespaceURI(String prefix) { if (prefix == null) { - throw new NullPointerException("Null prefix"); + throw new IllegalArgumentException("Null prefix"); } - if (NAMESPACE_PREFIX.equals(prefix)) { - return NAMESPACE_URI; - } + String namespace = map.get(prefix); - if ("xml".equals(prefix)) { - return XMLConstants.XML_NS_URI; - } - - return XMLConstants.NULL_NS_URI; + return namespace != null ? namespace : XMLConstants.NULL_NS_URI; } /** * @see javax.xml.namespace.NamespaceContext#getPrefix(String) * @param uri The URI - * @return nothing. - * @throws java.lang.UnsupportedOperationException */ public String getPrefix(String uri) { - throw new UnsupportedOperationException(); + + if (uri == null) { + throw new IllegalArgumentException("Null uri"); + } + + for (Map.Entry entry: map.entrySet()) { + if (entry.getValue().equals(uri)) { + return entry.getKey(); + } + } + + return XMLConstants.DEFAULT_NS_PREFIX; } /** * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) * @param uri The URI - * @return nothing - * @throws java.lang.UnsupportedOperationException */ public Iterator getPrefixes(String uri) { - throw new UnsupportedOperationException(); + ArrayList results = new ArrayList(); + for (Map.Entry entry: map.entrySet()) { + if (entry.getValue().equals(uri)) { + results.add(entry.getKey()); + } + } + return results.iterator(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :