/// <summary> /// Used primarily by <see cref="ICdsElement.ToXml"/> implementations. /// <para> /// Implementation will assign some default implementaitons /// to the unassigned <see cref="ToXmlFormatter.Method"/> fields /// of the "formatter" argument, unless information in /// the "data" argument specify otherwise. /// The assigned delegates are obtained from the "obj" argument's /// implementations of the <see cref="IToXmlData"/> methods. /// </para> /// <para> /// After assigning delegate implementations to the "formatter", the /// method calls <see cref="ToXmlFormatter.ToXml"/> to complete /// the standard implementation. /// </para> /// </summary> /// <param name="obj">This object provides the implementations assigned to the formatter argument.</param> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects. Delegate fields may be reassigned here /// if they are null. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> public static void ToXml(IToXmlData obj, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData)data; if ((formatter.StartElement == null) && (_d.IncludeElementDeclaration == true)) { formatter.StartElement = new ToXmlFormatter.Method(obj.StartElement); } if ((formatter.WriteInnerXml == null) && (_d.IncludeInnerXml == true)) { formatter.WriteInnerXml = new ToXmlFormatter.Method(obj.WriteInnerXml); } if ((formatter.WriteValue == null) && (_d.IncludeValue == true)) { formatter.WriteValue = new ToXmlFormatter.Method(obj.WriteValue); } if ((formatter.EndElement == null) && (_d.IncludeElementDeclaration == true)) { formatter.EndElement = new ToXmlFormatter.Method(obj.EndElement); } // Now call those implementations. ToXmlFormatter.ToXml(formatter, data, xmlWriter); }
/// <summary> /// /// </summary> /// <param name="mo"></param> /// <param name="writeProperties"></param> /// <param name="shouldPrintResources"></param> /// <param name="writeResources"></param> /// <param name="writeDescNodes"></param> /// <param name="formatter"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXml( IUPnPMedia mo, DelegateWriteProperties writeProperties, DelegateShouldPrintResources shouldPrintResources, DelegateWriteResources writeResources, DelegateWriteDescNodes writeDescNodes, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter ) { // When serializing the properties, resources, and desc nodes, // we must always write the inner xml, the value, and the element // declaration. Save the original values, print these portions // of the DIDL-Lite and then revert back. ToXmlData d2 = data; data.IncludeElementDeclaration = true; data.IncludeInnerXml = true; data.IncludeValue = true; if (writeProperties != null) { writeProperties(mo, data, xmlWriter); } if (writeResources != null) { writeResources(mo, shouldPrintResources, formatter, data, xmlWriter); } if (writeDescNodes != null) { writeDescNodes(mo, data, xmlWriter); } data.IncludeElementDeclaration = d2.IncludeElementDeclaration; data.IncludeInnerXml = d2.IncludeInnerXml; data.IncludeValue = d2.IncludeValue; IMediaContainer mc = mo as IMediaContainer; if (mc != null) { if (data.IsRecursive) { foreach (IUPnPMedia child in mc.CompleteList) { ToXmlFormatter f2 = formatter; f2.StartElement = null; f2.EndElement = null; f2.WriteInnerXml = null; f2.WriteValue = null; child.ToXml(f2, data, xmlWriter); } } } }
/// <summary> /// Instructs the "xmlWriter" argument to start the "upnp:searchClass" element. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown when the "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData)data; xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_searchClass); if (this.m_AttributeNames == null) { this.PrintFriendlyName(_d.DesiredProperties, xmlWriter); this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter); } else { foreach (string attribName in this.m_AttributeNames) { if (string.Compare(attribName, T[_ATTRIB.name]) == 0) { this.PrintFriendlyName(_d.DesiredProperties, xmlWriter); } else if (string.Compare(attribName, T[_ATTRIB.includeDerived]) == 0) { this.PrintIncludeDerived(_d.DesiredProperties, xmlWriter); } } } }
/// <summary> /// Instructs the "xmlWriter" argument to start the metadata element. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> public void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData)data; xmlWriter.WriteStartElement(this.ns_tag); if (_d.DesiredProperties != null) { if (_d.DesiredProperties.Contains(this.ns_tag + "@role")) { if ((this.m_role != null) && (this.m_role != "")) { xmlWriter.WriteAttributeString("role", this.m_role); } } } }
/// <summary> /// Default implementation to use when printing media object desc nodes. /// </summary> /// <param name="mo"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlDescNodes(IUPnPMedia mo, ToXmlData data, XmlTextWriter xmlWriter) { foreach (string descNode in mo.MergedDescNodes) { // do nothing for custom metadata for now if ( (data.DesiredProperties.Count == 0) || (data.DesiredProperties.Contains(Tags.GetInstance()[_DIDL.Desc]) == true) ) { // desc nodes are simply strings that // conform to CDS-compliant desc node elements xmlWriter.WriteRaw(descNode); } } }
/// <summary> /// Although this class doesn't implement /// <see cref="ICdsElement"/> /// the intent of this method is exactly the same as /// <see cref="ICdsElement.ToXml"/>. /// </summary> /// <param name="data"> /// Argument must be a <see cref="ToXmlData"/> object. /// </param> /// <param name="xmlWriter"> /// <see cref="XmlTextWriter"/> object that will print the /// reprsentation in an XML compliant way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> public void ToXml(ToXmlData data, XmlTextWriter xmlWriter) { ToXmlData _d = data; IList list; ICdsElement ele; string tag_title = T[_DC.title]; string tag_class = T[_UPNP.Class]; list = this[tag_title]; ele = (ICdsElement)list[0]; xmlWriter.WriteElementString(tag_title, ele.StringValue); list = this[tag_class]; ele = (ICdsElement)list[0]; xmlWriter.WriteElementString(tag_class, ele.StringValue); if (_d.DesiredProperties != null) { ICollection properties = this.PropertyNames; foreach (string propName in properties) { if ( (_d.DesiredProperties.Count == 0) || (_d.DesiredProperties.Contains(propName)) ) { if ((propName != tag_title) && (propName != tag_class)) { list = this[propName]; if (list != null) { if (list.Count > 0) { foreach (ICdsElement val in list) { val.ToXml(ToXmlFormatter.DefaultFormatter, _d, xmlWriter); //val.ToXml(false, desiredProperties, xmlWriter); } } } } } } } }
/// <summary> /// <para> /// Programmers assign the <see cref="ToXmlFormatter.StartElement"/> /// field to this method, when attempting to print this media object. /// </para> /// <para> /// Algorithm: /// 1. declare the item element /// /// 2. If this object will be added as a direct child /// of a container in a CreateObject request, then /// do not print the object's ID. /// /// 3. Print the ID of the item that this object points /// to if appropriate. If intending to request /// a MediaServer to create a child object that points /// to another object then a control point should /// use the CreateReference, so in such a case /// this method will throw an exception. /// /// 4. Print the parent object, taking into account /// CreateObject instructions. /// /// 5. Print the restricted attribute. /// </para> /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// /// <para> /// For an explanation why this argument allows any object, /// please consult the documentation for the /// <see cref="ToXmlFormatter.Method"/> delegate type. /// </para> /// /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown when the "data" argument is not a /// <see cref="ToXmlData"/> object. public override void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData)data; xmlWriter.WriteStartElement(T[_DIDL.Item]); if (_d.CreateObjectParentID != null) { xmlWriter.WriteAttributeString(T[_ATTRIB.id], ""); } else { xmlWriter.WriteAttributeString(T[_ATTRIB.id], this.ID); } if (this.IsReference) { if (_d.CreateObjectParentID != null) { throw new Error_BadMetadata("Cannot print this object's XML for use with CreateObject because it is a reference item. Use the CreateReference action instead. Error found on ID='" + this.m_ID + "'"); } xmlWriter.WriteAttributeString(T[_ATTRIB.refID], this.RefID); } if (_d.CreateObjectParentID != null) { xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], _d.CreateObjectParentID); } else if (this.m_Parent != null) { xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_Parent.ID); } else if (this.m_ParentID != null) { xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], this.m_ParentID); } else if (_d.IgnoreBlankParentError) { xmlWriter.WriteAttributeString(T[_ATTRIB.parentID], "-1"); } else { throw new Error_BadMetadata("Object must have a parent in order to be printed as DIDL-Lite. Error found on ID='" + this.m_ID + "'"); } xmlWriter.WriteAttributeString(T[_ATTRIB.restricted], GetBoolAsOneZero(this.IsRestricted).ToString()); }
/// <summary> /// Instructs the "xmlWriter" argument to start the "upnp:class" element. /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects and metadata. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> public virtual void StartElement(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { xmlWriter.WriteStartElement(Tags.PropertyAttributes.upnp_class); ToXmlData _d = (ToXmlData)data; if (this.m_AttributeNames == null) { this.PrintFriendlyName(_d.DesiredProperties, xmlWriter); } else { foreach (string attribName in this.m_AttributeNames) { if (string.Compare(attribName, T[_ATTRIB.name]) == 0) { this.PrintFriendlyName(_d.DesiredProperties, xmlWriter); } } } }
/// <summary> /// Default implementation to use when printing media object resources. /// </summary> /// <param name="mo"></param> /// <param name="shouldPrintResources"></param> /// <param name="formatter"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlResources(IUPnPMedia mo, DelegateShouldPrintResources shouldPrintResources, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter) { if (shouldPrintResources(data.DesiredProperties)) { // Set up the resource formatter to use the // default StartElement, EndElement, WriteInnerXml, and WriteValue // implementations. This stuff has no effect // if the WriteResource field has been assigned. ToXmlFormatter resFormatter = formatter; resFormatter.StartElement = null; resFormatter.EndElement = null; resFormatter.WriteInnerXml = null; resFormatter.WriteValue = null; // print the resources foreach (IMediaResource res in mo.MergedResources) { res.ToXml(resFormatter, data, xmlWriter); } } }
/// <summary> /// /// </summary> /// <param name="mo"></param> /// <param name="writeProperties"></param> /// <param name="shouldPrintResources"></param> /// <param name="writeResources"></param> /// <param name="writeDescNodes"></param> /// <param name="formatter"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXml ( IUPnPMedia mo, DelegateWriteProperties writeProperties, DelegateShouldPrintResources shouldPrintResources, DelegateWriteResources writeResources, DelegateWriteDescNodes writeDescNodes, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter ) { // When serializing the properties, resources, and desc nodes, // we must always write the inner xml, the value, and the element // declaration. Save the original values, print these portions // of the DIDL-Lite and then revert back. ToXmlData d2 = data; data.IncludeElementDeclaration = true; data.IncludeInnerXml = true; data.IncludeValue = true; if (writeProperties != null) { writeProperties(mo, data, xmlWriter); } if (writeResources != null) { writeResources(mo, shouldPrintResources, formatter, data, xmlWriter); } if (writeDescNodes != null) { writeDescNodes(mo, data, xmlWriter); } data.IncludeElementDeclaration = d2.IncludeElementDeclaration; data.IncludeInnerXml = d2.IncludeInnerXml; data.IncludeValue = d2.IncludeValue; IMediaContainer mc = mo as IMediaContainer; if (mc != null) { if (data.IsRecursive) { foreach (IUPnPMedia child in mc.CompleteList) { ToXmlFormatter f2 = formatter; f2.StartElement = null; f2.EndElement = null; f2.WriteInnerXml = null; f2.WriteValue = null; child.ToXml(f2, data, xmlWriter); } } } }
/// <summary> /// Default implementation to use when printing media object properties. /// </summary> /// <param name="mo"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlProperties(IUPnPMedia mo, ToXmlData data, XmlTextWriter xmlWriter) { mo.MergedProperties.ToXml(data, xmlWriter); }
/// <summary> /// Prints the XML representation of the metadata element. /// <para> /// Implementation calls the <see cref="ToXmlData.ToXml"/> /// method for its implementation. /// </para> /// </summary> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if the "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> public void ToXml(ToXmlFormatter formatter, object data, XmlTextWriter xmlWriter) { ToXmlData.ToXml(this, formatter, (ToXmlData)data, xmlWriter); }
/// <summary> /// Default implementation to use when printing media object desc nodes. /// </summary> /// <param name="mo"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlDescNodes(IUPnPMedia mo, ToXmlData data, XmlTextWriter xmlWriter) { foreach (string descNode in mo.MergedDescNodes) { // do nothing for custom metadata for now if ( (data.DesiredProperties.Count == 0) || (data.DesiredProperties.Contains(Tags.GetInstance()[_DIDL.Desc]) == true) ) { // desc nodes are simply strings that // conform to CDS-compliant desc node elements xmlWriter.WriteRaw(descNode); } } }
/// <summary> /// Default implementation to use when printing media object properties. /// </summary> /// <param name="mo"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlProperties(IUPnPMedia mo, ToXmlData data, XmlTextWriter xmlWriter) { mo.MergedProperties.ToXml(data, xmlWriter); }
public void SetTxtBox() { if (this.MediaObj != null) { StringBuilder sbXml = null; sbXml = new StringBuilder(MediaObject.XML_BUFFER_SIZE); StringWriter sw = new StringWriter(sbXml); XmlTextWriter xmlWriter = new XmlTextWriter(sw); xmlWriter.Formatting = System.Xml.Formatting.Indented; xmlWriter.Namespaces = true; ToXmlFormatter _f = new ToXmlFormatter(); ToXmlData _d = new ToXmlData(); _d.DesiredProperties = new ArrayList(0); _d.IsRecursive = false; this.MediaObj.ToXml(_f, _d, xmlWriter); //this.MediaObj.ToXml(false, new ArrayList(0), xmlWriter); this.txtbox.Text = sbXml.ToString(); } }
/// <summary> /// Used primarily by <see cref="ICdsElement.ToXml"/> implementations. /// <para> /// Implementation will assign some default implementaitons /// to the unassigned <see cref="ToXmlFormatter.Method"/> fields /// of the "formatter" argument, unless information in /// the "data" argument specify otherwise. /// The assigned delegates are obtained from the "obj" argument's /// implementations of the <see cref="IToXmlData"/> methods. /// </para> /// <para> /// After assigning delegate implementations to the "formatter", the /// method calls <see cref="ToXmlFormatter.ToXml"/> to complete /// the standard implementation. /// </para> /// </summary> /// <param name="obj">This object provides the implementations assigned to the formatter argument.</param> /// <param name="formatter"> /// A <see cref="ToXmlFormatter"/> object that /// specifies method implementations for printing /// media objects. Delegate fields may be reassigned here /// if they are null. /// </param> /// <param name="data"> /// This object should be a <see cref="ToXmlData"/> /// object that contains additional instructions used /// by the "formatter" argument. /// </param> /// <param name="xmlWriter"> /// The <see cref="XmlTextWriter"/> object that /// will format the representation in an XML /// valid way. /// </param> public static void ToXml(IToXmlData obj, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter) { ToXmlData _d = (ToXmlData) data; if ((formatter.StartElement == null) && (_d.IncludeElementDeclaration == true)) { formatter.StartElement = new ToXmlFormatter.Method (obj.StartElement); } if ((formatter.WriteInnerXml == null) && (_d.IncludeInnerXml == true)) { formatter.WriteInnerXml = new ToXmlFormatter.Method (obj.WriteInnerXml); } if ((formatter.WriteValue == null) && (_d.IncludeValue == true)) { formatter.WriteValue = new ToXmlFormatter.Method (obj.WriteValue); } if ((formatter.EndElement == null) && (_d.IncludeElementDeclaration == true)) { formatter.EndElement = new ToXmlFormatter.Method (obj.EndElement); } // Now call those implementations. ToXmlFormatter.ToXml(formatter, data, xmlWriter); }
/// <summary> /// Default implementation to use when printing media object resources. /// </summary> /// <param name="mo"></param> /// <param name="shouldPrintResources"></param> /// <param name="formatter"></param> /// <param name="data"></param> /// <param name="xmlWriter"></param> public static void WriteInnerXmlResources(IUPnPMedia mo, DelegateShouldPrintResources shouldPrintResources, ToXmlFormatter formatter, ToXmlData data, XmlTextWriter xmlWriter) { if (shouldPrintResources(data.DesiredProperties)) { // Set up the resource formatter to use the // default StartElement, EndElement, WriteInnerXml, and WriteValue // implementations. This stuff has no effect // if the WriteResource field has been assigned. ToXmlFormatter resFormatter = formatter; resFormatter.StartElement = null; resFormatter.EndElement = null; resFormatter.WriteInnerXml = null; resFormatter.WriteValue = null; // print the resources foreach (IMediaResource res in mo.MergedResources) { res.ToXml(resFormatter, data, xmlWriter); } } }
/// <summary> /// Although this class doesn't implement /// <see cref="ICdsElement"/> /// the intent of this method is exactly the same as /// <see cref="ICdsElement.ToXml"/>. /// </summary> /// <param name="data"> /// Argument must be a <see cref="ToXmlData"/> object. /// </param> /// <param name="xmlWriter"> /// <see cref="XmlTextWriter"/> object that will print the /// reprsentation in an XML compliant way. /// </param> /// <exception cref="InvalidCastException"> /// Thrown if "data" argument is not a <see cref="ToXmlData"/> object. /// </exception> public void ToXml(ToXmlData data, XmlTextWriter xmlWriter) { ToXmlData _d = data; IList list; ICdsElement ele; string tag_title = T[_DC.title]; string tag_class = T[_UPNP.Class]; list = this[tag_title]; ele = (ICdsElement)list[0]; xmlWriter.WriteElementString(tag_title, ele.StringValue); list = this[tag_class]; ele = (ICdsElement)list[0]; xmlWriter.WriteElementString(tag_class, ele.StringValue); if (_d.DesiredProperties != null) { ICollection properties = this.PropertyNames; foreach (string propName in properties) { if ( (_d.DesiredProperties.Count == 0) || (_d.DesiredProperties.Contains(propName)) ) { if ((propName != tag_title) && (propName != tag_class)) { list = this[propName]; if (list != null) { if (list.Count > 0) { foreach (ICdsElement val in list) { val.ToXml(ToXmlFormatter.DefaultFormatter, _d, xmlWriter); //val.ToXml(false, desiredProperties, xmlWriter); } } } } } } } }