本文整理匯總了Java中org.mozilla.javascript.Scriptable類的典型用法代碼示例。如果您正苦於以下問題:Java Scriptable類的具體用法?Java Scriptable怎麽用?Java Scriptable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Scriptable類屬於org.mozilla.javascript包,在下文中一共展示了Scriptable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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) : "");
}
示例2: 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();
}
}
示例3: 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);
}
示例4: 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;
}
}
示例5: 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();
}
}
示例6: 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;
}
示例7: 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();
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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();
}
}
};
}
示例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;
}
示例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);
}
}
示例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;
}