}
// It is possible that the namespace is associated with multiple prefixes,
// So try getting the namespace as a second step.
if (writerPrefix != null) {
NamespaceContext nsContext = writer.getNamespaceContext();
if(nsContext != null) {
String writerNS = nsContext.getNamespaceURI(prefix);
return namespace.equals(writerNS);
}
}
return false;
} else {
// UNQUALIFIED NAMESPACE
// Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
if (prefix.length() > 0) {
throw new OMException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");
}
// Get the namespace associated with the prefix.
// It is illegal to call getPrefix with null, but the specification is not
// clear on what happens if called with "". So the following code is
// protected
try {
String writerPrefix = writer.getPrefix("");
if (writerPrefix != null && writerPrefix.length() == 0) {
return true;
}
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
}
}
// Fallback to using the namespace context
NamespaceContext nsContext = writer.getNamespaceContext();
if (nsContext != null) {
String writerNS = nsContext.getNamespaceURI("");
if (writerNS != null && writerNS.length() > 0) {
return false;
}
}
return true;