Add testcase for multiple missing IDs
[mono.git] / mcs / class / System.XML / System.Xml / DefaultXmlWriter.cs
1 //
2 // DefaultXmlWriter.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
8 //
9 using System;
10 using System.Globalization;
11 using System.Collections;
12
13 namespace System.Xml
14 {
15         internal class DefaultXmlWriter : XmlWriter
16         {
17                 XmlWriter writer;
18                 WriteState state = WriteState.Start;
19                 bool delegate_write_state;
20
21                 public DefaultXmlWriter (XmlWriter writer)
22                         : this (writer, true)
23                 {
24                 }
25
26                 public DefaultXmlWriter (XmlWriter writer, bool delegateWriteState)
27                 {
28                         this.writer = writer;
29                         delegate_write_state = delegateWriteState;
30                 }
31         
32                 protected XmlWriter Writer {
33                         get { return writer; }
34                 }
35
36                 private void CloseStartElement ()
37                 {
38                         state = WriteState.Content;
39                 }
40
41                 public override void Close ()
42                 {
43                         if (state != WriteState.Closed)
44                                 writer.Close ();
45                         state = WriteState.Closed;
46                 }
47         
48                 public override void Flush ()
49                 {
50                         writer.Flush ();
51                 }
52         
53                 public override string LookupPrefix (string ns)
54                 {
55                         return writer.LookupPrefix (ns);
56                 }
57         
58                 public override void WriteBase64 (byte [] buffer, int index, int count)
59                 {
60                         writer.WriteBase64 (buffer, index, count);
61                         state = WriteState.Content;
62                 }
63         
64                 public override void WriteBinHex (byte [] buffer, int index, int count)
65                 {
66                         writer.WriteBinHex (buffer, index, count);
67                         state = WriteState.Content;
68                 }
69         
70                 public override void WriteCData (string text)
71                 {
72                         writer.WriteCData (text);
73                         state = WriteState.Content;
74                 }
75         
76                 public override void WriteCharEntity (char ch)
77                 {
78                         writer.WriteCharEntity (ch);
79                         state = WriteState.Content;
80                 }
81         
82                 public override void WriteChars (char [] buffer, int index, int count)
83                 {
84                         writer.WriteChars (buffer, index, count);
85                         state = WriteState.Content;
86                 }
87         
88                 public override void WriteComment (string text)
89                 {
90                         writer.WriteComment (text);
91                         if (state == WriteState.Start)
92                                 state = WriteState.Prolog;
93                         else
94                                 state = WriteState.Content;
95                 }
96         
97                 public override void WriteDocType (string name, string pubid, string sysid, string subset)
98                 {
99                         writer.WriteDocType (name, pubid, sysid, subset);
100                         state = WriteState.Prolog;
101                 }
102         
103                 public override void WriteEndAttribute ()
104                 {
105                         writer.WriteEndAttribute ();
106                         state = WriteState.Element;
107                 }
108         
109                 public override void WriteEndDocument ()
110                 {
111                         writer.WriteEndDocument ();
112                         state = WriteState.Start;
113                 }
114         
115                 public override void WriteEndElement ()
116                 {
117                         writer.WriteEndElement ();
118                         state = WriteState.Content;
119                 }
120         
121                 public override void WriteEntityRef (string name)
122                 {
123                         writer.WriteEntityRef (name);
124                         state = WriteState.Content;
125                 }
126         
127                 public override void WriteFullEndElement ()
128                 {
129                         writer.WriteFullEndElement ();
130                         state = WriteState.Content;
131                 }
132         
133                 public override void WriteName (string name)
134                 {
135                         writer.WriteName (name);
136                         state = WriteState.Content;
137                 }
138         
139                 public override void WriteNmToken (string name)
140                 {
141                         writer.WriteNmToken (name);
142                         state = WriteState.Content;
143                 }
144         
145                 public override void WriteNode (XmlReader reader, bool defattr)
146                 {
147                         writer.WriteNode (reader, defattr);
148                 }
149         
150                 public override void WriteProcessingInstruction (string name, string text)
151                 {
152                         writer.WriteProcessingInstruction (name, text);
153                         if (state == WriteState.Start)
154                                 state = WriteState.Prolog;
155                         else
156                                 state = WriteState.Content;
157                 }
158         
159                 public override void WriteQualifiedName (string localName, string ns)
160                 {
161                         writer.WriteQualifiedName (localName, ns);
162                         state = WriteState.Content;
163                 }
164         
165                 public override void WriteRaw (string data)
166                 {
167                         writer.WriteRaw (data);
168                         if (state == WriteState.Start)
169                                 state = WriteState.Prolog;
170                         else
171                                 state = WriteState.Content;
172                 }
173         
174                 public override void WriteRaw (char [] buffer, int index, int count)
175                 {
176                         writer.WriteRaw (buffer, index, count);
177                         if (state == WriteState.Start)
178                                 state = WriteState.Prolog;
179                         else
180                                 state = WriteState.Content;
181                 }
182         
183                 public override void WriteStartAttribute (string prefix, string localName, string ns)
184                 {
185                         writer.WriteStartAttribute (prefix, localName, ns);
186                         state = WriteState.Attribute;
187                 }
188         
189                 public override void WriteStartDocument (bool standalone)
190                 {
191                         writer.WriteStartDocument (standalone);
192                         state = WriteState.Prolog;
193                 }
194         
195                 public override void WriteStartDocument ()
196                 {
197                         writer.WriteStartDocument ();
198                         state = WriteState.Prolog;
199                 }
200         
201                 public override void WriteStartElement (string prefix, string localName, string ns)
202                 {
203                         writer.WriteStartElement (prefix, localName, ns);
204                         state = WriteState.Element;
205                 }
206         
207                 public override void WriteString (string text)
208                 {
209                         writer.WriteString (text);
210                         state = WriteState.Content;
211                 }
212         
213                 public override void WriteSurrogateCharEntity (char lowChar, char highChar)
214                 {
215                         writer.WriteSurrogateCharEntity (lowChar, highChar);
216                         state = WriteState.Content;
217                 }
218         
219                 public override void WriteWhitespace (string ws)
220                 {
221                         writer.WriteWhitespace (ws);
222                         if (state == WriteState.Start)
223                                 state = WriteState.Prolog;
224                         else
225                                 state = WriteState.Content;
226                 }
227         
228                 public override WriteState WriteState {
229                         get {
230                                 if (delegate_write_state)
231                                         return writer.WriteState;
232                                 else
233                                         return state;
234                         }
235                 }
236         
237                 public override string XmlLang {
238                         get {
239                                 return writer.XmlLang;
240                         }
241                 }
242         
243                 public override XmlSpace XmlSpace {
244                         get {
245                                 return writer.XmlSpace;
246                         }
247                 }
248         }
249 }