public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI)
throws XMLStreamException {
return getUniquePrefix(writer, namespaceURI, false);
}
public static String getUniquePrefix(XMLStreamWriter writer) {
NamespaceContext nc = writer.getNamespaceContext();
if (nc == null) {
return DEF_PREFIXES[0];
}
for (String t : DEF_PREFIXES) {
String uri = nc.getNamespaceURI(t);
if (StringUtils.isEmpty(uri)) {
return t;
}
}
int n = 10;
while (true) {
String nsPrefix = "ns" + n;
String uri = nc.getNamespaceURI(nsPrefix);
if (StringUtils.isEmpty(uri)) {
return nsPrefix;
}
n++;
}