Map<String,String> prefixMap = getPrefixMap();
String prefix = getNamespaceMap().get(namespace);
if (prefix != null) {
return prefix;
} else if (create) { // only if not present and prefix is true
NamespaceEnum defaultMapping = NamespaceEnum.forNamespace(namespace);
if (defaultMapping != null && !prefixMap.containsKey(defaultMapping.getPrefix())) {
/*
* NOTE: we need to check here also if the default prefix is not yet taken, because the Solr
* Index used to store the prefixes might be older than the latest change within the
* NamespaceEnum. Therefore there might be cases where a default prefix configured by this
* Enum is already assigned to a different namespace within the Solr index! In such cases, we
* need to create a new prefix for this namespace
*/
prefix = defaultMapping.getPrefix();
} else {
// need to generate a default mapping
prefix = createPrefix(prefixMap);
}
addNamespaceMapping(prefix, namespace); // we need to add the new mapping