protected char[] normalize(final char[] path) throws URIException {
  if (path == null) {
    return null;
  }
  String normalized=new String(path);
  if (normalized.startsWith("./")) {
    normalized=normalized.substring(1);
  }
 else   if (normalized.startsWith("../")) {
    normalized=normalized.substring(2);
  }
 else   if (normalized.startsWith("..")) {
    normalized=normalized.substring(2);
  }
  int index=-1;
  while ((index=normalized.indexOf("/./")) != -1) {
    normalized=normalized.substring(0,index) + normalized.substring(index + 2);
  }
  if (normalized.endsWith("/.")) {
    normalized=normalized.substring(0,normalized.length() - 1);
  }
  int startIndex=0;
  while ((index=normalized.indexOf("/../",startIndex)) != -1) {
    final int slashIndex=normalized.lastIndexOf('/',index - 1);
    if (slashIndex >= 0) {
      normalized=normalized.substring(0,slashIndex) + normalized.substring(index + 3);
    }
 else {
      startIndex=index + 3;
    }
  }
  if (normalized.endsWith("/..")) {
    final int slashIndex=normalized.lastIndexOf('/',normalized.length() - 4);
    if (slashIndex >= 0) {
      normalized=normalized.substring(0,slashIndex + 1);
    }
  }
  while ((index=normalized.indexOf("/../")) != -1) {
    final int slashIndex=normalized.lastIndexOf('/',index - 1);
    if (slashIndex >= 0) {
      break;
    }
 else {
      normalized=normalized.substring(index + 3);
    }
  }
  if (normalized.endsWith("/..")) {
    final int slashIndex=normalized.lastIndexOf('/',normalized.length() - 4);
    if (slashIndex < 0) {
      normalized="/";
    }
  }
  return normalized.toCharArray();
}

protected char [ ] normalize ( final char [ ] path ) throws URIException { if ( path == null ) { return null ; } String normalized = new String ( path ) ; if ( normalized . startsWith ( "./" ) ) { normalized = normalized . substring ( 1 ) ; } else if ( normalized . startsWith ( "../" ) ) { normalized = normalized . substring ( 2 ) ; } else if ( normalized . startsWith ( ".." ) ) { normalized = normalized . substring ( 2 ) ; } int index = - 1 ; while ( ( index = normalized . indexOf ( "/./" ) ) != - 1 ) { normalized = normalized . substring ( 0 , index ) + normalized . substring ( index + 2 ) ; } if ( normalized . endsWith ( "/." ) ) { normalized = normalized . substring ( 0 , normalized . length ( ) - 1 ) ; } int startIndex = 0 ; while ( ( index = normalized . indexOf ( "/../" , startIndex ) ) != - 1 ) { final int slashIndex = normalized . lastIndexOf ( '/' , index - 1 ) ; if ( slashIndex >= 0 ) { normalized = normalized . substring ( 0 , slashIndex ) + normalized . substring ( index + 3 ) ; } else { startIndex = index + 3 ; } } if ( normalized . endsWith ( "/.." ) ) { final int slashIndex = normalized . lastIndexOf ( '/' , normalized . length ( ) - 4 ) ; if ( slashIndex >= 0 ) { normalized = normalized . substring ( 0 , slashIndex + 1 ) ; } } while ( ( index = normalized . indexOf ( "/../" ) ) != - 1 ) { final int slashIndex = normalized . lastIndexOf ( '/' , index - 1 ) ; if ( slashIndex >= 0 ) { break ; } else { normalized = normalized . substring ( index + 3 ) ; } } if ( normalized . endsWith ( "/.." ) ) { final int slashIndex = normalized . lastIndexOf ( '/' , normalized . length ( ) - 4 ) ; if ( slashIndex < 0 ) { normalized = "/" ; } } return normalized . toCharArray ( ) ; }
normalize the given hier path part . < p > algorithm taken from uri reference parser at http : / / www . apache . org / ~ fielding / uri / rev - 2002 / issues . html .
