Skip to content

Commit

Permalink
[bugfix] Correct the difference between QName#getStringValue() and QN…
Browse files Browse the repository at this point in the history
…ame#toString()
  • Loading branch information
adamretter committed Sep 10, 2023
1 parent c074a66 commit ad96fd2
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions exist-core/src/main/java/org/exist/dom/QName.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,44 @@ public byte getNameType() {
return nameType;
}

/**
* Get a string representation of this qualified name.
*
* Will either be of the format `local-name` or `prefix:local-name`.
*
* @return the string representation of this qualified name.
* */
public String getStringValue() {
if (prefix != null && !prefix.isEmpty()) {
return prefix + COLON + localPart;
} else if (namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + localPart;
}
return localPart;
return getStringRepresentation(false);
}

/**
* Only for debugging purposes,
* use {@link #getStringValue()} for production
* Get a string representation of this qualified name.
*
* Will either be of the format `local-name`, `prefix:local-name`, or `{namespace}local-name`.
*
* @return the string representation of this qualified name.
*/
@Override
public String toString() {
//TODO : remove this copy of getStringValue()
return getStringValue();
//TODO : replace by something like this
/*
if (prefix != null && prefix.length() > 0)
return getStringRepresentation(true);
}

/**
* Get a string representation of this qualified name.
*
* @param showNsWithoutPrefix true if the namespace should be shown even when there is no prefix, false otherwise.
* When shown, it will be output using Clark notation, e.g. `{http://namespace}local-name`.
*
* @return the string representation of this qualified name.
*/
private String getStringRepresentation(final boolean showNsWithoutPrefix) {
if (prefix != null && !prefix.isEmpty()) {
return prefix + COLON + localPart;
if (hasNamespace()) {
if (prefix != null && prefix.length() > 0)
return "{" + namespaceURI + "}" + prefix + COLON + localPart;
return "{" + namespaceURI + "}" + localPart;
} else
return localPart;
*/
} else if (showNsWithoutPrefix && namespaceURI != null && !XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
return LEFT_BRACE + namespaceURI + RIGHT_BRACE + localPart;
}
return localPart;
}

/**
Expand Down Expand Up @@ -568,4 +578,4 @@ private static String asMessage(final byte validity) {
return builder.toString();
}
}
}
}

0 comments on commit ad96fd2

Please sign in to comment.