Package org.mozilla.javascript

Examples of org.mozilla.javascript.Script


    public static Script buildScript(Element element) throws IOException {
        String jsText = DomHelper.getElementText(element);
        String sourceName = DomHelper.getSystemIdLocation(element);
       
        Context ctx = Context.enter();
        Script script;
        try {
            script = ctx.compileReader(
                getRootScope(), //scope
                new StringReader(jsText), // in
                sourceName == null ? "<unknown>" : sourceName, // sourceName
View Full Code Here


    public Object jsFunction_load( String filename )
        throws Exception {
        org.mozilla.javascript.Context cx =
            org.mozilla.javascript.Context.getCurrentContext();
        Scriptable scope = getParentScope();
        Script script = interpreter.compileScript( cx,
                                                   environment,
                                                   filename );
        return script.exec( cx, scope );
    }   
View Full Code Here

           
            boolean readOnly = DomHelper.getAttributeAsBoolean(element, "read-only", false);
       

            Element loadElem = DomHelper.getChildElement(element, BindingManager.NAMESPACE, "load-form");
            Script loadScript = JavaScriptHelper.buildScript(loadElem);
           
            Script saveScript;
            if (readOnly) {
                saveScript = null;
            } else {
                Element saveElem = DomHelper.getChildElement(element, BindingManager.NAMESPACE, "save-form");
                saveScript = JavaScriptHelper.buildScript(saveElem);
View Full Code Here

*/
public class JavaScriptWidgetListenerBuilder implements WidgetListenerBuilder {

    public WidgetListener buildListener(Element element, Class listenerClass) throws Exception {
       
        Script script = JavaScriptHelper.buildScript(element);
       
        if (listenerClass == ActionListener.class) {
            return new JavaScriptWidgetListener.JSActionListener(script);
        } else if (listenerClass == ValueChangedListener.class) {
            return new JavaScriptWidgetListener.JSValueChangedListener(script);
View Full Code Here

    public Object jsFunction_load( String filename )
        throws Exception {
        org.mozilla.javascript.Context cx =
            org.mozilla.javascript.Context.getCurrentContext();
        Scriptable scope = getParentScope();
        Script script = interpreter.compileScript( cx,
                                                   environment,
                                                   filename );
        return script.exec( cx, scope );
    }   
View Full Code Here

        else
        {
            // strip off leading slash
            scriptName = scriptName.substring(1);
        }
        Script script = scriptStorage.getScript(scriptName);
        if(script == null)
        {
            throw new FileNotFoundException("script:" + scriptName);
        }
        ++includeLevel;
        try
        {
            String oldScriptDirectory = currentScriptDirectory;
            currentScriptDirectory = getDirectoryForScript(scriptName);
            try
            {
                script.exec(cx, scope);
            }
            finally
            {
                currentScriptDirectory = oldScriptDirectory;
            }
View Full Code Here

            String scriptDirectory = HostObject.getDirectoryForScript(
                    scriptPath);
            hostObject.setCurrentScriptDirectory(scriptDirectory);
            ScriptableObject.defineProperty(scope, SCRIPT_DIR_PROPERTY,
                    scriptDirectory, UNMODIFIABLE);
            final Script script;
            try
            {
                script = scriptStorage.getScript(scriptPath);
            }
            catch(FileNotFoundException e)
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return null;
            }
            if(script == null)
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return null;
            }
            if(flowExecutionInterceptor != null)
            {
                flowExecutionInterceptor.beforeFlowExecution(request,
                        scriptPath, cx, scope);
            }
            try
            {
                if(stateExecutionInterceptor != null)
                {
                    stateExecutionInterceptor.aroundStateExecution(new Script()
                    {
                        public Object exec(Context cx, Scriptable scope)
                        {
                            return cx.executeScriptWithContinuations(script,
                                    scope);
                        }
                    }, cx, scope);
                }
                else
                {
                    cx.executeScriptWithContinuations(script, scope);
                }
            }
            catch(ContinuationPending e)
            {
                newContinuation = (NativeContinuation)e.getContinuation();
            }
            catch(Exception e)
            {
                afterFlowExecution(request, cx, scope, e);
                throw e;
            }
        }
        else
        {
            hostObject.setCurrentScriptDirectory(String.valueOf(
                    ScriptableObject.getProperty(scope, SCRIPT_DIR_PROPERTY)));
            try
            {
                if(stateExecutionInterceptor != null)
                {
                    stateExecutionInterceptor.aroundStateExecution(new Script()
                    {
                        public Object exec(Context cx, Scriptable scope)
                        {
                            return cx.resumeContinuation(continuation, scope,
                                    null);
View Full Code Here

        ContextAction ca = new ContextAction() {
            public Object run(Context cx) {
                try {
                    cx.setOptimizationLevel(-1);
                    // Run the built-in library script
                    Script libraryScript = loadScript(new ClassPathResource(
                            "library.js", ScriptStorage.class), "~library.js");
                    cx.initStandardObjects(library);
                    libraryScript.exec(cx, library);
                    ScriptableObject.defineClass(library, HostObject.class);
                    // Force instantiation of lazily loaded objects
                    for (int i = 0; i < lazilyNames.length; i++) {
                        ScriptableObject.getProperty(library, lazilyNames[i]);
                    }
                   
                    if(libraryScripts != null) {
                        int i = 0;
                        for (Iterator iter = libraryScripts.iterator(); iter.hasNext(); ++i) {
                            Object scriptSpec = iter.next();
                            Script s;
                            String path;
                            if(scriptSpec instanceof String) {
                                path = (String)scriptSpec;
                                s = getScript(path);
                            }
                            else if(scriptSpec instanceof Resource) {
                                Resource r = (Resource)scriptSpec;
                                path = r.getDescription();
                                s = loadScript(r, path);
                            }
                            else if(scriptSpec instanceof Script) {
                                s = (Script)scriptSpec;
                                path = "~libraryScript[" + i + "].js";
                                createFunctionStubs(path, s);
                            }
                            else {
                                throw new IllegalArgumentException(
                                        "libraryScripts[" + i + "] is " +
                                        scriptSpec.getClass().getName());
                            }
                            s.exec(cx, library);
                        }
                    }

                    if(libraryCustomizer != null) {
                        libraryCustomizer.customizeLibrary(cx, library);
View Full Code Here

        final Reader r = new InputStreamReader(in, scriptCharacterEncoding);
        try
        {
            Object securityDomain = securityDomainFactory == null ? null :
                securityDomainFactory.createSecurityDomain(resource);
            Script script = Context.getCurrentContext().compileReader(r,
                    resource.getDescription(), 1, securityDomain);
            createFunctionStubs(path, script);
            return script;
        }
        catch(FileNotFoundException e)
View Full Code Here


  private Object runScript(final String scriptSourceText) {
    return contextFactory.call(new ContextAction() {
      public Object run(Context context) {
        Script script = context.compileString(scriptSourceText, "", 1, null);
        return script.exec(context, global);
      }
    });
  }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Script

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.