// Path: components/hostobjects/org.jaggeryjs.hostobjects.file/src/main/java/org/jaggeryjs/hostobjects/file/JavaScriptFileManager.java
// public interface JavaScriptFileManager {
// 
//     public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException;
// 
//     public File getFile(String path) throws ScriptException;
// 
//     public String getDirectoryPath(String path) throws ScriptException;
// 
// }
// 
// Path: components/hostobjects/org.jaggeryjs.hostobjects.file/src/main/java/org/jaggeryjs/hostobjects/file/JavaScriptFileManagerImpl.java
// public class JavaScriptFileManagerImpl implements JavaScriptFileManager {
// 
//     private static final Log log = LogFactory.getLog(JavaScriptFileManagerImpl.class);
// 
//     @Override
//     public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException {
//         if (object instanceof String) {
//             String uri = (String) object;
//             return new JavaScriptFileImpl(uri, getFile(uri).getAbsolutePath());
//         } else {
//             String msg = "Unsupported parameter to the File constructor : " + object.getClass();
//             log.error(msg);
//             throw new ScriptException(msg);
//         }
//     }
// 
//     @SuppressFBWarnings("PATH_TRAVERSAL_IN")
//     @Override
//     public File getFile(String uri) throws ScriptException {
//         File file;
//         if (uri.startsWith("file://")) {
//             try {
//                 file = FileUtils.toFile(new URL(uri));
//             } catch (MalformedURLException e) {
//                 log.error(e.getMessage(), e);
//                 throw new ScriptException(e);
//             }
//         } else {
//             String oldPath = uri;
//             uri = FilenameUtils.normalizeNoEndSeparator(uri);
//             if (uri == null) {
//                 String msg = "Invalid file URI : " + oldPath;
//                 log.error(msg);
//                 throw new ScriptException(msg);
//             }
//             file = new File(uri);
//         }
// 
//         return file;
//     }
// 
//     @Override
//     public String getDirectoryPath(String path) throws ScriptException {
//         return getFile(path).getAbsolutePath();
//     }
// }
// 
// Path: components/script-engine/org.jaggeryjs.scriptengine/src/main/java/org/jaggeryjs/scriptengine/exceptions/ScriptException.java
// public class ScriptException extends Exception {
// 
//     public ScriptException(String message) {
//         super(message);
//     }
// 
//     public ScriptException(Exception exception) {
//         super(exception);
//     }
// 
//     public ScriptException(String message, Exception exception) {
//         super(message, exception);
//     }
// }


import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jaggeryjs.hostobjects.file.JavaScriptFile;
import org.jaggeryjs.hostobjects.file.JavaScriptFileManager;
import org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl;
import org.jaggeryjs.scriptengine.exceptions.ScriptException;
import javax.servlet.ServletContext;
import java.io.File;
package org.jaggeryjs.jaggery.core.plugins;



public class WebAppFileManager implements JavaScriptFileManager {

    private static final Log log = LogFactory.getLog(WebAppFileManager.class);

    private ServletContext context;
    private static final String FILE_PATH = "file://";

    public WebAppFileManager(ServletContext context) throws ScriptException {
        this.context = context;
    }

    @Override
    public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException {
        if (object instanceof String) {
            String path = (String) object;
            if (path.startsWith(FILE_PATH)) {
// Path: components/hostobjects/org.jaggeryjs.hostobjects.file/src/main/java/org/jaggeryjs/hostobjects/file/JavaScriptFileManager.java
// public interface JavaScriptFileManager {
// 
//     public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException;
// 
//     public File getFile(String path) throws ScriptException;
// 
//     public String getDirectoryPath(String path) throws ScriptException;
// 
// }
// 
// Path: components/hostobjects/org.jaggeryjs.hostobjects.file/src/main/java/org/jaggeryjs/hostobjects/file/JavaScriptFileManagerImpl.java
// public class JavaScriptFileManagerImpl implements JavaScriptFileManager {
// 
//     private static final Log log = LogFactory.getLog(JavaScriptFileManagerImpl.class);
// 
//     @Override
//     public JavaScriptFile getJavaScriptFile(Object object) throws ScriptException {
//         if (object instanceof String) {
//             String uri = (String) object;
//             return new JavaScriptFileImpl(uri, getFile(uri).getAbsolutePath());
//         } else {
//             String msg = "Unsupported parameter to the File constructor : " + object.getClass();
//             log.error(msg);
//             throw new ScriptException(msg);
//         }
//     }
// 
//     @SuppressFBWarnings("PATH_TRAVERSAL_IN")
//     @Override
//     public File getFile(String uri) throws ScriptException {
//         File file;
//         if (uri.startsWith("file://")) {
//             try {
//                 file = FileUtils.toFile(new URL(uri));
//             } catch (MalformedURLException e) {
//                 log.error(e.getMessage(), e);
//                 throw new ScriptException(e);
//             }
//         } else {
//             String oldPath = uri;
//             uri = FilenameUtils.normalizeNoEndSeparator(uri);
//             if (uri == null) {
//                 String msg = "Invalid file URI : " + oldPath;
//                 log.error(msg);
//                 throw new ScriptException(msg);
//             }
//             file = new File(uri);
//         }
// 
//         return file;
//     }
// 
//     @Override
//     public String getDirectoryPath(String path) throws ScriptException {
//         return getFile(path).getAbsolutePath();
//     }
// }
// 
// Path: components/script-engine/org.jaggeryjs.scriptengine/src/main/java/org/jaggeryjs/scriptengine/exceptions/ScriptException.java
// public class ScriptException extends Exception {
// 
//     public ScriptException(String message) {
//         super(message);
//     }
// 
//     public ScriptException(Exception exception) {
//         super(exception);
//     }
// 
//     public ScriptException(String message, Exception exception) {
//         super(message, exception);
//     }
// }


// Path: components/jaggery-core/org.jaggeryjs.jaggery.core/src/main/java/org/jaggeryjs/jaggery/core/plugins/WebAppFileManager.java
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jaggeryjs.hostobjects.file.JavaScriptFile;
import org.jaggeryjs.hostobjects.file.JavaScriptFileManager;
import org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl;
import org.jaggeryjs.scriptengine.exceptions.ScriptException;
import javax.servlet.ServletContext;
import java.io.File;

package org.jaggeryjs.jaggery.core.plugins;



public class WebAppFileManager implements JavaScriptFileManager {

    private static final Log log = LogFactory.getLog(WebAppFileManager.class);

    private ServletContext context;
    private static final String FILE_PATH = "file://";

    public WebAppFileManager(ServletContext context) throws ScriptException {
        this.context = context;
    }

    @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);