public static String getEncapsulatingDir ( final String aPtPath ) throws InvalidPathException { Objects . requireNonNull ( aPtPath , LOGGER . getMessage ( MessageCodes . PT_003 ) ) ; // Walk the Pairtree path looking for first non-shorty final String [ ] pPathParts = aPtPath . split ( "\\" + mySeparator ) ; // If there is only 1 part if ( pPathParts . length == SINGLE_PART ) { // If part <= shorty length then no encapsulating directory if ( pPathParts [ 0 ] . length ( ) <= myShortyLength ) { return null ; } else { // Else no Pairtree path throw new InvalidPathException ( MessageCodes . PT_001 , aPtPath ) ; } } // All parts up to next to last and last should have shorty length for ( int index = 0 ; index < pPathParts . length - 2 ; index ++ ) { if ( pPathParts [ index ] . length ( ) != myShortyLength ) { throw new InvalidPathException ( MessageCodes . PT_002 , myShortyLength , pPathParts [ index ] . length ( ) , aPtPath ) ; } } final String nextToLastPart = pPathParts [ pPathParts . length - 2 ] ; // Next to last should have shorty length or less if ( nextToLastPart . length ( ) > myShortyLength ) { throw new InvalidPathException ( MessageCodes . PT_005 , aPtPath ) ; } String lastPart = pPathParts [ pPathParts . length - 1 ] ; // If next to last has shorty length if ( nextToLastPart . length ( ) == myShortyLength ) { // If last has length > shorty length then encapsulating directory if ( lastPart . length ( ) > myShortyLength ) { lastPart = decodeID ( lastPart ) ; } else { // Else no encapsulating directory lastPart = null ; } } // Else last is encapsulating directory return lastPart == null ? null : decodeID ( lastPart ) ; }
Extracts the encapsulating directory from the supplied Pairtree path .