本文整理汇总了Java中org.mozilla.javascript.Scriptable.get方法的典型用法代码示例。如果您正苦于以下问题:Java Scriptable.get方法的具体用法?Java Scriptable.get怎么用?Java Scriptable.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.Scriptable
的用法示例。
在下文中一共展示了Scriptable.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toMap
import org.mozilla.javascript.Scriptable; //导入方法依赖的package包/类
public static Map<String, Object> toMap(Scriptable obj) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (Object id : obj.getIds()) {
String key;
Object value;
if (id instanceof String) {
key = (String) id;
value = obj.get(key, obj);
} else if (id instanceof Integer) {
key = id.toString();
value = obj.get((Integer) id, obj);
} else {
throw new IllegalArgumentException(String.format("Unexpected key type: %s (value: %s)", id.getClass().getName(), id));
}
map.put(key, toJavaValue(value));
}
return map;
}
示例2: 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;
}
示例3: stepExecute
import org.mozilla.javascript.Scriptable; //导入方法依赖的package包/类
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
variables.clear();
if (isEnabled()) {
for (RequestableVariable var : getParentSequence().getAllVariables()) {
try {
//evaluate(javascriptContext, scope, var.getName(), "expression", true);
evaluated = scope.get(var.getName(), scope);
if (evaluated != null && !(evaluated instanceof Undefined)) {
if (evaluated instanceof NativeJavaObject) {
evaluated = ((NativeJavaObject) evaluated).unwrap();
}
variables.put(var.getName(), evaluated);
}
} catch (Exception e) {
evaluated = null;
Engine.logBeans.warn(e.getMessage());
}
}
return super.stepExecute(javascriptContext, scope);
}
return false;
}
示例4: stepExecute
import org.mozilla.javascript.Scriptable; //导入方法依赖的package包/类
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
if (isEnabled()) {
if (super.stepExecute(javascriptContext, scope)) {
String variableName = getVariableName();
NodeList list = (NodeList) scope.get(variableName, scope);
Object string = null;
if (list.getLength() > 0) {
Node node = list.item(0);
if (node instanceof Element) {
Element element = (Element) node;
string = element.getTextContent();
} else {
string = node.getNodeValue();
}
}
scope.put(variableName, scope, string);
return true;
}
}
return false;
}
示例5: 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();
}
}