ccfaadfd2889119bbc404acabfe0f29c150774cc
[mono.git] / mcs / class / System.XML / System.Xml / XmlWriterSettings.cs
1 //
2 // XmlWriterSettings.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.Text;
36 using System.Xml.Schema;
37
38 namespace System.Xml
39 {
40         public sealed class XmlWriterSettings
41         {
42                 private bool checkCharacters;
43                 private bool closeOutput;
44                 private ConformanceLevel conformance;
45                 private Encoding encoding;
46                 private bool indent;
47                 private string indentChars;
48                 private string newLineChars;
49                 private bool newLineOnAttributes;
50                 private NewLineHandling newLineHandling;
51                 private bool omitXmlDeclaration;
52                 private XmlOutputMethod outputMethod;
53
54 #if NET_4_5
55                 private bool isReadOnly;
56                 private bool isAsync;
57 #endif
58
59                 public XmlWriterSettings ()
60                 {
61                         Reset ();
62                 }
63
64                 public XmlWriterSettings Clone ()
65                 {
66                         return (XmlWriterSettings) MemberwiseClone ();
67                 }
68
69                 // This might better be rewrite to "examine two settings and return the existing one or new one if required".
70                 internal void MergeFrom (XmlWriterSettings other)
71                 {
72                         CloseOutput |= other.CloseOutput;
73                         OmitXmlDeclaration |= other.OmitXmlDeclaration;
74                         if (ConformanceLevel == ConformanceLevel.Auto)
75                                 ConformanceLevel = other.ConformanceLevel;
76                 }
77
78                 public void Reset ()
79                 {
80                         checkCharacters = true;
81                         closeOutput = false; // ? not documented
82                         conformance = ConformanceLevel.Document;
83                         encoding = Encoding.UTF8;
84                         indent = false;
85                         indentChars = "  ";
86                         newLineChars = "\r\n";
87                         newLineOnAttributes = false;
88                         newLineHandling = NewLineHandling.Replace;
89                         omitXmlDeclaration = false;
90                         outputMethod = XmlOutputMethod.AutoDetect;
91 #if NET_4_5
92                         isAsync = false;
93 #endif
94                 }
95
96                 // It affects only on XmlTextWriter
97                 public bool CheckCharacters {
98                         get { return checkCharacters; }
99                         set { checkCharacters = value; }
100                 }
101
102                 // It affects only on XmlTextWriter
103                 public bool CloseOutput {
104                         get { return closeOutput; }
105                         set { closeOutput = value; }
106                 }
107
108                 // It affects only on XmlTextWriter????
109                 public ConformanceLevel ConformanceLevel {
110                         get { return conformance; }
111                         set { conformance = value; }
112                 }
113
114                 public Encoding Encoding {
115                         get { return encoding; }
116                         set { encoding = value; }
117                 }
118
119                 // It affects only on XmlTextWriter
120                 public bool Indent {
121                         get { return indent; }
122                         set { indent = value; }
123                 }
124
125                 // It affects only on XmlTextWriter
126                 public string IndentChars {
127                         get { return indentChars; }
128                         set { indentChars = value; }
129                 }
130
131                 // It affects only on XmlTextWriter
132                 public string NewLineChars {
133                         get { return newLineChars; }
134                         set {
135                                 if (value == null)
136                                         throw new ArgumentNullException ("value");
137                                 newLineChars = value;
138                         }
139                 }
140
141                 // It affects only on XmlTextWriter
142                 public bool NewLineOnAttributes {
143                         get { return newLineOnAttributes; }
144                         set { newLineOnAttributes = value; }
145                 }
146
147                 // It affects only on XmlTextWriter
148                 public NewLineHandling NewLineHandling {
149                         get { return newLineHandling; }
150                         set { newLineHandling = value; }
151                 }
152
153                 // It affects only on XmlTextWriter
154                 public bool OmitXmlDeclaration {
155                         get { return omitXmlDeclaration; }
156                         set { omitXmlDeclaration = value; }
157                 }
158
159                 // does it affect only on XmlTextWriter?
160                 public XmlOutputMethod OutputMethod {
161                         get { return outputMethod; }
162                         //set { outputMethod = value; }
163                 }
164
165 #if NET_4_0
166                 public
167 #else
168                 internal
169 #endif
170                 NamespaceHandling NamespaceHandling { get; set; }
171
172 #if NET_4_5
173                 internal void SetReadOnly ()
174                 {
175                         isReadOnly = true;
176                 }
177
178                 /*
179                  * FIXME: The .NET 4.5 runtime throws an exception when attempting to
180                  *        modify any of the properties after the XmlReader has been constructed.
181                  */
182                 void EnsureWritability ()
183                 {
184                         if (isReadOnly)
185                                 throw new InvalidOperationException ("XmlReaderSettings in read-only");
186                 }
187
188                 public bool Async {
189                         get { return isAsync; }
190                         set {
191                                 EnsureWritability ();
192                                 isAsync = value;
193                         }
194                 }
195 #endif
196
197         }
198 }
199
200 #endif