internal static XMLName Parse(XMLLib lib, Context cx, string name) { if (name == null) { throw new ArgumentNullException("name"); } int l = name.Length; if (l != 0) { char firstChar = name [0]; if (firstChar == '*') { if (l == 1) { return(FormStar()); } } else if (firstChar == '@') { XMLName xmlName = FormProperty("", name.Substring(1)); xmlName.IsAttributeName = true; return(xmlName); } } String uri = lib.GetDefaultNamespaceURI(cx); return(XMLName.FormProperty(uri, name)); }
internal XMLName toQualifiedName(Context cx, Object namespaceValue, Object nameValue) { // This is duplication of constructQName(cx, namespaceValue, nameValue) // but for XMLName String uri; String localName; if (nameValue is QName) { QName qname = (QName)nameValue; localName = qname.LocalName; } else { localName = ScriptConvert.ToString(nameValue); } Namespace ns; if (namespaceValue == Undefined.Value) { if ("*".Equals(localName)) { ns = null; } else { ns = GetDefaultNamespace(cx); } } else if (namespaceValue == null) { ns = null; } else if (namespaceValue is Namespace) { ns = (Namespace)namespaceValue; } else { ns = Namespace.Parse(this, cx, namespaceValue); } if (ns == null) { uri = null; } else { uri = ns.Uri; } return(XMLName.FormProperty(uri, localName)); }
private XMLList Attribute(XMLName xmlName) { XMLList list = new XMLList(lib); foreach (XML xml in this) { list.AddRange(xml.Attribute(xmlName)); } return(list); }
private XMLList Descendants(XMLName xmlName) { XMLList list = new XMLList(lib); foreach (XML xml in this) { list.AddRange(xml.Descendants(xmlName)); } return(list); }
/// <summary> /// XMLList.prototype.child ( propertyName ) /// /// The child method calls the child() method of each XML object in /// this XMLList object and returns an XMLList containing the results /// in order. /// /// See ECMA 13.5.4.4 /// </summary> private XMLList Child(XMLName xmlName) { XMLList list = new XMLList(lib); foreach (XML xml in this) { list.AddRange(xml.Child(xmlName)); } return(list); }
internal XMLList GetPropertyList(XMLName xmlName) { XMLList list = new XMLList(lib); foreach (XML xml in m_Nodes) { list.AddRange(xml.GetPropertyList(xmlName)); } return(list); }
/// <summary> /// XMLList.prototype.processingInstructions ( [ name ] ) /// /// The processingInstructions method calls the processingInstructions /// method of each XML object in this XMLList object passing the optional /// parameter name (or "*" if it is omitted) and returns an XMList /// containing the results in order. /// /// See ECMA /// </summary> private XMLList ProcessingInstructions(XMLName name) { XMLList list = new XMLList(lib); foreach (XML xml in this) { list.AddRange(xml.ProcessingInstructions(name)); } return(list); }
public IRef NameRef(Context cx, object name, IScriptable scope, int memberTypeFlags) { XMLName nameRef = XMLName.Parse(this, cx, name); if (nameRef == null) { return(null); } return(nameRef); }
private bool HasOwnProperty(XMLName xmlName) { if (isPrototype) { return(FindPrototypeId(xmlName.localName) != 0); } else { return(GetPropertyList(xmlName).Length() > 0); } }
protected internal override object GetXMLProperty(XMLName name) { if (isPrototype) { return(base.Get(name.localName, this)); } XMLList list = new XMLList(lib); foreach (XML xml in m_Nodes) { list.AddRange((XMLList)xml.GetXMLProperty(name)); } return(list); }
public IRef MemberRef(Context cx, object ns, object elem, int memberTypeFlags) { XMLName xmlName = lib.toQualifiedName(cx, ns, elem); if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) { xmlName.IsAttributeName = true; } if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) { xmlName.IsDescendants = true; } xmlName.BindTo(this); return(xmlName); }
public IRef MemberRef(Context cx, object elem, int memberTypeFlags) { XMLName name = XMLName.Parse(lib, cx, elem); if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0) { name.IsAttributeName = true; } if ((memberTypeFlags & Node.DESCENDANTS_FLAG) != 0) { name.IsDescendants = true; } name.BindTo(this); return(name); }
public object EcmaGet(Context cx, object id) { XMLName name = XMLName.Parse(lib, cx, id); if (name == null) { long index = ScriptRuntime.lastUint32Result(cx); object result = base.Get((int)index, this); if (result == UniqueTag.NotFound) { return(Undefined.Value); } return(result); } return(GetXMLProperty(name)); }
public void EcmaPut(Context cx, object id, object value) { if (cx == null) { cx = Context.CurrentContext; } XMLName xmlName = XMLName.Parse(lib, cx, id); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result(cx); // TODO Fix this cast Put((int)index, this, value); return; } PutXMLProperty(xmlName, value); }
protected internal override void PutXMLProperty(XMLName name, object value) { if (isPrototype) { return; } if (value == null) { value = "null"; } else if (value is Undefined) { value = "undefined"; } if (Length() > 1) { throw ScriptRuntime.TypeError("Assignment to lists with more that one item is not supported"); } throw new NotImplementedException(); }
/// <summary> /// XML.prototype.processingInstructions ( [ name ] ) /// /// When the processingInstructions method is called with one /// parameter name, it returns an XMLList containing all the /// children of this XML object that are processing-instructions /// with the given name. When the processingInstructions method /// is called with no parameters, it returns an XMLList containing /// all the children of this XML object that are processing-instructions /// regardless of their name. /// /// See ECMA 13.4.4.28 /// </summary> /// <returns></returns> internal XMLList ProcessingInstructions(XMLName xmlName) { XMLList list = new XMLList (lib); foreach (XmlNode child in UnderlyingNode.ChildNodes) { if (child is XmlProcessingInstruction) { if (xmlName == null || xmlName.Matches (child)) list.Add (new XML (lib, child)); } } return list; }
internal void MatchAttributes(XMLList list, XMLName xmlName, XmlNode parent, bool recursive) { if (parent is XmlDocument) parent = ((XmlDocument)parent).DocumentElement; if (!(parent is XmlElement)) return; foreach (XmlAttribute attr in parent.Attributes) { if (xmlName == null || xmlName.Matches (attr)) list.Add (new XML (lib, attr)); } if (recursive) { foreach (XmlNode node in parent.ChildNodes) MatchAttributes (list, xmlName, node, recursive); } }
protected internal abstract void PutXMLProperty (XMLName xmlName, object value);
protected internal override void PutXMLProperty (XMLName name, object value) { if (isPrototype) return; if (value == null) value = "null"; else if (value is Undefined) value = "undefined"; if (Length () > 1) { throw ScriptRuntime.TypeError ("Assignment to lists with more that one item is not supported"); } throw new NotImplementedException (); }
private XMLList Descendants (XMLName xmlName) { XMLList list = new XMLList (lib); foreach (XML xml in this) list.AddRange (xml.Descendants (xmlName)); return list; }
/// <summary> /// XML.prototype.attribute ( attributeName ) /// /// The attribute method returns an XMLList /// containing zero or one XML attributes associated with /// this XML object that have the given attributeName. /// /// See ECMA 13.4.4.4 /// </summary> /// <param name="xmlName"></param> /// <returns></returns> internal XMLList Attribute(XMLName xmlName) { XMLList list = new XMLList (lib); MatchAttributes (list, xmlName, UnderlyingNode, false); return list; }
/// <summary> /// XML.prototype.elements ( [ name ] ) /// /// When the elements method is called with one parameter name, /// it returns an XMLList containing all the children of this /// XML object that are XML elements with the given name. When /// the elements method is called with no parameters, it returns /// an XMLList containing all the children of this XML object that /// are XML elements regardless of their name. /// /// See ECMA 13.4.4.13 /// </summary> private XMLList Elements(XMLName xmlName) { if (xmlName == null) return Children (); XMLList list = new XMLList (lib); MatchChildren (list, xmlName, UnderlyingNode, false); return list; }
internal XMLList GetPropertyList (XMLName xmlName) { XMLList list = new XMLList (lib); foreach (XML xml in m_Nodes) { list.AddRange (xml.GetPropertyList (xmlName)); } return list; }
private XMLList Attribute (XMLName xmlName) { XMLList list = new XMLList (lib); foreach (XML xml in this) list.AddRange (xml.Attribute (xmlName)); return list; }
/// <summary> /// XMLList.prototype.processingInstructions ( [ name ] ) /// /// The processingInstructions method calls the processingInstructions /// method of each XML object in this XMLList object passing the optional /// parameter name (or "*" if it is omitted) and returns an XMList /// containing the results in order. /// /// See ECMA /// </summary> private XMLList ProcessingInstructions (XMLName name) { XMLList list = new XMLList (lib); foreach (XML xml in this) { list.AddRange (xml.ProcessingInstructions (name)); } return list; }
protected internal override object GetXMLProperty (XMLName name) { if (isPrototype) { return base.Get (name.localName, this); } XMLList list = new XMLList (lib); foreach (XML xml in m_Nodes) { list.AddRange ((XMLList)xml.GetXMLProperty (name)); } return list; }
protected internal override void PutXMLProperty(XMLName xmlName, object value) { if (isPrototype) return; if (value == null) value = "null"; else if (value is Undefined) value = "undefined"; if (xmlName.IsAttributeName) { SetAttribute (xmlName, value); } else { if (value is XMLList) { XMLList xmlList = (value as XMLList); XMLList matches = GetPropertyList (xmlName); if (matches.Length () == 0) { foreach (XML xml in xmlList) AppendChild (xml); } else { for (int i = 1; i < matches.Length (); i++) { UnderlyingNode.RemoveChild (matches [i].UnderlyingNode); } for (int i = 1; i < xmlList.Length (); i++) { UnderlyingNode.InsertAfter ( ImportNode (xmlList [i].UnderlyingNode), matches [0].UnderlyingNode); } UnderlyingNode.ReplaceChild ( ImportNode (xmlList [0].UnderlyingNode), matches [0].UnderlyingNode); } } else { XML xml = (value as XML); if (xml == null) { xml = XML.CreateFromJS (lib, value); } XMLList matches = GetPropertyList (xmlName); if (matches.Length () == 0) { AppendChild (xml); } else { for (int i = 1; i < matches.Length (); i++) { UnderlyingNode.RemoveChild (matches [i].UnderlyingNode); } if (xml.UnderlyingNode is XmlText) { matches [0].RemoveAllChildren (); matches [0].AppendChild (xml); } else { UnderlyingNode.ReplaceChild ( ImportNode (xml.UnderlyingNode), matches [0].UnderlyingNode); } } } } }
/// <summary> /// XML.prototype.descendants ( [ name ] ) /// /// The descendants method returns all the XML valued descendants /// (children, grandchildren, great-grandchildren, etc.) of this XML /// object with the given name. If the name parameter is omitted, /// it returns all descendants of this XML object. /// /// See ECMA 13.4.4.12 /// </summary> /// <param name="xmlName"></param> /// <returns></returns> internal XMLList Descendants(XMLName xmlName) { XMLList list = new XMLList (lib); if (xmlName.IsAttributeName) { MatchAttributes (list, xmlName, UnderlyingNode, true); } else { MatchChildren (list, xmlName, UnderlyingNode, true); } return list; }
internal void SetAttribute(XMLName xmlName, object value) { if (xmlName.uri == null && xmlName.localName.Equals ("*")) { throw ScriptRuntime.TypeError ("@* assignment not supported."); } XmlNode target = UnderlyingNode; if (target is XmlDocument) target = ((XmlDocument)target).DocumentElement; if (target is XmlElement) { ((XmlElement)target).SetAttribute ( xmlName.localName, xmlName.uri, ScriptConvert.ToString (value)); } }
protected internal override object GetXMLProperty(XMLName name) { if (isPrototype) { return base.Get (name.localName, this); } if (name.IsDescendants) { return Descendants (name); } if (name.IsAttributeName) { return Attribute (name); } return Child (name); }
public void MatchChildren(XMLList list, XMLName xmlName, XmlNode parent, bool recursive) { foreach (XmlNode child in parent.ChildNodes) { if (xmlName.Matches (child)) list.Add (new XML (lib, child)); if (recursive) MatchChildren (list, xmlName, child, recursive); } }
protected internal abstract object GetXMLProperty(XMLName name);
/// <summary> /// XML.prototype.child ( propertyName ) /// /// The child method returns the list of children in this /// XML object matching the given propertyName. If propertyName is a numeric /// index, the child method returns a list containing the child at the /// ordinal position identified by propertyName. /// /// See ECMA 13.4.4.6 /// </summary> /// <param name="index"></param> /// <returns></returns> internal XMLList Child(XMLName xmlName) { XMLList list = new XMLList (lib); MatchChildren (list, xmlName, UnderlyingNode, false); return list; }
internal static XMLName Parse(XMLLib lib, Context cx, Object value) { XMLName result; if (value is XMLName) { result = (XMLName)value; } else if (value is String) { String str = (String)value; long test = ScriptRuntime.testUint32String(str); if (test >= 0) { ScriptRuntime.storeUint32Result(cx, test); result = null; } else { result = Parse(lib, cx, str); } } else if (CliHelper.IsNumber(value)) { double d = ScriptConvert.ToNumber(value); long l = (long)d; if (l == d && 0 <= l && l <= 0xFFFFFFFFL) { ScriptRuntime.storeUint32Result(cx, l); result = null; } else { throw XMLLib.BadXMLName(value); } } else if (value is QName) { QName qname = (QName)value; String uri = qname.Uri; bool 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 is Boolean || value == Undefined.Value || value == null) { throw XMLLib.BadXMLName(value); } else { String str = ScriptConvert.ToString(value); long test = ScriptRuntime.testUint32String(str); if (test >= 0) { ScriptRuntime.storeUint32Result(cx, test); result = null; } else { result = Parse(lib, cx, str); } } return(result); }
internal XMLList GetPropertyList(XMLName name) { XMLList result; // Get the named property if (name.IsDescendants) { result = Descendants (name); } else if (name.IsAttributeName) { result = Attribute (name); } else { result = Child (name); } return result; }
protected internal abstract void PutXMLProperty(XMLName xmlName, object value);
/// <summary> /// XML.prototype.hasOwnProperty ( P ) /// /// The hasOwnProperty method returns a Boolean value indicating whether /// this object has the property specified by P. For all XML objects except /// the XML prototype object, this is the same result returned by the /// internal method [[HasProperty]]. For the XML prototype object, /// hasOwnProperty also examines the list of local properties to /// determine if there is a method property with the given name. /// /// See ECMA 13.4.4.14 /// </summary> /// <param name="name"></param> /// <returns></returns> internal bool HasOwnProperty(XMLName xmlName) { if (isPrototype) { return FindPrototypeId (xmlName.localName) != 0; } else { return GetPropertyList (xmlName).Length () > 0; } }
public override object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { if (!f.HasTag(XMLOBJECT_TAG)) { return(base.ExecIdCall(f, cx, scope, thisObj, args)); } int id = f.MethodId; if (id == Id_constructor) { return(JsConstructor(cx, thisObj == null, args)); } // All XML.prototype methods require thisObj to be XML if (!(thisObj is XMLList)) { throw IncompatibleCallError(f); } XMLList realThis = (XMLList)thisObj; XMLName xmlName; switch (id) { case Id_attribute: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.Attribute(xmlName)); case Id_attributes: return(realThis.Attributes()); case Id_child: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); if (xmlName == null) { long index = ScriptRuntime.lastUint32Result(cx); return(realThis.Child(index)); } else { return(realThis.Child(xmlName)); } case Id_children: return(realThis.Children()); case Id_contains: return(realThis.Contains(GetArgSafe(args, 0))); case Id_copy: return(realThis.Copy()); case Id_descendants: { xmlName = (args.Length == 0) ? XMLName.FormStar() : XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.Descendants(xmlName)); } case Id_hasOwnProperty: xmlName = XMLName.Parse(lib, cx, GetArgSafe(args, 0)); return(realThis.HasOwnProperty(xmlName)); case Id_hasComplexContent: return(realThis.HasComplexContent()); case Id_hasSimpleContent: return(realThis.HasSimpleContent()); case Id_length: return(realThis.Length()); case Id_normalize: realThis.Normalize(); return(Undefined.Value); case Id_parent: return(realThis.Parent()); case Id_processingInstructions: xmlName = (args.Length > 0) ? XMLName.Parse(lib, cx, args [0]) : XMLName.FormStar(); return(realThis.ProcessingInstructions(xmlName)); case Id_propertyIsEnumerable: { return(realThis.PropertyIsEnumerable(GetArgSafe(args, 0))); } case Id_text: return(realThis.Text()); case Id_toString: return(realThis.ToString()); case Id_toXMLString: return(realThis.ToXMLString()); case Id_valueOf: return(realThis); case Id_addNamespace: return(realThis.DelegateTo("addNamespace").AddNamespace(GetArgSafe(args, 0))); case Id_appendChild: return(realThis.DelegateTo("appendChild").AppendChild(GetArgSafe(args, 0))); case Id_childIndex: return(realThis.DelegateTo("childIndex").ChildIndex()); case Id_inScopeNamespaces: return(realThis.DelegateTo("inScopeNamespaces").InScopeNamespaces()); case Id_insertChildAfter: return(realThis.DelegateTo("insertChildAfter").InsertChildAfter(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_insertChildBefore: return(realThis.DelegateTo("insertChildBefore").InsertChildBefore(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_localName: return(realThis.DelegateTo("localName").LocalName()); case Id_name: return(realThis.DelegateTo("name").Name()); case Id_namespace: return(realThis.DelegateTo("namespace").Namespace(GetArgSafe(args, 0))); case Id_namespaceDeclarations: return(realThis.DelegateTo("namespaceDeclarations").NamespaceDeclarations()); case Id_nodeKind: return(realThis.DelegateTo("nodeKind").NodeKind()); case Id_prependChild: return(realThis.DelegateTo("prependChild").PrependChild(GetArgSafe(args, 0))); case Id_removeNamespace: return(realThis.DelegateTo("removeNamespace").RemoveNamespace(GetArgSafe(args, 0))); case Id_replace: return(realThis.DelegateTo("replace").Replace(GetArgSafe(args, 0), GetArgSafe(args, 1))); case Id_setChildren: return(realThis.DelegateTo("setChildren").SetChildren(GetArgSafe(args, 0))); case Id_setLocalName: realThis.DelegateTo("setLocalName").SetLocalName(GetArgSafe(args, 0)); return(Undefined.Value); case Id_setName: realThis.DelegateTo("setName").SetName(GetArgSafe(args, 0)); return(Undefined.Value); case Id_setNamespace: realThis.DelegateTo("setNamespace").SetNamespace(GetArgSafe(args, 0)); return(Undefined.Value); } throw new System.ArgumentException(System.Convert.ToString(id)); }
protected internal abstract object GetXMLProperty (XMLName name);
/// <summary> /// XMLList.prototype.child ( propertyName ) /// /// The child method calls the child() method of each XML object in /// this XMLList object and returns an XMLList containing the results /// in order. /// /// See ECMA 13.5.4.4 /// </summary> private XMLList Child (XMLName xmlName) { XMLList list = new XMLList (lib); foreach (XML xml in this) list.AddRange (xml.Child (xmlName)); return list; }