本文整理匯總了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.get方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptObjectMirror.get方法的具體用法?Java ScriptObjectMirror.get怎麽用?Java ScriptObjectMirror.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jdk.nashorn.api.scripting.ScriptObjectMirror
的用法示例。
在下文中一共展示了ScriptObjectMirror.get方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convert
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public static Object convert(Object original) {
if (original == null) {
return null;
} else if (original instanceof String || original instanceof Integer || original instanceof Long || original instanceof Boolean || original instanceof Double) {
return original;
} else if (original instanceof ScriptObjectMirror) {
ScriptObjectMirror jsOriginal = (ScriptObjectMirror)original;
if (jsOriginal.isArray()) {
List<Object> listResult = new ArrayList<Object>();
Integer length = (Integer)jsOriginal.get("length");
for (int i = 0; i < length; i++) {
listResult.add(convert(jsOriginal.get("" + i)));
}
return listResult;
} else if (jsOriginal.isFunction()) {
// can't convert it...
return null;
}
Map<String,Object> mapResult = new LinkedHashMap<String,Object>();
for (Map.Entry<String,Object> entry: jsOriginal.entrySet()) {
mapResult.put(entry.getKey(), convert(entry.getValue()));
}
return mapResult;
}
return original;
}
示例2: getTicketInfoForPassengerForm
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private static String getTicketInfoForPassengerForm(String html, String key) throws ScriptException {
Document document = Jsoup.parse(html);
Elements elements = document.getElementsByTag("script");
String jsContent = elements.stream().filter(e -> e.data().contains("ticketInfoForPassengerForm") && e.childNodes().size() > 0)
.findFirst().map(e -> e.childNode(0).outerHtml()).orElse(StringUtils.EMPTY);
jsContent = jsContent.substring(0, jsContent.lastIndexOf("var"));
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");
engine.eval(jsContent);
ScriptObjectMirror objectMirror = (ScriptObjectMirror) engine.get("ticketInfoForPassengerForm");
return (String) objectMirror.get(key);
}
示例3: jsToNode
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private org.antology.db.Node jsToNode(Object object) throws Exception {
if (object instanceof ScriptObjectMirror) {
ScriptObjectMirror mirror = (ScriptObjectMirror) object;
if (mirror.isArray()) {
List<org.antology.db.Node> list = new LinkedList<>();
for (int i = 0; i < mirror.size(); i++) {
list.add(jsToNode(mirror.get(Integer.toString(i))));
}
return new Node(Schema.Type.LIST, list);
} else {
Map<String, org.antology.db.Node> struct = new HashMap<>();
for (String key : mirror.getOwnKeys(false)) {
java.lang.Object value = mirror.get(key);
struct.put(key, jsToNode(value));
}
return new Node(Schema.Type.STRUCT, struct);
}
} else if (object instanceof String) {
return new Node(Schema.Type.STRING, object);
} else if (object instanceof Integer) {
return new Node(Schema.Type.INTEGER, object);
} else if (object instanceof Double) {
return new Node(Schema.Type.FLOAT, object);
} else if (object instanceof Boolean) {
return new Node(Schema.Type.BOOLEAN, object);
} else {
throw new Exception("Unknown type " + object.getClass().getName());
}
}
示例4: logMessage
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private static String logMessage(ScriptObjectMirror mirror, int length) {
final Object first = mirror.get("0");
if (first instanceof String) {
final String format = (String) first;
if (SUBSTITUTIONS.matcher(format).find()) {
// The first element is a string and it contains substitution(s).
return logMessageFormat(format, mirror, length);
}
}
// The first element does not contain substitution(s).
return logMessageSimple(new StringBuilder(64), mirror, 0, length);
}
示例5: StringifyObject
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private static void StringifyObject(Object object, StringBuilder builder, boolean inObjectOrArray) {
if (object == null) {
builder.append("null");
} else if (object instanceof String && inObjectOrArray) {
builder.append("\"").append(((String) object).replaceAll("\"", "\\\"")).append("\"");
} else if (object instanceof String) {
builder.append(object);
} else if (object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Double) {
builder.append(object.toString());
} else if (object instanceof ScriptObjectMirror) {
ScriptObjectMirror scriptObject = (ScriptObjectMirror)object;
if (scriptObject.isArray()) {
builder.append("[");
Integer length = (Integer) scriptObject.get("length");
for (int i = 0; i < length; i++) {
StringifyObject(scriptObject.get("" + i), builder, true);
}
builder.append("]");
} else if (scriptObject.isFunction()) {
builder.append("[function()]");
} else {
builder.append("{");
boolean isFirst = true;
for (Map.Entry<String, Object> entry : scriptObject.entrySet()) {
builder.append(isFirst ? "" : ", ")
.append("\"")
.append(entry.getKey())
.append("\": ");
StringifyObject(entry.getValue(), builder, true);
isFirst = false;
}
builder.append("}");
}
} else {
builder.append(object.toString());
}
}
示例6: funcScriptObjectMirror
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public static Object funcScriptObjectMirror(final ScriptObjectMirror sobj) {
return sobj.get("foo");
}
示例7: getProp
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public static Object getProp(ScriptObjectMirror context, String prop) {
return context.get(prop);
}
示例8: getStaticProp
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public static Object getStaticProp(ScriptEngine engine, String className, String property) {
ScriptObjectMirror classObject = getClassObject(engine, className);
return classObject.get(property);
}