org.mozilla.javascript.xml.XMLObject Java Examples
The following examples show how to use
org.mozilla.javascript.xml.XMLObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 6 votes |
public static Object getObjectElem(Scriptable obj, Object elem, Context cx) { Object result; if (obj instanceof XMLObject) { result = ((XMLObject)obj).get(cx, elem); } else { String s = toStringIdOrIndex(cx, elem); if (s == null) { int index = lastIndexResult(cx); result = ScriptableObject.getProperty(obj, index); } else { result = ScriptableObject.getProperty(obj, s); } } if (result == Scriptable.NOT_FOUND) { result = Undefined.instance; } return result; }
Example #2
Source File: XML.java From astor with GNU General Public License v2.0 | 6 votes |
private String ecmaToString() { // See ECMA357 10.1.1 if (isAttribute() || isText()) { return ecmaValue(); } if (this.hasSimpleContent()) { StringBuffer rv = new StringBuffer(); for (int i=0; i < this.node.getChildCount(); i++) { XmlNode child = this.node.getChild(i); if (!child.isProcessingInstructionType() && !child.isCommentType()) { // TODO: Probably inefficient; taking clean non-optimized // solution for now XML x = new XML(getLib(), getParentScope(), (XMLObject)getPrototype(), child); rv.append(x.toString()); } } return rv.toString(); } return toXMLString(); }
Example #3
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 6 votes |
public static Object setObjectElem(Scriptable obj, Object elem, Object value, Context cx) { if (obj instanceof XMLObject) { ((XMLObject)obj).put(cx, elem, value); } else { String s = toStringIdOrIndex(cx, elem); if (s == null) { int index = lastIndexResult(cx); ScriptableObject.putProperty(obj, index, value); } else { ScriptableObject.putProperty(obj, s, value); } } return value; }
Example #4
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
public static Object getObjectElem(Scriptable obj, Object elem, Context cx) { Object result; if (obj instanceof XMLObject) { result = ((XMLObject)obj).get(cx, elem); } else if (isSymbol(elem)) { result = ScriptableObject.getProperty(obj, (Symbol)elem); } else { String s = toStringIdOrIndex(cx, elem); if (s == null) { int index = lastIndexResult(cx); result = ScriptableObject.getProperty(obj, index); } else { result = ScriptableObject.getProperty(obj, s); } } if (result == Scriptable.NOT_FOUND) { result = Undefined.instance; } return result; }
Example #5
Source File: XML.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
private String ecmaToString() { // See ECMA357 10.1.1 if (isAttribute() || isText()) { return ecmaValue(); } if (this.hasSimpleContent()) { StringBuilder rv = new StringBuilder(); for (int i=0; i < this.node.getChildCount(); i++) { XmlNode child = this.node.getChild(i); if (!child.isProcessingInstructionType() && !child.isCommentType()) { // TODO: Probably inefficient; taking clean non-optimized // solution for now XML x = new XML(getLib(), getParentScope(), (XMLObject)getPrototype(), child); rv.append(x.toString()); } } return rv.toString(); } return toXMLString(); }
Example #6
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
public static Object setObjectElem(Scriptable obj, Object elem, Object value, Context cx) { if (obj instanceof XMLObject) { ((XMLObject)obj).put(cx, elem, value); } else if (isSymbol(elem)) { ScriptableObject.putProperty(obj, (Symbol)elem, value); } else { String s = toStringIdOrIndex(cx, elem); if (s == null) { int index = lastIndexResult(cx); ScriptableObject.putProperty(obj, index, value); } else { ScriptableObject.putProperty(obj, s, value); } } return value; }
Example #7
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Scriptable enterWith(Object obj, Context cx, Scriptable scope) { Scriptable sobj = toObjectOrNull(cx, obj, scope); if (sobj == null) { throw typeError1("msg.undef.with", toString(obj)); } if (sobj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)sobj; return xmlObject.enterWith(scope); } return new NativeWith(scope, sobj); }
Example #8
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Ref memberRef(Object obj, Object namespace, Object elem, Context cx, int memberTypeFlags) { if (!(obj instanceof XMLObject)) { throw notXmlError(obj); } XMLObject xmlObject = (XMLObject)obj; return xmlObject.memberRef(cx, namespace, elem, memberTypeFlags); }
Example #9
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Ref memberRef(Object obj, Object elem, Context cx, int memberTypeFlags) { if (!(obj instanceof XMLObject)) { throw notXmlError(obj); } XMLObject xmlObject = (XMLObject)obj; return xmlObject.memberRef(cx, elem, memberTypeFlags); }
Example #10
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Scriptable enterDotQuery(Object value, Scriptable scope) { if (!(value instanceof XMLObject)) { throw notXmlError(value); } XMLObject object = (XMLObject)value; return object.enterDotQuery(scope); }
Example #11
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Scriptable enterWith(Object obj, Context cx, Scriptable scope) { Scriptable sobj = toObjectOrNull(cx, obj); if (sobj == null) { throw typeError1("msg.undef.with", toString(obj)); } if (sobj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)sobj; return xmlObject.enterWith(scope); } return new NativeWith(scope, sobj); }
Example #12
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Object nameIncrDecr(Scriptable scopeChain, String id, Context cx, int incrDecrMask) { Scriptable target; Object value; search: { do { if (cx.useDynamicScope && scopeChain.getParentScope() == null) { scopeChain = checkDynamicScope(cx.topCallScope, scopeChain); } target = scopeChain; do { if (target instanceof NativeWith && target.getPrototype() instanceof XMLObject) { break; } value = target.get(id, scopeChain); if (value != Scriptable.NOT_FOUND) { break search; } target = target.getPrototype(); } while (target != null); scopeChain = scopeChain.getParentScope(); } while (scopeChain != null); throw notFoundError(scopeChain, id); } return doScriptableIncrDecr(target, id, scopeChain, value, incrDecrMask); }
Example #13
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 5 votes |
public static Object setConst(Scriptable bound, Object value, Context cx, String id) { if (bound instanceof XMLObject) { bound.put(id, bound, value); } else { ScriptableObject.putConstProperty(bound, id, value); } return value; }
Example #14
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Object setConst(Scriptable bound, Object value, Context cx, String id) { if (bound instanceof XMLObject) { bound.put(id, bound, value); } else { ScriptableObject.putConstProperty(bound, id, value); } return value; }
Example #15
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Ref memberRef(Object obj, Object namespace, Object elem, Context cx, int memberTypeFlags) { if (!(obj instanceof XMLObject)) { throw notXmlError(obj); } XMLObject xmlObject = (XMLObject)obj; return xmlObject.memberRef(cx, namespace, elem, memberTypeFlags); }
Example #16
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Ref memberRef(Object obj, Object elem, Context cx, int memberTypeFlags) { if (!(obj instanceof XMLObject)) { throw notXmlError(obj); } XMLObject xmlObject = (XMLObject)obj; return xmlObject.memberRef(cx, elem, memberTypeFlags); }
Example #17
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Scriptable enterDotQuery(Object value, Scriptable scope) { if (!(value instanceof XMLObject)) { throw notXmlError(value); } XMLObject object = (XMLObject)value; return object.enterDotQuery(scope); }
Example #18
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public static Object nameIncrDecr(Scriptable scopeChain, String id, Context cx, int incrDecrMask) { Scriptable target; Object value; search: { do { if (cx.useDynamicScope && scopeChain.getParentScope() == null) { scopeChain = checkDynamicScope(cx.topCallScope, scopeChain); } target = scopeChain; do { if (target instanceof NativeWith && target.getPrototype() instanceof XMLObject) { break; } value = target.get(id, scopeChain); if (value != Scriptable.NOT_FOUND) { break search; } target = target.getPrototype(); } while (target != null); scopeChain = scopeChain.getParentScope(); } while (scopeChain != null); throw notFoundError(scopeChain, id); } return doScriptableIncrDecr(target, id, scopeChain, value, incrDecrMask); }
Example #19
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
private static Object nameOrFunction(Context cx, Scriptable scope, Scriptable parentScope, String name, boolean asFunctionCall) { Object result; Scriptable thisObj = scope; // It is used only if asFunctionCall==true. XMLObject firstXMLObject = null; for (;;) { if (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObj = (XMLObject)withObj; if (xmlObj.has(name, xmlObj)) { // function this should be the target object of with thisObj = xmlObj; result = xmlObj.get(name, xmlObj); break; } if (firstXMLObject == null) { firstXMLObject = xmlObj; } } else { result = ScriptableObject.getProperty(withObj, name); if (result != Scriptable.NOT_FOUND) { // function this should be the target object of with thisObj = withObj; break; } } } else if (scope instanceof NativeCall) { // NativeCall does not prototype chain and Scriptable.get // can be called directly. result = scope.get(name, scope); if (result != Scriptable.NOT_FOUND) { if (asFunctionCall) { // ECMA 262 requires that this for nested funtions // should be top scope thisObj = ScriptableObject. getTopLevelScope(parentScope); } break; } } else { // Can happen if Rhino embedding decided that nested // scopes are useful for what ever reasons. result = ScriptableObject.getProperty(scope, name); if (result != Scriptable.NOT_FOUND) { thisObj = scope; break; } } scope = parentScope; parentScope = parentScope.getParentScope(); if (parentScope == null) { result = topScopeName(cx, scope, name); if (result == Scriptable.NOT_FOUND) { if (firstXMLObject == null || asFunctionCall) { throw notFoundError(scope, name); } // The name was not found, but we did find an XML // object in the scope chain and we are looking for name, // not function. The result should be an empty XMLList // in name context. result = firstXMLObject.get(name, firstXMLObject); } // For top scope thisObj for functions is always scope itself. thisObj = scope; break; } } if (asFunctionCall) { if (!(result instanceof Callable)) { throw notFunctionError(result, name); } storeScriptable(cx, thisObj); } return result; }
Example #20
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 4 votes |
private static Object nameOrFunction(Context cx, Scriptable scope, Scriptable parentScope, String name, boolean asFunctionCall) { Object result; Scriptable thisObj = scope; // It is used only if asFunctionCall==true. XMLObject firstXMLObject = null; for (;;) { if (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObj = (XMLObject)withObj; if (xmlObj.has(name, xmlObj)) { // function this should be the target object of with thisObj = xmlObj; result = xmlObj.get(name, xmlObj); break; } if (firstXMLObject == null) { firstXMLObject = xmlObj; } } else { result = ScriptableObject.getProperty(withObj, name); if (result != Scriptable.NOT_FOUND) { // function this should be the target object of with thisObj = withObj; break; } } } else if (scope instanceof NativeCall) { // NativeCall does not prototype chain and Scriptable.get // can be called directly. result = scope.get(name, scope); if (result != Scriptable.NOT_FOUND) { if (asFunctionCall) { // ECMA 262 requires that this for nested funtions // should be top scope thisObj = ScriptableObject. getTopLevelScope(parentScope); } break; } } else { // Can happen if Rhino embedding decided that nested // scopes are useful for what ever reasons. result = ScriptableObject.getProperty(scope, name); if (result != Scriptable.NOT_FOUND) { thisObj = scope; break; } } scope = parentScope; parentScope = parentScope.getParentScope(); if (parentScope == null) { result = topScopeName(cx, scope, name); if (result == Scriptable.NOT_FOUND) { if (firstXMLObject == null || asFunctionCall) { throw notFoundError(scope, name); } // The name was not found, but we did find an XML // object in the scope chain and we are looking for name, // not function. The result should be an empty XMLList // in name context. result = firstXMLObject.get(name, firstXMLObject); } // For top scope thisObj for functions is always scope itself. thisObj = scope; break; } } if (asFunctionCall) { if (!(result instanceof Callable)) { throw notFunctionError(result, name); } storeScriptable(cx, thisObj); } return result; }
Example #21
Source File: ScriptRuntime.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Returns the object in the scope chain that has a given property. * * The order of evaluation of an assignment expression involves * evaluating the lhs to a reference, evaluating the rhs, and then * modifying the reference with the rhs value. This method is used * to 'bind' the given name to an object containing that property * so that the side effects of evaluating the rhs do not affect * which property is modified. * Typically used in conjunction with setName. * * See ECMA 10.1.4 */ public static Scriptable bind(Context cx, Scriptable scope, String id) { Scriptable firstXMLObject = null; Scriptable parent = scope.getParentScope(); childScopesChecks: if (parent != null) { // Check for possibly nested "with" scopes first while (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)withObj; if (xmlObject.has(cx, id)) { return xmlObject; } if (firstXMLObject == null) { firstXMLObject = xmlObject; } } else { if (ScriptableObject.hasProperty(withObj, id)) { return withObj; } } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } for (;;) { if (ScriptableObject.hasProperty(scope, id)) { return scope; } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } } // scope here is top scope if (cx.useDynamicScope) { scope = checkDynamicScope(cx.topCallScope, scope); } if (ScriptableObject.hasProperty(scope, id)) { return scope; } // Nothing was found, but since XML objects always bind // return one if found return firstXMLObject; }
Example #22
Source File: ScriptRuntime.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
/** * Returns the object in the scope chain that has a given property. * * The order of evaluation of an assignment expression involves * evaluating the lhs to a reference, evaluating the rhs, and then * modifying the reference with the rhs value. This method is used * to 'bind' the given name to an object containing that property * so that the side effects of evaluating the rhs do not affect * which property is modified. * Typically used in conjunction with setName. * * See ECMA 10.1.4 */ public static Scriptable bind(Context cx, Scriptable scope, String id) { Scriptable firstXMLObject = null; Scriptable parent = scope.getParentScope(); childScopesChecks: if (parent != null) { // Check for possibly nested "with" scopes first while (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)withObj; if (xmlObject.has(cx, id)) { return xmlObject; } if (firstXMLObject == null) { firstXMLObject = xmlObject; } } else { if (ScriptableObject.hasProperty(withObj, id)) { return withObj; } } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } for (;;) { if (ScriptableObject.hasProperty(scope, id)) { return scope; } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } } // scope here is top scope if (cx.useDynamicScope) { scope = checkDynamicScope(cx.topCallScope, scope); } if (ScriptableObject.hasProperty(scope, id)) { return scope; } // Nothing was found, but since XML objects always bind // return one if found return firstXMLObject; }
Example #23
Source File: XML.java From JsDroidCmd with Mozilla Public License 2.0 | 4 votes |
XML(XMLLibImpl lib, Scriptable scope, XMLObject prototype, XmlNode node) { super(lib, scope, prototype); initialize(node); }
Example #24
Source File: XML.java From astor with GNU General Public License v2.0 | 4 votes |
XML(XMLLibImpl lib, Scriptable scope, XMLObject prototype, XmlNode node) { super(lib, scope, prototype); initialize(node); }