using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Xml; namespace FastReport.Messaging.Xmpp { /// /// Represents the base class for XML stanzas used in XMPP. /// public abstract class Stanza { #region Fields private XmlElement data; private string jidFrom; private string jidTo; private string id; private CultureInfo language; #endregion // Fields #region Properties /// /// Gets the data of the stanza. /// public XmlElement Data { get { return data; } set { data = value; } } /// /// Gets or sets the JID of the sender. /// public string JidFrom { get { return jidFrom; } set { jidFrom = value; if (value == null) { data.RemoveAttribute("from"); } else { data.SetAttribute("from", value); } } } /// /// Gets or sets the JID of the recipient. /// public string JidTo { get { return jidTo; } set { jidTo = value; if (value == null) { data.RemoveAttribute("to"); } else { data.SetAttribute("to", value); } } } /// /// Gets or sets the ID of the stanza. /// public string Id { get { return id; } set { id = value; if (value == null) { data.RemoveAttribute("id"); } else { data.SetAttribute("id", value); } } } /// /// Gets or sets the language of the stanza. /// public CultureInfo Language { get { return language; } set { language = value; if (value == null) { data.RemoveAttribute("xml:lang"); } else { data.SetAttribute("xml:lang", value.Name); } } } #endregion // Properties #region Constructors /// /// Initializes a new instance of the class with specified parameters. /// /// The namespace of the stanza. /// The JID of the sender. /// The JID of the recipient. /// The ID of the stanza. /// The language of the stanza. /// The data of the stanza. public Stanza(string nspace, string jidFrom, string jidTo, string id, CultureInfo language, List data) { string name = GetType().Name.ToLowerInvariant(); Data = Xml.CreateElement(name, nspace); JidFrom = jidFrom; JidTo = jidTo; Id = id; Language = language; foreach (XmlElement e in data) { if (e != null) { Xml.AddChild(Data, e); } } } /// /// Initializes a new instance of the class using specified XmlElement instance. /// /// The XmlElement instance using like a data. public Stanza(XmlElement data) { this.data = data; } #endregion // Constructors #region Public Methods /// /// Converts stanza to string. /// /// String containing stanza value. public override string ToString() { return Xml.ToXmlString(data, false, true); } #endregion // Public Methods } }