/** * Returns the last mapping for the prefix or null if the prefix was not mapped. */ public String getPrefix(String nsURI) { Object obj = prefixByUri.get(nsURI); String prefix = null; if (obj != null) { if (obj instanceof String) { prefix = (String)obj; } else if (obj instanceof List) { List list = (List)obj; prefix = (String)list.get(list.size() - 1); } else { throwUnexpectedEntryException(obj); } } return prefix; }
/** Get the nsURI for a given prefix, maybe null. */ public String getNamespaceURI(String prefix) { Object obj = uriByPrefix.get(prefix); String uri = null; if (obj != null) { if (obj instanceof String) { uri = (String)obj; } else if (obj instanceof List) { List list = (List)obj; uri = (String)list.get(list.size() - 1); } else { throwUnexpectedEntryException(obj); } } return uri; }
/** * Returns all prefixes for the given URI. * * @param namespaceURI the URI to return prefixes for * @return prefixes mapped to the URI */ public Iterator getPrefixes(String namespaceURI) { Object obj = prefixByUri.get(namespaceURI); Iterator result = null; if (obj == null) { result = Collections.EMPTY_LIST.iterator(); } else if (obj instanceof String) { result = Collections.singletonList(obj).iterator(); } else if (obj instanceof List) { result = ((List)obj).iterator(); } else { throwUnexpectedEntryException(obj); } return result; }