2 // System.Configuration.ConfigXmlDocument
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #if NET_2_0 && CONFIGURATION_DEP
31 using System
.Configuration
.Internal
;
34 using System
.Security
;
35 using System
.Security
.Permissions
;
40 namespace System
.Configuration
42 [PermissionSet (SecurityAction
.LinkDemand
, Unrestricted
= true)]
43 public sealed class ConfigXmlDocument
: XmlDocument
, IConfigXmlNode
44 #if NET_2_0 && CONFIGURATION_DEP
52 public override XmlAttribute
CreateAttribute (string prefix
,
56 return new ConfigXmlAttribute (this, prefix
, localName
, namespaceUri
);
59 public override XmlCDataSection
CreateCDataSection (string data
)
61 return new ConfigXmlCDataSection (this, data
);
64 public override XmlComment
CreateComment (string comment
)
66 return new ConfigXmlComment (this, comment
);
69 public override XmlElement
CreateElement (string prefix
, string localName
, string namespaceUri
)
71 return new ConfigXmlElement (this, prefix
, localName
, namespaceUri
);
74 public override XmlSignificantWhitespace
CreateSignificantWhitespace (string data
)
76 return base.CreateSignificantWhitespace (data
);
79 public override XmlText
CreateTextNode (string text
)
81 return new ConfigXmlText (this, text
);
84 public override XmlWhitespace
CreateWhitespace (string data
)
86 return base.CreateWhitespace (data
);
89 public override void Load (string filename
)
91 XmlTextReader rd
= new XmlTextReader (filename
);
94 LoadSingleElement (filename
, rd
);
100 public void LoadSingleElement (string filename
, XmlTextReader sourceReader
)
103 lineNumber
= sourceReader
.LineNumber
;
104 string xml
= sourceReader
.ReadOuterXml();
105 reader
= new XmlTextReader (new StringReader (xml
), sourceReader
.NameTable
);
110 public string Filename
113 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
114 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
120 public int LineNumber
127 #if NET_2_0 && CONFIGURATION_DEP
128 string System
.Configuration
.Internal
.IConfigErrorInfo
.Filename
{
129 get { return Filename; }
132 int System
.Configuration
.Internal
.IConfigErrorInfo
.LineNumber
{
133 get { return LineNumber; }
137 string IConfigXmlNode
.Filename
{
138 get { return Filename; }
141 int IConfigXmlNode
.LineNumber
{
142 get { return LineNumber; }
146 // Wrappers for Xml* that just provide file name and line number addition
148 class ConfigXmlAttribute
: XmlAttribute
, IConfigXmlNode
149 #if NET_2_0 && CONFIGURATION_DEP
156 public ConfigXmlAttribute (ConfigXmlDocument document
,
160 : base (prefix
, localName
, namespaceUri
, document
)
162 fileName
= document
.fileName
;
163 lineNumber
= document
.LineNumber
;
166 public string Filename
169 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
170 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
176 public int LineNumber
184 class ConfigXmlCDataSection
: XmlCDataSection
, IConfigXmlNode
185 #if NET_2_0 && CONFIGURATION_DEP
192 public ConfigXmlCDataSection (ConfigXmlDocument document
, string data
)
193 : base (data
, document
)
195 fileName
= document
.fileName
;
196 lineNumber
= document
.LineNumber
;
199 public string Filename
202 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
203 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
209 public int LineNumber
217 class ConfigXmlComment
: XmlComment
, IConfigXmlNode
222 public ConfigXmlComment (ConfigXmlDocument document
, string comment
)
223 : base (comment
, document
)
225 fileName
= document
.fileName
;
226 lineNumber
= document
.LineNumber
;
229 public string Filename
232 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
233 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
239 public int LineNumber
247 class ConfigXmlElement
: XmlElement
, IConfigXmlNode
248 #if NET_2_0 && CONFIGURATION_DEP
255 public ConfigXmlElement (ConfigXmlDocument document
,
259 : base (prefix
, localName
, namespaceUri
, document
)
261 fileName
= document
.fileName
;
262 lineNumber
= document
.LineNumber
;
265 public string Filename
268 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
269 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
275 public int LineNumber
283 class ConfigXmlText
: XmlText
, IConfigXmlNode
284 #if NET_2_0 && CONFIGURATION_DEP
291 public ConfigXmlText (ConfigXmlDocument document
, string data
)
292 : base (data
, document
)
294 fileName
= document
.fileName
;
295 lineNumber
= document
.LineNumber
;
298 public string Filename
301 if ((fileName
!= null) && (fileName
.Length
> 0) && SecurityManager
.SecurityEnabled
) {
302 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, fileName
).Demand ();
308 public int LineNumber