[Arakhnę-Dev] [337] * FileSystem: enable to convert a "resource" URL to a local File. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 337
Author: galland
Date: 2012-05-14 19:12:23 +0200 (Mon, 14 May 2012)
Log Message:
-----------
* FileSystem: enable to convert a "resource" URL to a local File.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2012-05-14 17:10:14 UTC (rev 336)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2012-05-14 17:12:23 UTC (rev 337)
@@ -1548,19 +1548,24 @@
return convertURLToFile(url);
}
- /** Convert an URL which represents a local file into a File.
+ /** Convert an URL which represents a local file or a resource into a File.
*
* @param url is the URL to convert.
* @return the file.
* @throws IllegalArgumentException is the URL was malformed.
*/
public static File convertURLToFile(URL url) {
- if (url==null) return null;
+ URL theUrl = url;
+ if (theUrl==null) return null;
+ if (URISchemeType.RESOURCE.isURL(theUrl)) {
+ theUrl = Resources.getResource(decodeHTMLEntities(theUrl.getFile()));
+ if (theUrl==null) theUrl = url;
+ }
URI uri;
try {
// this is the step that can fail, and so
// it should be this step that should be fixed
- uri = url.toURI();
+ uri = theUrl.toURI();
}
catch (URISyntaxException e) {
// OK if we are here, then obviously the URL did
@@ -1573,15 +1578,15 @@
// characters, then we have to use the component
// constructors:
try {
- uri = new URI(url.getProtocol(), url.getUserInfo(), url
- .getHost(), url.getPort(),
- decodeHTMLEntities(url.getPath()),
- decodeHTMLEntities(url.getQuery()),
- url.getRef());
+ uri = new URI(theUrl.getProtocol(), theUrl.getUserInfo(), theUrl
+ .getHost(), theUrl.getPort(),
+ decodeHTMLEntities(theUrl.getPath()),
+ decodeHTMLEntities(theUrl.getQuery()),
+ theUrl.getRef());
}
catch (URISyntaxException e1) {
// The URL is broken beyond automatic repair
- throw new IllegalArgumentException("broken URL: " + url); //$NON-NLS-1$
+ throw new IllegalArgumentException("broken URL: " + theUrl); //$NON-NLS-1$
}
}
@@ -1600,7 +1605,7 @@
return new File(decodeHTMLEntities(auth+path));
}
}
- throw new IllegalArgumentException("not a file URL: "+url); //$NON-NLS-1$
+ throw new IllegalArgumentException("not a file URL: "+theUrl); //$NON-NLS-1$
}
/** Convert a string to an URL according to several rules.