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);
}
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);
}
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;
}
Aggregations