Debian Codegraph @

src/main/java/ezvcard/io/xml/XCardNamespaceContext.java

raw symbols SCIP
1 package ezvcard.io.xml;
2
3 import java.util.Collections;
4 import java.util.Iterator;
5
6 import javax.xml.namespace.NamespaceContext;
7 import javax.xml.xpath.XPath;
8
9 import ezvcard.VCardVersion;
10
11 /**
12 * Used for xCard XPath expressions.
13 * @see XPath#setNamespaceContext(NamespaceContext)
14 * @author Michael Angstadt
15 */
16 public class XCardNamespaceContext implements NamespaceContext {
17 private final String ns;
18 private final String prefix;
19
20 /**
21 * @param version the vCard version to use
22 * @param prefix the prefix to use
23 */
24 public XCardNamespaceContext(VCardVersion version, String prefix) {
25 this.ns = version.getXmlNamespace();
26 this.prefix = prefix;
27 }
28
29 /**
30 * Gets the prefix to use in xpath expressions.
31 * @return the xpath prefix
32 */
33 public String getPrefix() {
34 return prefix;
35 }
36
37 //@Override
38 public String getNamespaceURI(String prefix) {
39 if (this.prefix.equals(prefix)) {
40 return ns;
41 }
42 return null;
43 }
44
45 //@Override
46 public String getPrefix(String ns) {
47 if (this.ns.equals(ns)) {
48 return prefix;
49 }
50 return null;
51 }
52
53 //@Override
54 public Iterator<String> getPrefixes(String ns) {
55 if (this.ns.equals(ns)) {
56 return Collections.singletonList(prefix).iterator();
57 }
58 return null;
59 }
60 }