/** * Gets the root ID for a qualified name. All names in the same namespace * will be stored together, to allow transforms to affect all properties in * a namespace through transforms on uri:*. */ private static QName getRootId(QName id) { if (id.getNs() != null && !"*".equals(id.getLocalName())) { return new QName(id.getNs(), "*"); } return id; }
/** * Order two QNames, where either may be null. A null value is considered * lower than a non-null value, and will come before it in the list. This * forces more-specific qnames to appear later. */ static int compareQName(QName a, QName b) { if (a == b) { return 0; } // If a is null (and b non-null), a < b. if (a == null) { return -1; } // If b is null (and a non-null), a > b. if (b == null) { return 1; } // Else compare using normal QName compare. return a.compareTo(b); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof RootKey)) { return false; } RootKey other = (RootKey) obj; if (type != null) { return type == other.type; } return id.equals(other.id); }
@Override public String toString() { if (getNs() == null || "".equals(getNs().getAlias())) { return getLocalName(); } return getNs().getAlias() + ":" + getLocalName(); }
if (id.matchesAnyNamespace()) { for (Map.Entry<QName, AttributeKey<?>> attrEntry : attributes.entrySet()) { if (id.matches(attrEntry.getKey())) { return attrEntry.getValue(); } else if (!id.matchesAnyLocalName()) {
/** * Checks if this QName is a match for the other QName. A QName is a match * if it is null and if 1) the local namespace is {@link ANY_NAMESPACE} or * the two namespaces are both null or have a matching uri and 2) the local * name is {@link ANY_LOCALNAME} or the two local names are equal. */ public boolean matches(QName o) { if (o == null) { return false; } if (!matchesAnyNamespace()) { XmlNamespace otherNs = o.getNs(); String idUri = (namespace == null) ? null : namespace.getUri(); String otherUri = (otherNs == null) ? null : otherNs.getUri(); // Check namespace uris. if (idUri == null) { if (otherUri != null) { return false; } } else if (!idUri.equals(otherUri)) { return false; } } // Check the local names. if (matchesAnyLocalName()) { return true; } return localName.equals(o.getLocalName()); }
private static void addAtompubTransform(MetadataRegistry registry, ElementKey<?, ?> key) { registry.build(key, V1_CONTEXT).setName( new QName(Namespaces.atomPubDraftNs, key.getId().getLocalName())); } }
@Override public int hashCode() { if (type != null) { return type.hashCode(); } return id.hashCode(); }
public XmlNamespace getDefaultNamespace() { // The default implementation uses the default namespace for the in-use name return getName().getNs(); }
/** * Converts a ContentValidationException to a parse exception, with a * separate exception for each parser error that was encountered. */ public ParseException toParseException() { ParseException result = null; Map<Element, List<ErrorContent>> errors = vc.getErrors(); for (Map.Entry<Element, List<ErrorContent>> entry : errors.entrySet()) { Element element = entry.getKey(); String location = element.getElementKey().getId().toString(); List<ErrorContent> codes = entry.getValue(); for (ErrorContent errorCode : codes) { ParseException pe = new ParseException(errorCode); pe.setLocation(location); if (result == null) { result = pe; } else { result.addSibling(pe); } } } return result; } }
/** * Match on id and datatype, used by subclasses to implement matching. */ boolean matchIdAndDatatype(MetadataKey<?> other) { if (id != null && !id.matches(other.id)) { return false; } // Datatypes much match if they are non-default types. return datatype.isAssignableFrom(other.datatype) || other.datatype == String.class; }
private static QName createQName( String qName, String nsUri, String localName) { XmlNamespace ns = null; if (!StringUtil.isEmpty(nsUri)) { String[] parts = qName.split(":"); if (parts.length == 2) { ns = new XmlNamespace(parts[0], nsUri); } else { ns = new XmlNamespace(null, nsUri); } } return new QName(ns, localName); } }
@Override public boolean equals(Object other) { if (!(other instanceof QName)) { return false; } QName otherQName = (QName) other; if (this.getNs() == null && otherQName.getNs() == null) { return getLocalName().equals(otherQName.getLocalName()); } if (this.getNs() != null && otherQName.getNs() != null) { return this.getNs().getUri().equals(otherQName.getNs().getUri()) && getLocalName().equals(otherQName.getLocalName()); } return false; }
if (id.matchesAnyNamespace()) { for (Map.Entry<QName, AttributeKey<?>> attrEntry : attributes.entrySet()) { if (id.matches(attrEntry.getKey())) { return attrEntry.getValue(); } else if (!id.matchesAnyLocalName()) {
/** * Checks if this QName is a match for the other QName. A QName is a match * if it is null and if 1) the local namespace is {@link ANY_NAMESPACE} or * the two namespaces are both null or have a matching uri and 2) the local * name is {@link ANY_LOCALNAME} or the two local names are equal. */ public boolean matches(QName o) { if (o == null) { return false; } if (!matchesAnyNamespace()) { XmlNamespace otherNs = o.getNs(); String idUri = (namespace == null) ? null : namespace.getUri(); String otherUri = (otherNs == null) ? null : otherNs.getUri(); // Check namespace uris. if (idUri == null) { if (otherUri != null) { return false; } } else if (!idUri.equals(otherUri)) { return false; } } // Check the local names. if (matchesAnyLocalName()) { return true; } return localName.equals(o.getLocalName()); }
@SuppressWarnings("deprecation") private static void addOssTransform(MetadataRegistry registry, ElementKey<?, ?> key) { registry.build(key, V1_CONTEXT).setName( new QName(Namespaces.openSearchNs, key.getId().getLocalName())); } }
@Override public int hashCode() { int hashCode = datatype.hashCode(); hashCode *= 17; if (id != null) { hashCode += id.hashCode(); } return hashCode; }
public XmlNamespace getDefaultNamespace() { // The default implementation uses the default namespace for the in-use name return getName().getNs(); }