Search in sources :

Example 26 with JaggeryContext

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

the class JaggeryWebSocketServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        CommonManager.getInstance().getEngine().enterContext();
    } 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);
}
Also used : ServletException(javax.servlet.ServletException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) WebSocketHostObject(org.jaggeryjs.hostobjects.web.WebSocketHostObject) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) Scriptable(org.mozilla.javascript.Scriptable)

Example 27 with JaggeryContext

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

the class WebAppManager method include_once.

public static void include_once(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
    String functionName = "include_once";
    int argsCount = args.length;
    if (argsCount != 1 && argsCount != 2) {
        HostObjectUtil.invalidNumberOfArgs(CommonManager.HOST_OBJECT_NAME, functionName, argsCount, false);
    }
    if (!(args[0] instanceof String)) {
        HostObjectUtil.invalidArgsError(CommonManager.HOST_OBJECT_NAME, functionName, "1", "string", args[0], false);
    }
    JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
    Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext);
    String parent = includesCallstack.lastElement();
    String fileURL = (String) args[0];
    if (CommonManager.isHTTP(fileURL) || CommonManager.isHTTP(parent)) {
        CommonManager.include_once(cx, thisObj, args, funObj);
        return;
    }
    if (argsCount == 2 && !(args[1] instanceof ScriptableObject)) {
        HostObjectUtil.invalidArgsError(CommonManager.HOST_OBJECT_NAME, functionName, "2", "Object", args[1], false);
    }
    ScriptableObject scope;
    if (argsCount == 2) {
        scope = (ScriptableObject) args[1];
    } else {
        scope = jaggeryContext.getScope();
    }
    executeScript(jaggeryContext, scope, fileURL, false, false, true);
}
Also used : JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

Example 28 with JaggeryContext

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

the class WebAppFile method getFilePath.

private String getFilePath(String fileURL) throws ScriptException {
    JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
    Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext);
    ServletContext context = (ServletContext) jaggeryContext.getProperty(Constants.SERVLET_CONTEXT);
    String parent = includesCallstack.lastElement();
    try {
        String[] keys = WebAppManager.getKeys(context.getContextPath(), parent, fileURL);
        fileURL = "/".equals(keys[1]) ? keys[2] : keys[1] + keys[2];
    } catch (NullPointerException ne) {
        throw new ScriptException("Invalid file path : " + fileURL, ne);
    }
    return fileURL;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

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