Search in sources :

Example 1 with JavaScriptFileManagerImpl

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;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JavaScriptFileManagerImpl(org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl) JavaScriptFile(org.jaggeryjs.hostobjects.file.JavaScriptFile) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with JavaScriptFileManagerImpl

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);
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JavaScriptFileManagerImpl(org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl)

Example 3 with JavaScriptFileManagerImpl

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();
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JavaScriptFileManagerImpl(org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl) JavaScriptFile(org.jaggeryjs.hostobjects.file.JavaScriptFile) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

JavaScriptFileManagerImpl (org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl)3 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 File (java.io.File)2 JavaScriptFile (org.jaggeryjs.hostobjects.file.JavaScriptFile)2 FileItem (org.apache.commons.fileupload.FileItem)1