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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
//
// System.Web.UI.WebControls.Xml.cs
//
// Authors:
// Gaurav Vaish (gvaish@iitk.ac.in)
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (c) 2002 Ximian, Inc. (http://www.ximian.com)
// (C) Gaurav Vaish (2002)
// (C) 2003 Andreas Nahr
//
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Web;
using System.Web.UI;
namespace System.Web.UI.WebControls
{
[DefaultProperty("DocumentSource")]
[PersistChildren(false)]
[ControlBuilder (typeof (XmlBuilder))]
[Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
public class Xml : Control
{
static XslTransform defaultTransform;
XmlDocument document;
string documentContent;
string documentSource;
XslTransform transform;
XsltArgumentList transformArgumentList;
string transformSource;
XPathDocument xpathDoc;
static Xml ()
{
XmlTextReader reader = new XmlTextReader (new StringReader("<xsl:stylesheet version='1.0' " +
"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
"<xsl:template match=\"*\">" +
"<xsl:copy-of select=\".\"/>" +
"</xsl:template>" +
"</xsl:stylesheet>"));
defaultTransform = new XslTransform();
#if NET_1_0
defaultTransform.Load (reader);
#else
defaultTransform.Load (reader, null, null);
#endif
}
public Xml ()
{
}
[MonoTODO("security")]
private void LoadXmlDoc ()
{
if (documentContent != null && documentContent.Length > 0) {
document = new XmlDocument ();
document.LoadXml (documentContent);
return;
}
if (documentSource != null && documentSource.Length != 0) {
document = new XmlDocument ();
document.Load (documentSource);
}
}
[Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[WebSysDescription ("This is the XML document that is used for the XML Webcontrol.")]
public XmlDocument Document {
get {
if (document == null)
LoadXmlDoc ();
return document;
}
set {
documentSource = null;
documentContent = null;
xpathDoc = null;
document = value;
}
}
[Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[WebSysDescription ("The XML content that is transformed for the XML Webcontrol.")]
public string DocumentContent {
get {
return String.Empty;
}
set {
document = null;
xpathDoc = null;
documentContent = value;
}
}
[DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
[Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
[WebSysDescription ("The URL or the source of the XML content that is transformed for the XML Webcontrol.")]
public string DocumentSource {
get {
if (documentSource != null)
return documentSource;
return String.Empty;
}
set {
document = null;
documentContent = null;
xpathDoc = null;
documentSource = value;
}
}
[Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[WebSysDescription ("The XSL transform that is applied to this XML Webcontrol.")]
public XslTransform Transform {
get {
return transform;
}
set {
transformSource = null;
transform = value;
}
}
[DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
[Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
[WebSysDescription ("An URL specifying the source that is used for the XSL transformation.")]
public string TransformSource {
get {
if (transformSource != null)
return transformSource;
return String.Empty;
}
set {
transform = null;
transformSource = value;
}
}
[Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[WebSysDescription ("Arguments that are used by the XSL Transform.")]
public XsltArgumentList TransformArgumentList {
get { return transformArgumentList; }
set { transformArgumentList = value; }
}
protected override void AddParsedSubObject (object obj)
{
if (obj is LiteralControl) {
DocumentContent = ((LiteralControl) obj).Text;
return;
}
throw new HttpException (HttpRuntime.FormatResourceString (
"Cannot_Have_Children_of_Type",
"Xml",
GetType().Name));
}
[MonoTODO("security")]
private void LoadXpathDoc ()
{
if (documentContent != null && documentContent.Length > 0) {
xpathDoc = new XPathDocument (new StringReader (documentContent));
return;
}
if (documentSource != null && documentSource.Length != 0) {
xpathDoc = new XPathDocument (documentSource);
return;
}
}
[MonoTODO("security")]
private void LoadTransform ()
{
if (transform != null)
return;
if (transformSource != null && transformSource.Length != 0) {
transform = new XslTransform ();
transform.Load (MapPathSecure (transformSource));
}
}
protected override void Render(HtmlTextWriter output)
{
if (document == null) {
LoadXpathDoc();
}
LoadTransform();
if (document == null && xpathDoc == null) {
return;
}
if (transform == null) {
transform = defaultTransform;
}
if (document != null) {
#if NET_1_0
Transform.Transform(document, transformArgumentList, output);
#else
Transform.Transform(document, transformArgumentList, output, null);
#endif
return;
}
#if NET_1_0
Transform.Transform(xpathDoc, transformArgumentList, output);
#else
Transform.Transform(xpathDoc, transformArgumentList, output, null);
#endif
}
}
}
|