当前位置: 首页>>代码示例>>Java>>正文


Java Scriptable类代码示例

本文整理汇总了Java中org.mozilla.javascript.Scriptable的典型用法代码示例。如果您正苦于以下问题:Java Scriptable类的具体用法?Java Scriptable怎么用?Java Scriptable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Scriptable类属于org.mozilla.javascript包,在下文中一共展示了Scriptable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomContextFactory

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
public void testCustomContextFactory() {
    ContextFactory factory = new MyFactory();
    Context cx = factory.enterContext();
    try {
        Scriptable globalScope = cx.initStandardObjects();
        // Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
        /* TODO(stevey): fix this functionality in parser
        Object result = cx.evaluateString(globalScope,
                "var obj = {};" +
                "function obj.foo() { return 'bar'; }" +
                "obj.foo();",
                "test source", 1, null);
        assertEquals("bar", result);
        */
    } catch (RhinoException e) {
        fail(e.toString());
    } finally {
        Context.exit();
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:21,代码来源:ContextFactoryTest.java

示例2: init

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
public static void init(Context cx, Scriptable scope, boolean sealed)
{

    NativeRegExp proto = new NativeRegExp();
    proto.re = (RECompiled)compileRE(cx, "", null, false);
    proto.activatePrototypeMap(MAX_PROTOTYPE_ID);
    proto.setParentScope(scope);
    proto.setPrototype(getObjectPrototype(scope));

    NativeRegExpCtor ctor = new NativeRegExpCtor();
    // Bug #324006: ECMA-262 15.10.6.1 says "The initial value of
    // RegExp.prototype.constructor is the builtin RegExp constructor." 
    proto.defineProperty("constructor", ctor, ScriptableObject.DONTENUM);

    ScriptRuntime.setFunctionProtoAndParent(ctor, scope);

    ctor.setImmunePrototypeProperty(proto);

    if (sealed) {
        proto.sealObject();
        ctor.sealObject();
    }

    defineProperty(scope, "RegExp", ctor, ScriptableObject.DONTENUM);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:26,代码来源:NativeRegExp.java

示例3: processFileNoThrow

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) {
    try {
        processFile(cx, scope, filename);
    } catch (IOException ioex) {
        Context.reportError(ToolErrorReporter.getMessage(
                "msg.couldnt.read.source", filename, ioex.getMessage()));
        exitCode = EXITCODE_FILE_NOT_FOUND;
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:21,代码来源:Main.java

示例4: helper

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
public void helper(String source) {
    Context cx = Context.enter();
    Context.ClassShutterSetter setter = cx.getClassShutterSetter();
    try {
        Scriptable globalScope = cx.initStandardObjects();
        if (setter == null) {
            setter = classShutterSetter;
        } else {
            classShutterSetter = setter;
        }
        setter.setClassShutter(new OpaqueShutter());
        cx.evaluateString(globalScope, source, "test source", 1, null);
    } finally {
        setter.setClassShutter(null);
        Context.exit();
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:18,代码来源:ClassShutterExceptionTest.java

示例5: execute

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
	if (isEnabled()) {
		if (super.execute(javascriptContext, scope)) {
			for (FunctionStatement function : getFunctions()) {
				if (function.getName().equals(functionName)) {
					Scriptable curScope = javascriptContext.initStandardObjects();
					curScope.setParentScope(scope);
					boolean ret = function.execute(javascriptContext, curScope);
					Object returnedValue = function.getReturnedValue();
					if (returnedValue != null) {
						ReturnStatement.returnLoop(this.parent, returnedValue);
					}
					return ret;
				}
			}
		}
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:21,代码来源:CallFunctionStatement.java

示例6: runScript

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例7: stepExecute

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
	if (isEnabled()) {
		if (super.stepExecute(javascriptContext, scope)) {
			DatabaseObject parentStep = this.parent;
			while (parentStep != null) {
				if (parentStep instanceof FunctionStep) {
					FunctionStep functionStep = (FunctionStep)parentStep;
					functionStep.setReturnedValue(this.evaluated);
					functionStep.bContinue = false;
					return true;
				}
				else {
					if (parentStep instanceof StepWithExpressions)
						((StepWithExpressions)parentStep).bContinue = false;
					parentStep = parentStep.getParent();
				}
			}
			sequence.skipNextSteps(true);
			return true;
		}
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:ReturnStep.java

示例8: getActiveWorkflows

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
/**
 * Get active workflow instances this node belongs to
 * 
 * @return the active workflow instances this node belongs to
 */
public Scriptable getActiveWorkflows()
{
    if (this.activeWorkflows == null)
    {
        WorkflowService workflowService = this.services.getWorkflowService();
        
        List<WorkflowInstance> workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true);
        Object[] jsWorkflowInstances = new Object[workflowInstances.size()];
        int index = 0;
        for (WorkflowInstance workflowInstance : workflowInstances)
        {
            jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope);
        }
        this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances);		
    }

    return this.activeWorkflows;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ScriptNode.java

示例9: getFunctionObject

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
private static FunctionObject getFunctionObject( Class aClass, String methodName, Scriptable scriptable ) {
    Hashtable functionMap = (Hashtable) _classFunctionMaps.get( aClass );
    if (functionMap == null) {
        _classFunctionMaps.put( aClass, functionMap = new Hashtable() );
    }

    Object result = functionMap.get( methodName );
    if (result == NO_SUCH_PROPERTY) return null;
    if (result != null) return (FunctionObject) result;

    Method[] methods = aClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getName().equalsIgnoreCase( methodName )) {
            FunctionObject function = new FunctionObject( methodName, method, scriptable );
            functionMap.put( methodName, function );
            return function;
        }
    }
    functionMap.put( methodName, NO_SUCH_PROPERTY );
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ScriptingSupport.java

示例10: migrateSourceXpathFor620

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
public String migrateSourceXpathFor620(String xpath) {
	Context javascriptContext = null;
	Scriptable scope = null;
	try {
		javascriptContext = org.mozilla.javascript.Context.enter();
		scope = javascriptContext.initStandardObjects();
		String filePath = evaluateDataFileName(javascriptContext, scope);
		xpath = migrateSourceXpathFor620(filePath, xpath);
		if (xpath.startsWith("/")) {
			xpath = xpath.replaceFirst("/", "./");
		}
	}
	catch (Exception e) {}
	finally {
		org.mozilla.javascript.Context.exit();
		javascriptContext = null;
		scope = null;
	}
	return xpath;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:21,代码来源:ReadFileStep.java

示例11: createTest

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
private static Test createTest(final File testDir, final String name) {
    return new TestCase(name) {
        @Override
        public int countTestCases() {
            return 1;
        }
        @Override
        public void runBare() throws Throwable {
            final Context cx = Context.enter();
            try {
                cx.setOptimizationLevel(-1);
                final Scriptable scope = cx.initStandardObjects();
                ScriptableObject.putProperty(scope, "print", new Print(scope));
                createRequire(testDir, cx, scope).requireMain(cx, "program");
            }
            finally {
                Context.exit();
            }
        }
    };
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:22,代码来源:ComplianceTest.java

示例12: ScriptUser

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
/**
 * Constructs a scriptable object representing a user.
 * 
 * @param userName The username
 * @param personNodeRef The NodeRef
 * @param serviceRegistry A ServiceRegistry instance
 * @param scope Script scope
 * @since 4.0
 */
public ScriptUser(String userName, NodeRef personNodeRef, ServiceRegistry serviceRegistry, Scriptable scope)
{
   this.serviceRegistry = serviceRegistry;
   this.authorityService = serviceRegistry.getAuthorityService();
   this.personService = serviceRegistry.getPersonService();
   this.scope = scope;
   this.personNodeRef = personNodeRef == null ? personService.getPerson(userName) : personNodeRef;
   this.userName = userName;
   
   this.shortName = authorityService.getShortName(userName);
   NodeService nodeService = serviceRegistry.getNodeService();
   String firstName = (String)nodeService.getProperty(this.personNodeRef, ContentModel.PROP_FIRSTNAME);
   String lastName = (String)nodeService.getProperty(this.personNodeRef, ContentModel.PROP_LASTNAME);
   this.displayName = this.fullName = (firstName != null ? firstName : "") + (lastName != null ? (' ' + lastName) : "");
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:ScriptUser.java

示例13: listInvitations

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
/**
   * List the open invitations for this web site.
   * props specifies optional properties to be searched.
   * 
   * @param props inviteeUserName
   *
   * @return the invitations
   */
  public ScriptInvitation<?>[] listInvitations(Scriptable props)
  {
  	InvitationSearchCriteriaImpl crit = new InvitationSearchCriteriaImpl();
  	crit.setResourceName(getShortName());
  	crit.setResourceType(Invitation.ResourceType.WEB_SITE);
  	
  	if (props.has("inviteeUserName", props))
  	{
  		crit.setInvitee((String)props.get("inviteeUserName", props));
    	}
  	if (props.has("invitationType", props))
  	{
  		String invitationType = (String)props.get("invitationType", props);
  		crit.setInvitationType(InvitationType.valueOf(invitationType));
      }

  	List<Invitation> invitations = invitationService.searchInvitation(crit);
  	ScriptInvitation<?>[] ret = new ScriptInvitation[invitations.size()];
      int i = 0;
for(Invitation item : invitations)
{
	ret[i++] = scriptInvitationFactory.toScriptInvitation(item);
}
  	return ret;
  }
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:34,代码来源:Site.java

示例14: convertValueForScript

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
@Override
public Serializable convertValueForScript(ServiceRegistry serviceRegistry, Scriptable theScope, QName qname, Serializable value)
{
    // ALF-14863: If script-node is used outside of Script-call (eg. Activiti evaluating an expression that contains variables of type ScriptNode)
    // a scope should be created solely for this conversion. The scope will ALWAYS be set when value-conversion is called from the
    // ScriptProcessor
    ensureScopePresent();
    if (theScope == null)
    {
        theScope = scope;
    }

    if (value instanceof NodeRef)
    {
        return new ActivitiScriptNode(((NodeRef)value), serviceRegistry);
    }
    else if (value instanceof Date)
    {
        return value;
    }
    else
    {
        return super.convertValueForScript(serviceRegistry, theScope, qname, value);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:ActivitiScriptNode.java

示例15: JscriptWorkflowNode

import org.mozilla.javascript.Scriptable; //导入依赖的package包/类
/**
 * Constructor to create a new instance of this class from an 
 * existing instance of WorkflowNode from the CMR workflow 
 * object model
 * 
 * @param workflowNode CMR workflow node object to create 
 * 		new <code>JscriptWorkflowNode</code> from
 * @param scope root scripting scope for this newly instantiated object
 * @param serviceRegistry service registry object
 */
public JscriptWorkflowNode(WorkflowNode workflowNode, Scriptable scope, ServiceRegistry serviceRegistry)
{
	this.name = workflowNode.name;
	this.title = workflowNode.title;
	this.description = workflowNode.description;
	this.isTaskNode = workflowNode.isTaskNode;
	this.transitions = new ArrayList<JscriptWorkflowTransition>();
	WorkflowTransition[] cmrWorkflowTransitions = workflowNode.transitions;
	for (WorkflowTransition cmrWorkflowTransition : cmrWorkflowTransitions)
	{
		transitions.add(new JscriptWorkflowTransition(cmrWorkflowTransition));
	}
	this.scope = scope;
	this.serviceRegistry = serviceRegistry;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:JscriptWorkflowNode.java


注:本文中的org.mozilla.javascript.Scriptable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。