public Item getItem ( String pathName , ItemGroup context ) { if ( context == null ) context = this ; if ( pathName == null ) return null ; if ( pathName . startsWith ( "/" ) ) // absolute return getItemByFullName ( pathName ) ; Object /*Item|ItemGroup*/ ctx = context ; StringTokenizer tokens = new StringTokenizer ( pathName , "/" ) ; while ( tokens . hasMoreTokens ( ) ) { String s = tokens . nextToken ( ) ; if ( s . equals ( ".." ) ) { if ( ctx instanceof Item ) { ctx = ( ( Item ) ctx ) . getParent ( ) ; continue ; } ctx = null ; // can't go up further break ; } if ( s . equals ( "." ) ) { continue ; } if ( ctx instanceof ItemGroup ) { ItemGroup g = ( ItemGroup ) ctx ; Item i = g . getItem ( s ) ; if ( i == null || ! i . hasPermission ( Item . READ ) ) { // TODO consider DISCOVER ctx = null ; // can't go up further break ; } ctx = i ; } else { return null ; } } if ( ctx instanceof Item ) return ( Item ) ctx ; // fall back to the classic interpretation return getItemByFullName ( pathName ) ; }
Gets the item by its path name from the given context