public static String mergePath(String current,String realPath) throws MalformedURLException {
  String currDir;
  if (current == null || current.indexOf('/') == -1)   currDir="/";
 else   if (current.endsWith("/"))   currDir=current;
 else   currDir=current.substring(0,current.lastIndexOf('/') + 1);
  String path;
  if (realPath.startsWith("./"))   path=currDir + realPath.substring(2);
 else   if (realPath.startsWith("/"))   path=realPath;
 else   if (!realPath.startsWith("../"))   path=currDir + realPath;
 else {
    while (realPath.startsWith("../") || currDir.length() == 0) {
      realPath=realPath.substring(3);
      currDir=currDir.substring(0,currDir.length() - 1);
      int index=currDir.lastIndexOf('/');
      if (index == -1)       throw new MalformedURLException("invalid realpath definition for URL");
      currDir=currDir.substring(0,index + 1);
    }
    path=currDir + realPath;
  }
  return path;
}

public static String mergePath ( String current , String realPath ) throws MalformedURLException { String currDir ; if ( current == null || current . indexOf ( '/' ) == - 1 ) currDir = "/" ; else if ( current . endsWith ( "/" ) ) currDir = current ; else currDir = current . substring ( 0 , current . lastIndexOf ( '/' ) + 1 ) ; String path ; if ( realPath . startsWith ( "./" ) ) path = currDir + realPath . substring ( 2 ) ; else if ( realPath . startsWith ( "/" ) ) path = realPath ; else if ( ! realPath . startsWith ( "../" ) ) path = currDir + realPath ; else { while ( realPath . startsWith ( "../" ) || currDir . length ( ) == 0 ) { realPath = realPath . substring ( 3 ) ; currDir = currDir . substring ( 0 , currDir . length ( ) - 1 ) ; int index = currDir . lastIndexOf ( '/' ) ; if ( index == - 1 ) throw new MalformedURLException ( "invalid realpath definition for URL" ) ; currDir = currDir . substring ( 0 , index + 1 ) ; } path = currDir + realPath ; } return path ; }
merge to pathes to one
