Package org.jaggeryjs.scriptengine.engine

Examples of org.jaggeryjs.scriptengine.engine.JaggeryContext


        if (argsCount != 1) {
            HostObjectUtil.invalidNumberOfArgs(hostObjectName, hostObjectName, argsCount, true);
        }

        FileHostObject fho = new FileHostObject();
        JaggeryContext context = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
        Object obj = context.getProperty(JAVASCRIPT_FILE_MANAGER);
        if (obj instanceof JavaScriptFileManager) {
            fho.manager = (JavaScriptFileManager) obj;
        } else {
            fho.manager = new JavaScriptFileManagerImpl();
        }
View Full Code Here


        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.setTenantId(currentContext.getTenantId());

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

        int argsCount = args.length;
        if (argsCount != 0) {
            HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
        }
        RequestHostObject rho = (RequestHostObject) thisObj;
        JaggeryContext context = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
        Stack stack = (Stack) context.getProperty(LogHostObject.JAGGERY_INCLUDES_CALLSTACK);
        String path = (String) stack.firstElement();
        if (rho.request.getRequestURI().equals(path)) {
            return null;
        }
        return path;
View Full Code Here

        int argsCount = args.length;
        if (argsCount > 1) {
            HostObjectUtil.invalidNumberOfArgs(HOSTOBJECT_NAME, HOSTOBJECT_NAME, argsCount, true);
        }
        String loggerName;
        JaggeryContext context = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
        if (argsCount == 1 && (args[0] instanceof String)) {
            loggerName = (String) args[0];
        } else {
            String requestString = ((Stack<String>) context.getProperty(JAGGERY_INCLUDES_CALLSTACK)).peek();
            loggerName = ROOT_LOGGER + requestString.replace(".jag", ":jag").replace(".js", ":js").replace("/", ".");
        }
        LogHostObject logObj = new LogHostObject();
        logObj.logger = Logger.getLogger(loggerName);

        String logLevel = (String) context.getProperty(LOG_LEVEL);
        if (LOG_LEVEL_FATAL.equalsIgnoreCase(logLevel)) {
            logObj.logger.setLevel(Level.FATAL);
        } else if (LOG_LEVEL_WARN.equalsIgnoreCase(logLevel)) {
            logObj.logger.setLevel(Level.WARN);
        } else if (LOG_LEVEL_DEBUG.equalsIgnoreCase(logLevel)) {
View Full Code Here

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

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

        }
        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(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, false);
    }
View Full Code Here

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

     * JaggeryMethod responsible of writing to the output stream
     */
    public static void print(Context cx, Scriptable thisObj, Object[] args, Function funObj)
            throws ScriptException {
        if (!isWebSocket) {
            JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();

            //If the script itself havent set the content type we set the default content type to be text/html
            HttpServletResponse servletResponse = (HttpServletResponse) jaggeryContext.getProperty(SERVLET_RESPONSE);

            //servletResponse can be null if the script is executed as a initScripts, destroyScripts or
            //a sessionDestroyedListeners
            if (servletResponse != null) {
                if (servletResponse.getContentType() == null) {
View Full Code Here

        }
    }

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

TOP

Related Classes of org.jaggeryjs.scriptengine.engine.JaggeryContext

Copyright © 2018 www.massapicom. 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.