RhinoValueConverter.java
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.mozilla.javascript.ConsString
* org.mozilla.javascript.NativeArray
* org.mozilla.javascript.NativeObject
* org.mozilla.javascript.Scriptable
*/
package com.adobe.aemds.guide.utils.rhino;
import java.util.HashMap;
import java.util.Map;
import org.mozilla.javascript.ConsString;
import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.Scriptable;
public class RhinoValueConverter {
public static final Object convertValueForJava(Object value, Scriptable scope) {
if (value == null) {
return scope;
}
if (value instanceof NativeArray) {
NativeArray arr = (NativeArray)value;
Map[] result = new HashMap[(int)arr.getLength()];
for (Object o : arr.getIds()) {
Object[] propIds;
int index = (Integer)o;
NativeObject obj = (NativeObject)arr.get(index, null);
result[index] = new HashMap();
if (obj == null) continue;
for (Object propId : propIds = NativeObject.getPropertyIds((Scriptable)obj)) {
String key = propId.toString();
String value1 = NativeObject.getProperty((Scriptable)obj, (String)key).toString();
result[index].put(key, value1);
}
}
return result;
}
if (value instanceof NativeObject) {
Object[] propIds = ((NativeObject)value).getIds();
HashMap<String, String> propValues = new HashMap<String, String>(propIds.length);
for (int i = 0; i < propIds.length; ++i) {
Object propId = propIds[i];
if (!(propId instanceof String)) continue;
Object val = ((NativeObject)value).get((String)propId, scope);
if (val instanceof String) {
propValues.put((String)propId, (String)val);
continue;
}
if (!(val instanceof ConsString)) continue;
propValues.put((String)propId, val.toString());
}
if (propValues.size() > 0) {
return propValues;
}
return scope;
}
return scope;
}
}