public static java.io.File | getFile(org.apache.avalon.framework.context.Context context, java.lang.String fileURL)Gets the file or directory described by the argument file URL.
if ((context == null) || (fileURL == null)) {
throw new IllegalArgumentException("The getFile method doesn't allow null arguments.");
}
String internalFileURL = fileURL.trim();
if (!(internalFileURL.startsWith(filePrefix))) {
throw new IllegalArgumentException("The fileURL argument to getFile doesn't start with the required file prefix - " + filePrefix);
}
String fileName = fileURL.substring(filePrefixLength);
if (!(fileName.startsWith("/"))) {
String baseDirectory = "";
try {
File applicationHome =
(File)context.get(AvalonContextConstants.APPLICATION_HOME);
baseDirectory = applicationHome.toString();
} catch (ContextException ce) {
throw new ContextException("Encountered exception when resolving application home in Avalon context.", ce);
} catch (ClassCastException cce) {
throw new ContextException("Application home object stored in Avalon context was not of type java.io.File.", cce);
}
StringBuffer fileNameBuffer =
new StringBuffer(128)
.append(baseDirectory)
.append(File.separator)
.append(fileName);
fileName = fileNameBuffer.toString();
}
try {
File returnValue = (new File(fileName)).getCanonicalFile();
return returnValue;
} catch (IOException ioe) {
throw new ContextException("Encountered an unexpected exception while retrieving file.", ioe);
}
|