export default class ResourceUtils { public static ABSOLUTE_PATH_PATTERN : RegExp = /^\// ; param resource returns { any } public static getChildren ( resource ) { let children = { } ; if ( resource ) { Object . keys ( resource ) . forEach ( ( propertyName ) : void => { let child = resource [ propertyName ] ; if ( child [ "sling:resourceType" ] ) { children [ propertyName ] = child ; } } ) ; } return children ; } public static getProperty ( data , path ) { for ( let i = 0 ; i < path . length ; i ++ ) { data = data [ path [ i ] ] ; if ( ! data ) { return null ; } } return data ; } public static isAbsolutePath ( path ) { return ResourceUtils . ABSOLUTE_PATH_PATTERN . test ( path ) ; } public static findAncestor ( resourcePath , depth ) { let subPath = [ ] ; for ( let i = 0 ; i < depth ; i ++ ) { let index = resourcePath . lastIndexOf ( "/" ) ; if ( index < 0 ) { return null ; } subPath . push ( resourcePath . substring ( index + 1 ) ) ; resourcePath = resourcePath . substring ( 0 , index ) ; } return { path : resourcePath , subPath : subPath } ; } public static getContainingPagePath ( requestPath ) { let index = requestPath . indexOf ( "jcr:content" ) ; if ( index < 0 ) { return requestPath ; } let dot = requestPath . indexOf ( "." ) ; return requestPath . substring ( 0 , index - 1 ) + requestPath . substring ( dot , requestPath . length ) ; } } export interface PathResult { path : string ; subPath : string [ ] ; }