Skip to content
Snippets Groups Projects
Commit 0411e5da authored by vforchi's avatar vforchi
Browse files

simplified resolution of file paths

parent 8b2d8575
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,6 @@ import java.io.File; ...@@ -45,7 +45,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.*; import java.util.*;
import static tap.config.TAPConfiguration.*; import static tap.config.TAPConfiguration.*;
...@@ -258,38 +257,27 @@ public final class ConfigurableServiceConnection implements ServiceConnection { ...@@ -258,38 +257,27 @@ public final class ConfigurableServiceConnection implements ServiceConnection {
/** /**
* <p>Resolve the given file name/path.</p> * <p>Resolve the given file name/path.</p>
* *
* <p>Only the URI protocol "file:" is allowed. If the protocol is different a {@link TAPException} is thrown.</p>
*
* <p> * <p>
* If not an absolute URI, the given path may be either relative or absolute. A relative path is always considered * If not an absolute path, the given path may be either relative or absolute. A relative path is always considered
* as relative from the Web Application directory (supposed to be given in 2nd parameter). * as relative from the Web Application directory (supposed to be given in 2nd parameter).
* </p> * </p>
* *
* @param filePath URI/Path/Name of the file to get. * @param filePath Path/Name of the file to get.
* @param webAppRootPath Web Application directory local path. * @param webAppRootPath Web Application directory local path.
* @param propertyName Name of the property which gives the given file path. * @param propertyName Name of the property which gives the given file path.
* *
* @return The specified File instance. * @return The specified File instance.
* *
* @throws TAPException If the given URI is malformed or if the used URI scheme is different from "file:".
*/ */
protected static final File getFile(final String filePath, final String webAppRootPath, final String propertyName) throws TAPException{ protected static final File getFile(final String filePath, final String webAppRootPath, final String propertyName) {
if (filePath == null) if (filePath == null)
return null; return null;
URI uri = new File(filePath).toURI(); File f = new File(filePath);
if (uri.isAbsolute()){ if (f.isAbsolute())
if (uri.getScheme().equalsIgnoreCase("file")) return f;
return new File(uri); else
else return new File(webAppRootPath, filePath);
throw new TAPException("Incorrect file URI for the property \"" + propertyName + "\": \"" + filePath + "\"! Only URI with the protocol \"file:\" are allowed.");
}else{
File f = new File(filePath);
if (f.isAbsolute())
return f;
else
return new File(webAppRootPath, filePath);
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment