- public final static Comparator<QName> QNAME_COMPARATOR = new Comparator<QName>() {
-
- @Override
- public int compare(QName qn1, QName qn2) {
- if (Objects.equals(qn1.getNamespaceURI(), qn2.getNamespaceURI())) {// same namespace
- return qn1.getLocalPart().compareTo(qn2.getLocalPart());
- } else {
- return qn1.getNamespaceURI().compareTo(qn2.getNamespaceURI());
- }
+ /**
+ * Whether thei {@link QName} has a namespace, that is its namespace is not
+ * {@link XMLConstants#NULL_NS_URI}.
+ */
+ public static boolean hasNamespace(QName qName) {
+ return !qName.getNamespaceURI().equals(XMLConstants.NULL_NS_URI);
+ }
+
+ /** Throws an exception if the provided string has a prefix. */
+ public static void checkNoPrefix(String unqualified) throws IllegalArgumentException {
+ if (unqualified.indexOf(':') >= 0)
+ throw new IllegalArgumentException("Name " + unqualified + " has a prefix");
+ }
+
+ /**
+ * Create an unqualified {@link QName}, checking that the argument does not
+ * contain a prefix.
+ */
+ public static QName unqualified(String name) {
+ checkNoPrefix(name);
+ return new ContentName(XMLConstants.NULL_NS_URI, name, XMLConstants.DEFAULT_NS_PREFIX);
+
+ }
+
+ /**
+ * The common (fully qualified) representation of this name, as defined in
+ * {@link QName#toString()}. This should be used when a fully qualified
+ * representation is required, as subclasses of {@link QName} may override the
+ * {@link QName#toString()} method.
+ *
+ * @see ContentName#toString()
+ */
+ public static String toFullyQualified(QName name) {
+ if (name.getNamespaceURI().equals(XMLConstants.NULL_NS_URI)) {
+ return name.getLocalPart();
+ } else {
+ return "{" + name.getNamespaceURI() + "}" + name.getLocalPart();