WebDAVProperty.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System.Xml;
  2. namespace Mtp2Dav.WebDAVSharp.Server._1d2086a502937936ebc6bfe19cfa15d855be1c31
  3. {
  4. /// <summary>
  5. /// This class implements the core WebDAV server.
  6. /// </summary>
  7. internal class WebDavProperty
  8. {
  9. /// <summary>
  10. /// This class implements the core WebDAV server.
  11. /// </summary>
  12. public string Name;
  13. /// <summary>
  14. /// This class implements the core WebDAV server.
  15. /// </summary>
  16. public string Namespace;
  17. /// <summary>
  18. /// This class implements the core WebDAV server.
  19. /// </summary>
  20. public string Value;
  21. /// <summary>
  22. /// Standard constructor
  23. /// </summary>
  24. public WebDavProperty()
  25. {
  26. Namespace = string.Empty;
  27. Name = string.Empty;
  28. Value = string.Empty;
  29. }
  30. /// <summary>
  31. /// Constructor for the WebDAVProperty class with "DAV:" as namespace and an empty value
  32. /// </summary>
  33. /// <param name="name">The name of the WebDAV property</param>
  34. public WebDavProperty(string name)
  35. {
  36. Name = name;
  37. Value = string.Empty;
  38. Namespace = "DAV:";
  39. }
  40. /// <summary>
  41. /// Constructor for the WebDAVProperty class with "DAV:" as namespace
  42. /// </summary>
  43. /// <param name="name">The name of the WebDAV property</param>
  44. /// <param name="value">The value of the WebDAV property</param>
  45. public WebDavProperty(string name, string value)
  46. {
  47. Name = name;
  48. Value = value;
  49. Namespace = "DAV:";
  50. }
  51. /// <summary>
  52. /// Constructor for the WebDAVProperty class
  53. /// </summary>
  54. /// <param name="name">The name of the WebDAV property</param>
  55. /// <param name="value">The value of the WebDAV property</param>
  56. /// <param name="ns">The namespace of the WebDAV property</param>
  57. public WebDavProperty(string name, string value, string ns)
  58. {
  59. Name = name;
  60. Value = value;
  61. Namespace = ns;
  62. }
  63. /// <summary>
  64. /// This class implements the core WebDAV server.
  65. /// </summary>
  66. /// <returns>
  67. /// A <see cref="System.String" /> that represents this instance.
  68. /// </returns>
  69. public override string ToString()
  70. {
  71. return StartString() + Value + EndString();
  72. }
  73. /// <summary>
  74. /// This class implements the core WebDAV server.
  75. /// </summary>
  76. /// <returns>The begin tag of an XML element as a string</returns>
  77. public string StartString()
  78. {
  79. if (Namespace == "DAV:")
  80. return "<D:" + Name + ">";
  81. return "<" + Name + " xmlns=\"" + Namespace + "\">";
  82. }
  83. /// <summary>
  84. /// This class implements the core WebDAV server.
  85. /// </summary>
  86. /// <returns>An empty XML element as a string</returns>
  87. public string EmptyString()
  88. {
  89. if (Namespace == "DAV:")
  90. return "<D:" + Name + "/>";
  91. return "<" + Name + " xmlns=\"" + Namespace + "\"/>";
  92. }
  93. /// <summary>
  94. /// This class implements the core WebDAV server.
  95. /// </summary>
  96. /// <returns>The closing tag of an XML element as a string</returns>
  97. public string EndString()
  98. {
  99. if (Namespace == "DAV:")
  100. return "</D:" + Name + ">";
  101. return "</" + Name + ">";
  102. }
  103. /// <summary>
  104. /// Creates an XmlDocumentFragment from the current WebDAVProperty
  105. /// </summary>
  106. /// <param name="doc">The XmlDocument where a XmlDocumentFragment is needed</param>
  107. /// <returns>
  108. /// The XmlDocumentFragment of the current WebDAVProperty object
  109. /// </returns>
  110. public XmlDocumentFragment ToXmlDocumentFragment(XmlDocument doc)
  111. {
  112. var fragment = doc.CreateDocumentFragment();
  113. fragment.InnerXml = ToString();
  114. return fragment;
  115. }
  116. /// <summary>
  117. /// reates an XmlElement from the current WebDAVProperty
  118. /// </summary>
  119. /// <param name="doc">The XmlDocument where a XmlElement is needed</param>
  120. /// <returns>
  121. /// The XmlElement of the current WebDAVProperty object
  122. /// </returns>
  123. public XmlElement ToXmlElement(XmlDocument doc)
  124. {
  125. // if the DocumentElement is not null, return the XmlElement with namespace
  126. if (doc.DocumentElement == null) return doc.CreateElement(Name);
  127. // Get the prefix of the namespace
  128. var prefix = doc.DocumentElement.GetPrefixOfNamespace(Namespace);
  129. // Create the element
  130. var element = doc.CreateElement(prefix, Name, Namespace);
  131. element.InnerText = Value;
  132. return element;
  133. // else, return XmlElement without namespace
  134. }
  135. }
  136. }