* @throws RepositoryException if an error during repository access occurs.
*/
private String getJcrName(DavPropertyName propName, Session session) throws RepositoryException {
// remove any encoding necessary for xml compliance
String pName = ISO9075.decode(propName.getName());
Namespace propNamespace = propName.getNamespace();
if (!Namespace.EMPTY_NAMESPACE.equals(propNamespace)) {
String prefix;
String emptyPrefix = Namespace.EMPTY_NAMESPACE.getPrefix();
try {
// lookup 'prefix' in the session-ns-mappings / namespace-registry
prefix = session.getNamespacePrefix(propNamespace.getURI());
} catch (NamespaceException e) {
// namespace uri has not been registered yet
NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
prefix = propNamespace.getPrefix();
// avoid trouble with default namespace
if (emptyPrefix.equals(prefix)) {
prefix = "_pre" + nsReg.getPrefixes().length + 1;
}
// NOTE: will fail if prefix is already in use in the namespace registry
nsReg.registerNamespace(prefix, propNamespace.getURI());
}
if (prefix != null && !emptyPrefix.equals(prefix)) {
pName = prefix + ":" + pName;
}
}