123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System.Xml;
- namespace Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31
- {
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- internal class WebDavProperty
- {
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- public string Name;
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- public string Namespace;
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- public string Value;
- /// <summary>
- /// Standard constructor
- /// </summary>
- public WebDavProperty()
- {
- Namespace = string.Empty;
- Name = string.Empty;
- Value = string.Empty;
- }
- /// <summary>
- /// Constructor for the WebDAVProperty class with "DAV:" as namespace and an empty value
- /// </summary>
- /// <param name="name">The name of the WebDAV property</param>
- public WebDavProperty(string name)
- {
- Name = name;
- Value = string.Empty;
- Namespace = "DAV:";
- }
- /// <summary>
- /// Constructor for the WebDAVProperty class with "DAV:" as namespace
- /// </summary>
- /// <param name="name">The name of the WebDAV property</param>
- /// <param name="value">The value of the WebDAV property</param>
- public WebDavProperty(string name, string value)
- {
- Name = name;
- Value = value;
- Namespace = "DAV:";
- }
- /// <summary>
- /// Constructor for the WebDAVProperty class
- /// </summary>
- /// <param name="name">The name of the WebDAV property</param>
- /// <param name="value">The value of the WebDAV property</param>
- /// <param name="ns">The namespace of the WebDAV property</param>
- public WebDavProperty(string name, string value, string ns)
- {
- Name = name;
- Value = value;
- Namespace = ns;
- }
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- /// <returns>
- /// A <see cref="System.String" /> that represents this instance.
- /// </returns>
- public override string ToString()
- {
- return StartString() + Value + EndString();
- }
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- /// <returns>The begin tag of an XML element as a string</returns>
- public string StartString()
- {
- if (Namespace == "DAV:")
- return "<D:" + Name + ">";
- return "<" + Name + " xmlns=\"" + Namespace + "\">";
- }
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- /// <returns>An empty XML element as a string</returns>
- public string EmptyString()
- {
- if (Namespace == "DAV:")
- return "<D:" + Name + "/>";
- return "<" + Name + " xmlns=\"" + Namespace + "\"/>";
- }
- /// <summary>
- /// This class implements the core WebDAV server.
- /// </summary>
- /// <returns>The closing tag of an XML element as a string</returns>
- public string EndString()
- {
- if (Namespace == "DAV:")
- return "</D:" + Name + ">";
- return "</" + Name + ">";
- }
- /// <summary>
- /// Creates an XmlDocumentFragment from the current WebDAVProperty
- /// </summary>
- /// <param name="doc">The XmlDocument where a XmlDocumentFragment is needed</param>
- /// <returns>
- /// The XmlDocumentFragment of the current WebDAVProperty object
- /// </returns>
- public XmlDocumentFragment ToXmlDocumentFragment(XmlDocument doc)
- {
- var fragment = doc.CreateDocumentFragment();
- fragment.InnerXml = ToString();
- return fragment;
- }
- /// <summary>
- /// reates an XmlElement from the current WebDAVProperty
- /// </summary>
- /// <param name="doc">The XmlDocument where a XmlElement is needed</param>
- /// <returns>
- /// The XmlElement of the current WebDAVProperty object
- /// </returns>
- public XmlElement ToXmlElement(XmlDocument doc)
- {
- // if the DocumentElement is not null, return the XmlElement with namespace
- if (doc.DocumentElement == null) return doc.CreateElement(Name);
- // Get the prefix of the namespace
- var prefix = doc.DocumentElement.GetPrefixOfNamespace(Namespace);
- // Create the element
- var element = doc.CreateElement(prefix, Name, Namespace);
- element.InnerText = Value;
- return element;
- // else, return XmlElement without namespace
- }
- }
- }
|