use of org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl in project jaggery by wso2.
the class WebAppFileManager method getFile.
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
@Override
public File getFile(String path) throws ScriptException {
if (path.startsWith(FILE_PATH)) {
return new JavaScriptFileManagerImpl().getFile(path);
}
String oldPath = path;
path = FilenameUtils.normalizeNoEndSeparator(path);
if (path == null) {
String msg = "Invalid file path : " + oldPath;
log.error(msg);
throw new ScriptException(msg);
}
File file = new File(context.getRealPath("/"), path);
if (file.isDirectory()) {
String msg = "File hostobject doesn't handle directories. Specified path contains a directory : " + path;
log.error(msg);
throw new ScriptException(msg);
}
return file;
}
use of org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl in project jaggery by wso2.
the class WebAppFileManager method getJavaScriptFile.
@Override
public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException {
if (object instanceof String) {
String path = (String) object;
if (path.startsWith(FILE_PATH)) {
return new JavaScriptFileManagerImpl().getJavaScriptFile(path);
}
WebAppFile webAppFile = new WebAppFile(path, context);
webAppFile.setFileManager(this);
return webAppFile;
} else if (object instanceof FileItem) {
UploadedFile uploadedFile = new UploadedFile((FileItem) object);
uploadedFile.setFileManager(this);
return uploadedFile;
} else {
String msg = "Unsupported parameter to the File constructor : " + object.getClass();
log.error(msg);
throw new ScriptException(msg);
}
}
use of org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl in project jaggery by wso2.
the class WebAppFileManager method getDirectoryPath.
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
@Override
public String getDirectoryPath(String path) throws ScriptException {
if (path.startsWith(FILE_PATH)) {
return new JavaScriptFileManagerImpl().getFile(path).getAbsolutePath();
}
String oldPath = path;
path = FilenameUtils.normalizeNoEndSeparator(path);
if (path == null) {
String msg = "Invalid file path : " + oldPath;
log.error(msg);
throw new ScriptException(msg);
}
File file = new File(context.getRealPath("/"), path);
return file.getPath();
}
Aggregations