org.mozilla.javascript.tools.SourceReader Java Examples

The following examples show how to use org.mozilla.javascript.tools.SourceReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: Main.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: Main.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #4
Source File: Test262SuiteTest.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: Main.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
}