Kill MOONLIGHT from System.Xml.
[mono.git] / mcs / class / System.XML / System.Xml / XmlReaderSettings.cs
1 //
2 // XmlReaderSettings.cs
3 //
4 // Author:
5 //   Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // (C) 2004 Novell Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.IO;
33 using System.Net;
34 using System.Xml.Schema;
35
36 using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
37
38 namespace System.Xml
39 {
40         public sealed class XmlReaderSettings
41         {
42                 private bool checkCharacters;
43                 private bool closeInput;
44                 private ConformanceLevel conformance;
45                 private bool ignoreComments;
46                 private bool ignoreProcessingInstructions;
47                 private bool ignoreWhitespace;
48                 private int lineNumberOffset;
49                 private int linePositionOffset;
50                 private bool prohibitDtd;
51                 private XmlNameTable nameTable;
52                 private XmlSchemaSet schemas;
53                 private bool schemasNeedsInitialization;
54                 private XsValidationFlags validationFlags;
55                 private ValidationType validationType;
56                 private XmlResolver xmlResolver;
57 #if NET_4_0 || NET_2_1
58                 private DtdProcessing dtdProcessing;
59 #endif
60                 private long maxCharactersFromEntities;
61                 private long maxCharactersInDocument;
62
63 #if NET_4_5
64                 private bool isReadOnly;
65                 private bool isAsync;
66 #endif
67
68                 public XmlReaderSettings ()
69                 {
70                         Reset ();
71                 }
72
73                 public event ValidationEventHandler ValidationEventHandler;
74
75                 public XmlReaderSettings Clone ()
76                 {
77                         var clone = (XmlReaderSettings) MemberwiseClone ();
78 #if NET_4_5
79                         clone.isReadOnly = false;
80 #endif
81                         return clone;
82                 }
83
84                 public void Reset ()
85                 {
86                         checkCharacters = true;
87                         closeInput = false; // ? not documented
88                         conformance = ConformanceLevel.Document;
89                         ignoreComments = false;
90                         ignoreProcessingInstructions = false;
91                         ignoreWhitespace = false;
92                         lineNumberOffset = 0;
93                         linePositionOffset = 0;
94                         prohibitDtd = true;
95                         schemas = null;
96                         schemasNeedsInitialization = true;
97                         validationFlags =
98                                 XsValidationFlags.ProcessIdentityConstraints |
99                                 XsValidationFlags.AllowXmlAttributes;
100                         validationType = ValidationType.None;
101                         xmlResolver = new XmlUrlResolver ();
102 #if NET_4_5
103                         isAsync = false;
104 #endif
105                 }
106
107                 public bool CheckCharacters {
108                         get { return checkCharacters; }
109                         set { checkCharacters = value; }
110                 }
111
112                 public bool CloseInput {
113                         get { return closeInput; }
114                         set { closeInput = value; }
115                 }
116
117                 public ConformanceLevel ConformanceLevel {
118                         get { return conformance; }
119                         set { conformance = value; }
120                 }
121 #if NET_4_0 || NET_2_1
122                 public DtdProcessing DtdProcessing {
123                         get { return dtdProcessing; }
124                         set {
125                                 dtdProcessing = value;
126                                 prohibitDtd = (value == DtdProcessing.Prohibit);
127                         }
128                 }
129 #endif
130                 public long MaxCharactersFromEntities {
131                         get { return maxCharactersFromEntities; }
132                         set { maxCharactersFromEntities = value; }
133                 }
134
135                 [MonoTODO ("not used yet")]
136                 public long MaxCharactersInDocument {
137                         get { return maxCharactersInDocument; }
138                         set { maxCharactersInDocument = value; }
139                 }
140
141                 public bool IgnoreComments {
142                         get { return ignoreComments; }
143                         set { ignoreComments = value; }
144                 }
145
146                 public bool IgnoreProcessingInstructions {
147                         get { return ignoreProcessingInstructions; }
148                         set { ignoreProcessingInstructions = value; }
149                 }
150
151                 public bool IgnoreWhitespace {
152                         get { return ignoreWhitespace; }
153                         set { ignoreWhitespace = value; }
154                 }
155
156                 public int LineNumberOffset {
157                         get { return lineNumberOffset; }
158                         set { lineNumberOffset = value; }
159                 }
160
161                 public int LinePositionOffset {
162                         get { return linePositionOffset; }
163                         set { linePositionOffset = value; }
164                 }
165
166 #if NET_4_0
167                 [ObsoleteAttribute("Use DtdProcessing property instead")]
168 #endif
169                 public bool ProhibitDtd {
170                         get { return prohibitDtd; }
171                         set { prohibitDtd = value; }
172                 }
173
174                 // LAMESPEC: MSDN documentation says "An empty XmlNameTable
175                 // object" for default value, but XmlNameTable cannot be
176                 // instantiate. It actually returns null by default.
177                 public XmlNameTable NameTable {
178                         get { return nameTable; }
179                         set { nameTable = value; }
180                 }
181
182                 public XmlSchemaSet Schemas {
183                         get {
184                                 if (schemasNeedsInitialization) {
185                                         schemas = new XmlSchemaSet ();
186                                         schemasNeedsInitialization = false;
187                                 }
188                                 return schemas;
189                         }
190                         set {
191                                 schemas = value;
192                                 schemasNeedsInitialization = false;
193                         }
194                 }
195
196                 internal void OnValidationError (object o, ValidationEventArgs e)
197                 {
198                         if (ValidationEventHandler != null)
199                                 ValidationEventHandler (o, e);
200                         else if (e.Severity == XmlSeverityType.Error)
201                                 throw e.Exception;
202                 }
203
204                 internal void SetSchemas (XmlSchemaSet schemas)
205                 {
206                         this.schemas = schemas;
207                 }
208
209                 public XsValidationFlags ValidationFlags {
210                         get { return validationFlags; }
211                         set { validationFlags = value; }
212                 }
213
214                 public ValidationType ValidationType {
215                         get { return validationType; }
216                         set { validationType = value; }
217                 }
218
219                 public XmlResolver XmlResolver {
220                         internal get { return xmlResolver; }
221                         set { xmlResolver = value; }
222                 }
223
224 #if NET_4_5
225                 internal void SetReadOnly ()
226                 {
227                         isReadOnly = true;
228                 }
229
230                 /*
231                  * FIXME: The .NET 4.5 runtime throws an exception when attempting to
232                  *        modify any of the properties after the XmlReader has been constructed.
233                  */
234                 void EnsureWritability ()
235                 {
236                         if (isReadOnly)
237                                 throw new InvalidOperationException ("XmlReaderSettings in read-only");
238                 }
239
240                 public bool Async {
241                         get { return isAsync; }
242                         set {
243                                 EnsureWritability ();
244                                 isAsync = value;
245                         }
246                 }
247 #endif
248         }
249 }