forked from WebDAVSharp/WebDAVSharp.Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebDAVProperty.cs
150 lines (136 loc) · 4.92 KB
/
WebDAVProperty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System.Xml;
namespace WebDAVSharp.Server
{
/// <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)
{
XmlDocumentFragment 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
string prefix = doc.DocumentElement.GetPrefixOfNamespace(Namespace);
// Create the element
XmlElement element = doc.CreateElement(prefix, Name, Namespace);
element.InnerText = Value;
return element;
// else, return XmlElement without namespace
}
}
}