protected static String getParentNameFromURI ( final StorageUri resourceAddress , final CloudFileShare share ) throws URISyntaxException { Utility . assertNotNull ( "resourceAddress" , resourceAddress ) ; Utility . assertNotNull ( "share" , share ) ; String delimiter = "/" ; String shareName = share . getName ( ) + delimiter ; String relativeURIString = Utility . safeRelativize ( share . getStorageUri ( ) . getPrimaryUri ( ) , resourceAddress . getPrimaryUri ( ) ) ; if ( relativeURIString . endsWith ( delimiter ) ) { relativeURIString = relativeURIString . substring ( 0 , relativeURIString . length ( ) - delimiter . length ( ) ) ; } String parentName ; if ( Utility . isNullOrEmpty ( relativeURIString ) ) { // Case 1 /<ShareName>[Delimiter]*? => /<ShareName> // Parent of share is share itself parentName = null ; } else { final int lastDelimiterDex = relativeURIString . lastIndexOf ( delimiter ) ; if ( lastDelimiterDex < 0 ) { // Case 2 /<Share>/<Directory> // Parent of a Directory is Share parentName = "" ; } else { // Case 3 /<Share>/<Directory>/[<subDirectory>/]*<FileName> // Parent of CloudFile is CloudFileDirectory parentName = relativeURIString . substring ( 0 , lastDelimiterDex ) ; if ( parentName != null && parentName . equals ( shareName ) ) { parentName = "" ; } } } return parentName ; }
Retrieves the parent name for a file URI .