private String validatePath ( String path , int line ) throws ParseException { if ( ! path . startsWith ( "/" ) ) { throw new ParseException ( "Path must start with '/'" , line ) ; } boolean openedKey = false ; for ( int i = 0 ; i < path . length ( ) ; i ++ ) { boolean validChar = isValidCharForPath ( path . charAt ( i ) , openedKey ) ; if ( ! validChar ) { throw new ParseException ( path , i ) ; } if ( path . charAt ( i ) == ' ' ) { openedKey = true ; } if ( path . charAt ( i ) == ' ' ) { openedKey = false ; } } return path ; }
Helper method . It validates if the path is valid .