Revision 34263 trunk/libraries/libIverUtiles/src/org/gvsig/tools/file/PathGenerator.java

View differences:

PathGenerator.java
1 1
package org.gvsig.tools.file;
2 2

  
3 3
import java.io.File;
4
import java.net.MalformedURLException;
4 5
import java.net.URI;
5 6
import java.net.URISyntaxException;
7
import java.net.URL;
6 8
import java.util.regex.Pattern;
7 9

  
8 10
/**
......
32 34
	 * @param pathSeparator separator path of system
33 35
	 * @return the path of file.
34 36
	 */
37
	 public String getURLPath(String targetPath) {
38
		 try {
39
			URL url=new URL(targetPath);
40
			File fileIn = new File(url.toURI());
41
			File file = getFile(getPath(fileIn.getAbsolutePath()));
42
			return file.toURI().toURL().toString();
43
		 } catch (MalformedURLException e) {
44
			e.printStackTrace();
45
		} catch (URISyntaxException e) {
46
			e.printStackTrace();
47
		}
48
		 return targetPath;
49
		 
50
	 }
51
	
52
	/**
53
	 * Return the path relative or absolute depends if the option 
54
	 * isAbsolutePath is true or false. 
55
	 * @param targetPath Absolute path of file
56
	 * @param pathSeparator separator path of system
57
	 * @return the path of file.
58
	 */
35 59
	 public String getPath(String targetPath) {
36 60
		 if (isAbsolutePath || basePath==null){
37 61
			 return targetPath;
......
130 154
	 * @param path relative path.
131 155
	 * @return
132 156
	 */
157
	public String getAbsoluteURLPath(String path){
158
		try {
159
			URL url=new URL(path);
160
			File fileIn=new File(url.toURI());
161
			File file = getFile(getAbsolutePath(fileIn.getAbsolutePath()));
162
			return file.toURI().toURL().toString();
163
		} catch (MalformedURLException e) {
164
			e.printStackTrace();
165
		} catch (URISyntaxException e) {
166
			e.printStackTrace();
167
		}
168
		return path;
169
		
170
	}
171
	
172
	/**
173
	 * Returns absolute path from a relative.
174
	 * @param path relative path.
175
	 * @return
176
	 */
133 177
	public String getAbsolutePath(String path){
134 178
		if (path==null)
135 179
			return null;
......
139 183
		filePath=new File(basePath, path);
140 184
		if (filePath.exists())
141 185
			return filePath.getAbsolutePath();
142
		return null;
186
		return path;
143 187
	}
144 188
	
145 189
	/**

Also available in: Unified diff