Examples of JaggeryContext


Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        return taskId;
    }

    public static String setInterval(final Context cx, final Scriptable thisObj, Object[] args, Function funObj)
            throws ScriptException {
        JaggeryContext context = CommonManager.getJaggeryContext();
        ServletContext servletContext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
        String contextPath = servletContext.getContextPath();
        String taskId = RhinoTopLevel.setInterval(cx, thisObj, args, funObj);
        List<String> taskIds = intervals.get(contextPath);
        if (taskIds == null) {
            taskIds = new ArrayList<String>();
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        return taskId;
    }

    public static void clearTimeout(final Context cx, final Scriptable thisObj, Object[] args, Function funObj)
            throws ScriptException {
        JaggeryContext context = CommonManager.getJaggeryContext();
        ServletContext servletContext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
        String contextPath = servletContext.getContextPath();
        RhinoTopLevel.clearTimeout(cx, thisObj, args, funObj);
        List<String> taskIds = timeouts.get(contextPath);
        taskIds.remove(String.valueOf(args[0]));
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        taskIds.remove(String.valueOf(args[0]));
    }

    public static void clearInterval(final Context cx, final Scriptable thisObj, Object[] args, Function funObj)
            throws ScriptException {
        JaggeryContext context = CommonManager.getJaggeryContext();
        ServletContext servletContext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
        String contextPath = servletContext.getContextPath();
        RhinoTopLevel.clearTimeout(cx, thisObj, args, funObj);
        List<String> taskIds = intervals.get(contextPath);
        taskIds.remove(String.valueOf(args[0]));
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

            String msg = "Invalid file path for require method : " + moduleId;
            log.error(msg);
            throw new ScriptException(msg);
        }

        JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
        Map<String, ScriptableObject> requiredModules = (Map<String, ScriptableObject>) jaggeryContext.getProperty(
                Constants.JAGGERY_REQUIRED_MODULES);
        ScriptableObject object = requiredModules.get(moduleId);
        if (object != null) {
            return object;
        }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

    public static JaggeryContext sharedJaggeryContext(ServletContext ctx) {
        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);

        JaggeryContext clone = new JaggeryContext();
        clone.setEngine(engine);
        clone.setTenantId(shared.getTenantId());
        clone.setScope(instanceScope);

        clone.addProperty(Constants.SERVLET_CONTEXT, shared.getProperty(Constants.SERVLET_CONTEXT));
        clone.addProperty(LogHostObject.LOG_LEVEL, shared.getProperty(LogHostObject.LOG_LEVEL));
        clone.addProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER,
                shared.getProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER));
        clone.addProperty(Constants.JAGGERY_CORE_MANAGER, shared.getProperty(Constants.JAGGERY_CORE_MANAGER));
        clone.addProperty(Constants.JAGGERY_INCLUDED_SCRIPTS, new HashMap<String, Boolean>());
        clone.addProperty(Constants.JAGGERY_INCLUDES_CALLSTACK, new Stack<String>());
        clone.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());

        return clone;
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        return clone;
    }

    public static void deploy(org.apache.catalina.Context context) throws ScriptException {
        ServletContext ctx = context.getServletContext();
        JaggeryContext sharedContext = new JaggeryContext();
        Context cx = Context.getCurrentContext();
        CommonManager.initContext(sharedContext);

        sharedContext.addProperty(Constants.SERVLET_CONTEXT, ctx);
        sharedContext.addProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER, new WebAppFileManager(ctx));
        sharedContext.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());
        String logLevel = (String) ctx.getAttribute(LogHostObject.LOG_LEVEL);
        if (logLevel != null) {
            sharedContext.addProperty(LogHostObject.LOG_LEVEL, logLevel);
        }
        ScriptableObject sharedScope = sharedContext.getScope();
        JavaScriptProperty application = new JavaScriptProperty("application");
        application.setValue(cx.newObject(sharedScope, "Application", new Object[]{ctx}));
        application.setAttribute(ScriptableObject.READONLY);
        RhinoEngine.defineProperty(sharedScope, application);
        ctx.setAttribute(SHARED_JAGGERY_CONTEXT, sharedContext);
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

    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);
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

    }

    private static JaggeryContext createJaggeryContext(Context cx, OutputStream out, String scriptPath,
                                                       HttpServletRequest request, HttpServletResponse response) {
        ServletContext servletContext = request.getServletContext();
        JaggeryContext context = clonedJaggeryContext(servletContext);
        CommonManager.setJaggeryContext(context);
        context.addProperty(SERVLET_REQUEST, request);
        context.addProperty(SERVLET_RESPONSE, response);
        CommonManager.getCallstack(context).push(scriptPath);
        CommonManager.getIncludes(context).put(scriptPath, true);
        context.addProperty(CommonManager.JAGGERY_OUTPUT_STREAM, out);
        defineProperties(cx, context, context.getScope());
        return context;
    }
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        return context;
    }

    protected static ScriptCachingContext getScriptCachingContext(HttpServletRequest request, String scriptPath)
            throws ScriptException {
        JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
        String tenantId = jaggeryContext.getTenantId();
        String[] parts = getKeys(request.getContextPath(), scriptPath, scriptPath);
        /**
         * tenantId = tenantId
         * context = webapp context
         * path = relative path to the directory of *.js file
View Full Code Here

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext

        } catch (ScriptException e) {
            log.error(e.getMessage(), e);
            throw new ServletException(e);
        }
        WebAppManager.execute(request, response);
        JaggeryContext context = CommonManager.getJaggeryContext();
        Scriptable scope = context.getScope();
        wsMessageInBound = new WSMessageInBound((WebSocketHostObject) scope.get("webSocket", scope));
        RhinoEngine.exitContext();
        super.doGet(request, response);
    }
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.