XmlNode.QName toNodeQName(Context cx, Object namespaceValue, Object nameValue) { // This is duplication of constructQName(cx, namespaceValue, nameValue) // but for XMLName String localName; if (nameValue instanceof QName) { QName qname = (QName) nameValue; localName = qname.localName(); } else { localName = ScriptRuntime.toString(nameValue); } XmlNode.Namespace ns; if (namespaceValue == Undefined.instance) { if ("*".equals(localName)) { ns = null; } else { ns = getDefaultNamespace(cx).getDelegate(); } } else if (namespaceValue == null) { ns = null; } else if (namespaceValue instanceof Namespace) { ns = ((Namespace) namespaceValue).getDelegate(); } else { ns = this.namespacePrototype.constructNamespace(namespaceValue).getDelegate(); } if (localName != null && localName.equals("*")) localName = null; return XmlNode.QName.create(ns, localName); }
static QName create(Namespace namespace, String localName) { // A null namespace indicates a wild-card match for any namespace // A null localName indicates "*" from the point of view of ECMA357 if (localName != null && localName.equals("*")) throw new RuntimeException("* is not valid localName"); QName rv = new QName(); rv.namespace = namespace; rv.localName = localName; return rv; }
/** * 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; }
/* 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; }