/** * If value represents Uint32 index, make it available through ScriptRuntime.lastUint32Result(cx) * and return null. Otherwise return the same value as toXMLName(cx, value). */ XMLName toXMLNameOrIndex(Context cx, Object value) { XMLName result; if (value instanceof XMLName) { result = (XMLName) value; } else if (value instanceof String) { String str = (String) value; long test = ScriptRuntime.testUint32String(str); if (test >= 0) { ScriptRuntime.storeUint32Result(cx, test); result = null; } else { result = toXMLNameFromString(cx, str); } } else if (value instanceof Number) { double d = ((Number) value).doubleValue(); long l = (long) d; if (l == d && 0 <= l && l <= 0xFFFFFFFFL) { ScriptRuntime.storeUint32Result(cx, l); result = null; } else { throw badXMLName(value); } } else if (value instanceof QName) { QName qname = (QName) value; String uri = qname.uri(); boolean number = false; result = null; if (uri != null && uri.length() == 0) { // Only in this case qname.toString() can resemble uint32 long test = ScriptRuntime.testUint32String(uri); if (test >= 0) { ScriptRuntime.storeUint32Result(cx, test); number = true; } } if (!number) { result = XMLName.formProperty(uri, qname.localName()); } } else if (value instanceof Boolean || value == Undefined.instance || value == null) { throw badXMLName(value); } else { String str = ScriptRuntime.toString(value); long test = ScriptRuntime.testUint32String(str); if (test >= 0) { ScriptRuntime.storeUint32Result(cx, test); result = null; } else { result = toXMLNameFromString(cx, str); } } return result; }
@Override void putXMLProperty(XMLName xmlName, Object value) { // Log("put property: " + name); // Special-case checks for undefined and null if (value == null) { value = "null"; } else if (value instanceof Undefined) { value = "undefined"; } if (length() > 1) { throw ScriptRuntime.typeError("Assignment to lists with more than one item is not supported"); } else if (length() == 0) { // Secret sauce for super-expandos. // We set an element here, and then add ourselves to our target. if (targetObject != null && targetProperty != null && targetProperty.getLocalName() != null && targetProperty.getLocalName().length() > 0) { // Add an empty element with our targetProperty name and // then set it. XML xmlValue = newTextElementXML(null, targetProperty, null); addToList(xmlValue); if (xmlName.isAttributeName()) { setAttribute(xmlName, value); } else { XML xml = item(0); xml.putXMLProperty(xmlName, value); // Update the list with the new item at location 0. replace(0, item(0)); } // Now add us to our parent XMLName name2 = XMLName.formProperty( targetProperty.getNamespace().getUri(), targetProperty.getLocalName()); targetObject.putXMLProperty(name2, this); replace(0, targetObject.getXML().getLastXmlChild()); } else { throw ScriptRuntime.typeError("Assignment to empty XMLList without targets not supported"); } } else if (xmlName.isAttributeName()) { setAttribute(xmlName, value); } else { XML xml = item(0); xml.putXMLProperty(xmlName, value); // Update the list with the new item at location 0. replace(0, item(0)); } }
/* TODO: Marked deprecated by original author */ XMLName toXMLName(Context cx, Object nameValue) { XMLName result; if (nameValue instanceof XMLName) { result = (XMLName) nameValue; } else if (nameValue instanceof QName) { QName qname = (QName) nameValue; result = XMLName.formProperty(qname.uri(), qname.localName()); } else if (nameValue instanceof String) { result = toXMLNameFromString(cx, (String) nameValue); } else if (nameValue instanceof Boolean || nameValue instanceof Number || nameValue == Undefined.instance || nameValue == null) { throw badXMLName(nameValue); } else { String name = ScriptRuntime.toString(nameValue); result = toXMLNameFromString(cx, name); } return result; }