| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ken.util; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.Iterator; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import javax.xml.namespace.NamespaceContext; |
| 23 | |
|
| 24 | |
import org.apache.log4j.Logger; |
| 25 | |
import org.w3c.dom.Document; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class DocumentNamespaceContext implements NamespaceContext { |
| 33 | 0 | private static final Logger LOG = Logger.getLogger(DocumentNamespaceContext.class); |
| 34 | |
|
| 35 | |
|
| 36 | |
private final Document doc; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | 0 | public DocumentNamespaceContext(Document doc) { |
| 43 | 0 | this.doc = doc; |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public String getNamespaceURI(String prefix) { |
| 50 | 0 | LOG.debug("getNamespaceURI(" + prefix + ")"); |
| 51 | 0 | if (prefix == null) { |
| 52 | 0 | throw new IllegalArgumentException("The prefix cannot be null."); |
| 53 | |
} |
| 54 | 0 | if (prefix.length() == 0) { |
| 55 | 0 | return doc.lookupNamespaceURI(null); |
| 56 | |
} |
| 57 | 0 | return doc.lookupNamespaceURI(prefix); |
| 58 | |
} |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public String getPrefix(String namespaceURI) { |
| 64 | 0 | LOG.debug("getPrefix(" + namespaceURI + ")"); |
| 65 | 0 | if (namespaceURI == null) { |
| 66 | 0 | throw new IllegalArgumentException("The namespace uri cannot be null."); |
| 67 | |
} |
| 68 | 0 | return doc.lookupPrefix(namespaceURI); |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public Iterator getPrefixes(String namespaceURI) { |
| 75 | 0 | LOG.debug("getPrefixes(" + namespaceURI + ")"); |
| 76 | 0 | if (namespaceURI == null) { |
| 77 | 0 | throw new IllegalArgumentException("The namespace uri cannot be null."); |
| 78 | |
} |
| 79 | 0 | List<String> list = new ArrayList<String>(1); |
| 80 | 0 | String s = getPrefix(namespaceURI); |
| 81 | 0 | if (s != null) { |
| 82 | 0 | list.add(s); |
| 83 | |
} |
| 84 | 0 | return list.iterator(); |
| 85 | |
} |
| 86 | |
} |