2007-12-06 Atsushi Enomoto <atsushi@ximian.com>
[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 #if NET_2_0
32
33 using System;
34 using System.IO;
35 using System.Net;
36 using System.Xml.Schema;
37
38 #if !NET_2_1
39 using XsValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags;
40 #endif
41
42 namespace System.Xml
43 {
44         public sealed class XmlReaderSettings
45         {
46                 private bool checkCharacters;
47                 private bool closeInput;
48                 private ConformanceLevel conformance;
49                 private bool ignoreComments;
50                 private bool ignoreProcessingInstructions;
51                 private bool ignoreWhitespace;
52                 private int lineNumberOffset;
53                 private int linePositionOffset;
54                 private bool prohibitDtd;
55                 private XmlNameTable nameTable;
56 #if !NET_2_1
57                 private XmlSchemaSet schemas;
58                 private bool schemasNeedsInitialization;
59                 private XsValidationFlags validationFlags;
60                 private ValidationType validationType;
61 #endif
62                 private XmlResolver xmlResolver;
63
64                 public XmlReaderSettings ()
65                 {
66                         Reset ();
67                 }
68
69 #if !NET_2_1
70                 public event ValidationEventHandler ValidationEventHandler;
71 #endif
72
73                 public XmlReaderSettings Clone ()
74                 {
75                         return (XmlReaderSettings) MemberwiseClone ();
76                 }
77
78                 public void Reset ()
79                 {
80                         checkCharacters = true;
81                         closeInput = false; // ? not documented
82                         conformance = ConformanceLevel.Document;
83                         ignoreComments = false;
84                         ignoreProcessingInstructions = false;
85                         ignoreWhitespace = false;
86                         lineNumberOffset = 0;
87                         linePositionOffset = 0;
88                         prohibitDtd = true;
89 #if !NET_2_1
90                         schemas = null;
91                         schemasNeedsInitialization = true;
92                         validationFlags =
93                                 XsValidationFlags.ProcessIdentityConstraints |
94                                 XsValidationFlags.AllowXmlAttributes;
95                         validationType = ValidationType.None;
96 #endif
97                         xmlResolver = new XmlUrlResolver ();
98                 }
99
100                 public bool CheckCharacters {
101                         get { return checkCharacters; }
102                         set { checkCharacters = value; }
103                 }
104
105                 public bool CloseInput {
106                         get { return closeInput; }
107                         set { closeInput = value; }
108                 }
109
110                 public ConformanceLevel ConformanceLevel {
111                         get { return conformance; }
112                         set { conformance = value; }
113                 }
114
115                 public bool IgnoreComments {
116                         get { return ignoreComments; }
117                         set { ignoreComments = value; }
118                 }
119
120                 public bool IgnoreProcessingInstructions {
121                         get { return ignoreProcessingInstructions; }
122                         set { ignoreProcessingInstructions = value; }
123                 }
124
125                 public bool IgnoreWhitespace {
126                         get { return ignoreWhitespace; }
127                         set { ignoreWhitespace = value; }
128                 }
129
130                 public int LineNumberOffset {
131                         get { return lineNumberOffset; }
132                         set { lineNumberOffset = value; }
133                 }
134
135                 public int LinePositionOffset {
136                         get { return linePositionOffset; }
137                         set { linePositionOffset = value; }
138                 }
139
140                 public bool ProhibitDtd {
141                         get { return prohibitDtd; }
142                         set { prohibitDtd = value; }
143                 }
144
145                 // LAMESPEC: MSDN documentation says "An empty XmlNameTable
146                 // object" for default value, but XmlNameTable cannot be
147                 // instantiate. It actually returns null by default.
148                 public XmlNameTable NameTable {
149                         get { return nameTable; }
150                         set { nameTable = value; }
151                 }
152
153 #if !NET_2_1
154                 public XmlSchemaSet Schemas {
155                         get {
156                                 if (schemasNeedsInitialization) {
157                                         schemas = new XmlSchemaSet ();
158                                         schemasNeedsInitialization = false;
159                                 }
160                                 return schemas;
161                         }
162                         set {
163                                 schemas = value;
164                                 schemasNeedsInitialization = false;
165                         }
166                 }
167
168                 internal void OnValidationError (object o, ValidationEventArgs e)
169                 {
170                         if (ValidationEventHandler != null)
171                                 ValidationEventHandler (o, e);
172                         else if (e.Severity == XmlSeverityType.Error)
173                                 throw e.Exception;
174                 }
175
176                 internal void SetSchemas (XmlSchemaSet schemas)
177                 {
178                         this.schemas = schemas;
179                 }
180
181                 public XsValidationFlags ValidationFlags {
182                         get { return validationFlags; }
183                         set { validationFlags = value; }
184                 }
185
186                 public ValidationType ValidationType {
187                         get { return validationType; }
188                         set { validationType = value; }
189                 }
190 #endif
191
192                 public XmlResolver XmlResolver {
193                         internal get { return xmlResolver; }
194                         set { xmlResolver = value; }
195                 }
196         }
197 }
198
199 #endif