Examples of RhinoEngine


Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

            //Initialize the Rhino context
            RhinoEngine.enterGlobalContext();
      final FileInputStream fstream = new FileInputStream(fileURL);
           
      final RhinoEngine engine = CommandLineManager.getCommandLineEngine();
      final ScriptableObject scope = engine.getRuntimeScope();
         
          //initialize JaggeryContext
      final JaggeryContext jaggeryContext = new JaggeryContext();
          jaggeryContext.setTenantId("0");
          jaggeryContext.setEngine(engine);
          jaggeryContext.setScope(scope);
            jaggeryContext.addProperty(CommonManager.JAGGERY_OUTPUT_STREAM, System.out);
         
          RhinoEngine.putContextProperty("jaggeryContext", jaggeryContext);

            //Parsing the script
          final Reader source = new ScriptReader(new BufferedInputStream(fstream));
            out.println("\n");
            ShellUtilityService.initializeUtilityServices();
            engine.exec(source, scope, null);
            ShellUtilityService.destroyUtilityServices();
            out.flush();
            out.println("\n");
    }catch (Exception e){
      out.println("\n");
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

        try{

          //Initialize the Rhino context
            RhinoEngine.enterGlobalContext();

            final RhinoEngine engine = CommandLineManager.getCommandLineEngine();
            final ScriptableObject scope = engine.getRuntimeScope();
         
          //initialize JaggeryContext
            final JaggeryContext jaggeryContext = new JaggeryContext();
          jaggeryContext.setTenantId("0");
          jaggeryContext.setEngine(engine);
          jaggeryContext.setScope(scope);
            jaggeryContext.addProperty(CommonManager.JAGGERY_OUTPUT_STREAM, out);
         
          RhinoEngine.putContextProperty("jaggeryContext", jaggeryContext);

          //Parsing the script
          ShellUtilityService.initializeUtilityServices();
            engine.exec(new StringReader(expression), scope, null);
            ShellUtilityService.destroyUtilityServices();
            out.flush();
    }catch (Exception e){
      out.println("Error: " + e.getMessage());
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

        if (isIncludeOnce && includedScripts.get(fileURL) != null) {
            return scope;
        }

        ScriptReader source;
        RhinoEngine engine = jaggeryContext.getEngine();
        if (isBuilt) {
            source = new ScriptReader(context.getResourceAsStream(fileURL)) {
                @Override
                protected void build() throws IOException {
                    try {
                        if (isJSON) {
                            sourceReader = new StringReader("(" + HostObjectUtil.streamToString(sourceIn) + ")");
                        } else {
                            sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn));
                        }
                    } catch (ScriptException e) {
                        throw new IOException(e);
                    }
                }
            };
        } else {
            source = new ScriptReader(context.getResourceAsStream(fileURL));
        }

        ScriptCachingContext sctx = new ScriptCachingContext(jaggeryContext.getTenantId(), keys[0], keys[1], keys[2]);
        sctx.setSecurityDomain(new JaggerySecurityDomain(fileURL, context));
        long lastModified = WebAppManager.getScriptLastModified(context, fileURL);
        sctx.setSourceModifiedTime(lastModified);

        includedScripts.put(fileURL, true);
        includesCallstack.push(fileURL);
        if (isJSON) {
            scope = (ScriptableObject) engine.eval(source, scope, sctx);
        } else {
            engine.exec(source, scope, sctx);
        }
        includesCallstack.pop();
        return scope;
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

        return (JaggeryContext) ctx.getAttribute(SHARED_JAGGERY_CONTEXT);
    }

    public static JaggeryContext clonedJaggeryContext(ServletContext context) {
        JaggeryContext shared = sharedJaggeryContext(context);
        RhinoEngine engine = shared.getEngine();
        Scriptable sharedScope = shared.getScope();
        Context cx = Context.getCurrentContext();
        ScriptableObject instanceScope = (ScriptableObject) cx.newObject(sharedScope);
        instanceScope.setPrototype(sharedScope);
        instanceScope.setParentScope(null);
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

    public static void execute(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        InputStream sourceIn;
        Context cx;
        JaggeryContext context;
        RhinoEngine engine = null;
        ServletContext servletContext = request.getServletContext();

        try {
            engine = CommonManager.getInstance().getEngine();
            cx = engine.enterContext();
            String scriptPath = getScriptPath(request);
            OutputStream out = response.getOutputStream();
            context = createJaggeryContext(cx, out, scriptPath, request, response);
            context.addProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER,
                    new WebAppFileManager(request.getServletContext()));

            if (ModuleManager.isModuleRefreshEnabled()) {
                //reload init scripts
                InputStream jaggeryConf = servletContext.getResourceAsStream(JaggeryCoreConstants.JAGGERY_CONF_FILE);
                if (jaggeryConf != null) {
                    StringWriter writer = new StringWriter();
                    IOUtils.copy(jaggeryConf, writer, null);
                    String jsonString = writer.toString();
                    JSONObject conf = (JSONObject) JSONValue.parse(jsonString);
                    JSONArray initScripts = (JSONArray) conf.get(JaggeryCoreConstants.JaggeryConfigParams.INIT_SCRIPTS);
                    if (initScripts != null) {
                        JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(servletContext);
                        ScriptableObject sharedScope = sharedContext.getScope();

                        Object[] scripts = initScripts.toArray();
                        for (Object script : scripts) {
                            if (!(script instanceof String)) {
                                log.error("Invalid value for initScripts in jaggery.conf : " + script);
                                continue;
                            }
                            String path = (String) script;
                            path = path.startsWith("/") ? path : "/" + path;
                            Stack<String> callstack = CommonManager.getCallstack(sharedContext);
                            callstack.push(path);
                            engine.exec(new ScriptReader(servletContext.getResourceAsStream(path)) {
                                @Override
                                protected void build() throws IOException {
                                    try {
                                        sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn));
                                    } catch (ScriptException e) {
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

        JaggeryContext context = CommonManager.getJaggeryContext();
        if (CommonManager.getJaggeryContext() == null) {
            context = WebAppManager.clonedJaggeryContext(ctx);
            CommonManager.setJaggeryContext(context);
        }
        RhinoEngine engine = context.getEngine();
        ScriptableObject clonedScope = context.getScope();

        JavaScriptProperty session = new JavaScriptProperty("session");
        session.setValue(cx.newObject(clonedScope, "Session", new Object[]{httpSessionEvent.getSession()}));
        session.setAttribute(ScriptableObject.READONLY);
        RhinoEngine.defineProperty(clonedScope, session);

        for (Object jsListener : jsListeners) {
            CommonManager.getCallstack(context).push((String) jsListener);
            try {
                ScriptReader sr = new ScriptReader(ctx.getResourceAsStream((String) jsListener)) {
                    @Override
                    protected void build() throws IOException {
                        try {
                            sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn));
                        } catch (ScriptException e) {
                            throw new IOException(e);
                        }
                    }
                };
                engine.exec(sr, clonedScope, null);
            } catch (ScriptException e) {
                log.error(e.getMessage(), e);
            } finally {
                CommonManager.getCallstack(context).pop();
            }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

        JaggeryContext context = CommonManager.getJaggeryContext();
        if (CommonManager.getJaggeryContext() == null) {
            context = WebAppManager.clonedJaggeryContext(ctx);
            CommonManager.setJaggeryContext(context);
        }
        RhinoEngine engine = context.getEngine();
        ScriptableObject clonedScope = context.getScope();

        JavaScriptProperty session = new JavaScriptProperty("session");
        session.setValue(cx.newObject(clonedScope, "Session", new Object[]{httpSessionEvent.getSession()}));
        session.setAttribute(ScriptableObject.READONLY);
        RhinoEngine.defineProperty(clonedScope, session);

        for (Object jsListener : jsListeners) {
            CommonManager.getCallstack(context).push((String) jsListener);
            try {
                ScriptReader sr = new ScriptReader(ctx.getResourceAsStream((String) jsListener)) {
                    @Override
                    protected void build() throws IOException {
                        try {
                            sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn));
                        } catch (ScriptException e) {
                            throw new IOException(e);
                        }
                    }
                };
                engine.exec(sr, clonedScope, null);
            } catch (ScriptException e) {
                log.error(e.getMessage(), e);
            } finally {
                CommonManager.getCallstack(context).pop();
            }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

    private static void addSessionCreatedListners(Context context, JSONArray arr) {
        if (arr != null) {
            try {
                JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(context.getServletContext());
                CommonManager.setJaggeryContext(sharedContext);
                RhinoEngine engine = sharedContext.getEngine();
                org.mozilla.javascript.Context cx = engine.enterContext();
                ServletContext servletContext = (ServletContext) sharedContext.getProperty(
                        org.jaggeryjs.hostobjects.web.Constants.SERVLET_CONTEXT);

                List<String> jsListeners = new ArrayList<String>();
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

    private static void addSessionDestroyedListners(Context context, JSONArray arr) {
        if (arr != null) {
            try {
                JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(context.getServletContext());
                CommonManager.setJaggeryContext(sharedContext);
                RhinoEngine engine = sharedContext.getEngine();
                org.mozilla.javascript.Context cx = engine.enterContext();
                ServletContext servletContext = (ServletContext) sharedContext.getProperty(
                        org.jaggeryjs.hostobjects.web.Constants.SERVLET_CONTEXT);

                List<String> jsListeners = new ArrayList<String>();
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.RhinoEngine

    private static void executeScripts(Context context, JSONArray arr) {
        if (arr != null) {
            try {
                JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(context.getServletContext());
                CommonManager.setJaggeryContext(sharedContext);
                RhinoEngine engine = sharedContext.getEngine();
                org.mozilla.javascript.Context cx = engine.enterContext();
                ServletContext servletContext = (ServletContext) sharedContext.getProperty(
                        org.jaggeryjs.hostobjects.web.Constants.SERVLET_CONTEXT);
                ScriptableObject sharedScope = sharedContext.getScope();

                Object[] scripts = arr.toArray();
                for (Object script : scripts) {
                    if (!(script instanceof String)) {
                        log.error("Invalid value for initScripts/destroyScripts in jaggery.conf : " + script);
                        continue;
                    }
                    String path = (String) script;
                    path = path.startsWith("/") ? path : "/" + path;
                    Stack<String> callstack = CommonManager.getCallstack(sharedContext);
                    callstack.push(path);
                    String[] parts = WebAppManager.getKeys(servletContext.getContextPath(), path, path);
                    ScriptCachingContext sctx = new ScriptCachingContext(sharedContext.getTenantId(),
                            parts[0], parts[1], parts[2]);
                    sctx.setSecurityDomain(new JaggerySecurityDomain(path, servletContext));
                    engine.exec(new ScriptReader(servletContext.getResourceAsStream(path)) {
                        @Override
                        protected void build() throws IOException {
                            try {
                                sourceReader = new StringReader(HostObjectUtil.streamToString(sourceIn));
                            } catch (ScriptException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.