Hi,

I'm trying to use a javascript from a java application using the rhino
engine provided by Java 6

The script to use is downloadable in this project :
http://code.google.com/p/google-code-prettify/
This script is designed for prettify source code.

I create a ScriptEngine like this:

public static ScriptEngine createGooglePrettifyEngine() {
        ScriptEngineManager scriptMgr = new ScriptEngineManager();
        ScriptEngine        jsEngine  =
scriptMgr.getEngineByName("JavaScript");
        InputStream is =
Prettifier.class.getResourceAsStream("prettify/prettify.js");
        try {
            Reader reader = new InputStreamReader(is);
            jsEngine.eval(reader);

            return jsEngine;
        } catch (ScriptException ex) {
            ex.printStackTrace();
        }
        return null;

    }


And i execute the script like this:

  public static String prettify(String src) {
        try {
            Invocable      prettifier =
(Invocable)createGooglePrettifyEngine();

            return "<html><header><link href=\"prettify/prettify.css\"
media=\"all\" type=\"text/css\" rel=\"stylesheet\"/></header><body>" +
 
(String)prettifier.invokeFunction("prettyPrintOne" , src , null) +
                   "</body></html>";
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }

When i call "prettyPrintOne" from an html page directly from a
browser, all works fine but when i call from my java application with
the invokeFunction, the result is not the same and don't return the
expected result.

I'm not sure if this group is the right place for this problem, but i
take the chance :P

Best regards,
ANDRE Sébastien.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to