public static void validatePath ( final Session session , final String path ) { final NamespaceRegistry namespaceRegistry = getNamespaceRegistry ( session ) ; final String [ ] pathSegments = path . replaceAll ( "^/+" , "" ) . replaceAll ( "/+$" , "" ) . split ( "/" ) ; for ( final String segment : pathSegments ) { final int colonPosition = segment . indexOf ( ' ' ) ; if ( segment . length ( ) > 0 && colonPosition > - 1 ) { final String prefix = segment . substring ( 0 , colonPosition ) ; // Skip the fcr namespace registration check to avoid the FedoraInvalidNamespaceException, // which will happen when it fails to retrieve the memento from Modeshape. if ( ! prefix . equals ( "fedora" ) && ! prefix . equals ( "fcr" ) ) { if ( prefix . length ( ) == 0 ) { throw new FedoraInvalidNamespaceException ( "Empty namespace in " + segment ) ; } try { namespaceRegistry . getURI ( prefix ) ; } catch ( final NamespaceException e ) { throw new FedoraInvalidNamespaceException ( "Prefix " + prefix + " has not been registered" , e ) ; } catch ( final RepositoryException e ) { throw new RepositoryRuntimeException ( e ) ; } } } } }
Validate resource path for unregistered namespace prefixes