Java 类org.mozilla.javascript.tools.SourceReader 实例源码

项目:whackpad    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true, 
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:code404    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:code404    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:S3F    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:S3F    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:rhino-jscover    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:rhino-jscover    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:astor    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:astor    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:Rhino-Prov-Mod    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:Rhino-Prov-Mod    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:closure-compiler-old    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:closure-compiler-old    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:closure-compiler-copy    文件:Main.java   
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
项目:closure-compiler-copy    文件:Main.java   
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
项目:whackpad    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
{
    try {
        return SourceReader.readFileOrUrl(path, convertToString, 
                shellContextFactory.getCharacterEncoding());
    } catch (IOException ex) {
        Context.reportError(ToolErrorReporter.getMessage(
                "msg.couldnt.read.source", path, ex.getMessage()));
        return null;
    }
}
项目:rhino-android    文件:Test262SuiteTest.java   
@Parameters(name = "js={0}, opt={3}, strict={4}")
public static Collection<Object[]> test262SuiteValues() throws IOException {
    List<Object[]> result = new ArrayList<Object[]>();
    List<File> tests = getTestFiles();
    for (File jsTest : tests) {
        String jsFileStr = (String) SourceReader.readFileOrUrl(jsTest.getPath(), true, "UTF-8");
        List<String> harnessFiles = new ArrayList<String>();
        harnessFiles.add("sta.js");
        harnessFiles.add("assert.js");

        Map header = (Map) YAML.load(jsFileStr.substring(jsFileStr.indexOf("/*---") + 5, jsFileStr.lastIndexOf("---*/")));
        if (header.containsKey("includes")) {
            harnessFiles.addAll((Collection)header.get("includes"));
        }

        EcmaErrorType errorType = EcmaErrorType._valueOf((String)header.get("negative"));
        List<String> flags = header.containsKey("flags") ? (List<String>) header.get("flags") : Collections.EMPTY_LIST;
        for (int optLevel : OPT_LEVELS) {
            if (!flags.contains("onlyStrict")) {
                result.add(new Object[]{jsTest.getPath(), jsFileStr, harnessFiles, optLevel, false, errorType});
            }
            if (!flags.contains("noStrict")) {
                result.add(new Object[]{jsTest.getPath(), jsFileStr, harnessFiles, optLevel, true, errorType});
            }
        }
    }
    return result;
}
项目:code404    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:S3F    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:rhino-jscover    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:astor    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:Rhino-Prov-Mod    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:closure-compiler-old    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:closure-compiler-copy    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 *
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException {
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
项目:Auto.js    文件:Main.java   
/**
 * Read file or url specified by <tt>path</tt>.
 *
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException {
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}