Search in sources :

Example 16 with JaggeryContext

use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.

the class WebAppManager method clearTimeout.

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]));
}
Also used : ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

Example 17 with JaggeryContext

use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.

the class WebSocketHostObject method jsConstructor.

public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws Exception {
    int argsCount = args.length;
    if (argsCount != 0) {
        HostObjectUtil.invalidNumberOfArgs(hostObjectName, hostObjectName, argsCount, true);
    }
    WebSocketHostObject who = new WebSocketHostObject();
    who.contextFactory = cx.getFactory();
    JaggeryContext currentContext = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
    JaggeryContext asyncContext = new JaggeryContext();
    asyncContext.setEngine(currentContext.getEngine());
    asyncContext.setScope(currentContext.getScope());
    asyncContext.setTenantDomain(currentContext.getTenantDomain());
    asyncContext.addProperty(Constants.SERVLET_CONTEXT, currentContext.getProperty(Constants.SERVLET_CONTEXT));
    asyncContext.addProperty(LogHostObject.LOG_LEVEL, currentContext.getProperty(LogHostObject.LOG_LEVEL));
    asyncContext.addProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER, currentContext.getProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER));
    asyncContext.addProperty(Constants.JAGGERY_CORE_MANAGER, currentContext.getProperty(Constants.JAGGERY_CORE_MANAGER));
    asyncContext.addProperty(Constants.JAGGERY_INCLUDED_SCRIPTS, new HashMap<String, Boolean>());
    asyncContext.addProperty(Constants.JAGGERY_INCLUDES_CALLSTACK, new Stack<String>());
    asyncContext.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());
    who.asyncContext = asyncContext;
    return who;
}
Also used : JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

Example 18 with JaggeryContext

use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.

the class WebAppManager method setTimeout.

public static String setTimeout(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.setTimeout(cx, thisObj, args, funObj);
    List<String> taskIds = timeouts.get(contextPath);
    if (taskIds == null) {
        taskIds = new ArrayList<String>();
        timeouts.put(contextPath, taskIds);
    }
    taskIds.add(taskId);
    return taskId;
}
Also used : ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

Example 19 with JaggeryContext

use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.

the class JaggeryDeployerManager method addSessionCreatedListners.

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>();
            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);
                jsListeners.add(path);
            }
            servletContext.setAttribute(JaggeryCoreConstants.JS_CREATED_LISTENERS, jsListeners);
        } finally {
            if (org.mozilla.javascript.Context.getCurrentContext() != null) {
                RhinoEngine.exitContext();
            }
        }
    }
}
Also used : ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) JSONObject(org.json.simple.JSONObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) LogHostObject(org.jaggeryjs.hostobjects.log.LogHostObject) RhinoEngine(org.jaggeryjs.scriptengine.engine.RhinoEngine)

Example 20 with JaggeryContext

use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.

the class JaggeryDeployerManager method addSessionDestroyedListners.

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>();
            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);
                jsListeners.add(path);
            }
            servletContext.setAttribute(JaggeryCoreConstants.JS_DESTROYED_LISTENERS, jsListeners);
        } finally {
            if (org.mozilla.javascript.Context.getCurrentContext() != null) {
                RhinoEngine.exitContext();
            }
        }
    }
}
Also used : ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) JSONObject(org.json.simple.JSONObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) LogHostObject(org.jaggeryjs.hostobjects.log.LogHostObject) RhinoEngine(org.jaggeryjs.scriptengine.engine.RhinoEngine)

Aggregations

JaggeryContext (org.jaggeryjs.scriptengine.engine.JaggeryContext)28 ServletContext (javax.servlet.ServletContext)15 ScriptableObject (org.mozilla.javascript.ScriptableObject)10 RhinoEngine (org.jaggeryjs.scriptengine.engine.RhinoEngine)9 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)8 LogHostObject (org.jaggeryjs.hostobjects.log.LogHostObject)5 ScriptReader (org.jaggeryjs.jaggery.core.ScriptReader)5 ScriptCachingContext (org.jaggeryjs.scriptengine.cache.ScriptCachingContext)5 JSONObject (org.json.simple.JSONObject)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 StreamHostObject (org.jaggeryjs.hostobjects.stream.StreamHostObject)3 JavaScriptProperty (org.jaggeryjs.scriptengine.engine.JavaScriptProperty)3 List (java.util.List)2 FileHostObject (org.jaggeryjs.hostobjects.file.FileHostObject)2 WebAppFileManager (org.jaggeryjs.jaggery.core.plugins.WebAppFileManager)2 Context (org.mozilla.javascript.Context)2 Stack (java.util.Stack)1 ZipEntry (java.util.zip.ZipEntry)1