Added README file
[metux-java.git] / util / VFile.java
blob823c696706b594899d7922bf5ac9b579895b1314
2 package org.de.metux.util;
4 import java.io.File;
6 /*
7 states which the file can have:
9 + VFile current_root -> beyond which root are we working ?
10 + boolean allow_breakout -> are we allowed to break out of the root ?
16 public class VFile
18 String root;
19 String workdir;
20 String filename;
22 public static String normalize_filename(String name)
24 boolean absolute = name.startsWith("/");
25 boolean dirname = name.endsWith("/");
27 String splitted[] = name.split("\\/");
28 String newstr[] = new String[splitted.length];
30 int y=0;
31 for (int x=0; x<splitted.length; x++)
33 String e = splitted[x];
34 if ((e==null)||(e.equals("")||e.equals("."))) ;
35 else if (e.equals(".."))
37 if (y>0)
38 y--;
39 else
40 newstr[y++] = "..";
42 else
43 newstr[y++] = e;
46 if (y==0)
47 return ((absolute||dirname) ? "/" : "");
49 String str = (absolute ? "/" : "")+newstr[0];
50 for (int x=1; x<y; x++)
51 str += "/"+newstr[x];
53 if (dirname)
54 str += "/";
56 return str;