2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / XmlOutputter.cs
1 //
2 // XmlOutputter.cs
3 //
4 // Authors:
5 //      Oleg Tkachenko (oleg@tkachenko.com)
6 //      
7 // (C) 2003 Oleg Tkachenko
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.Xml;
33 using System.IO;
34 using System.Collections;
35
36 namespace Mono.Xml.Xsl {
37         /// <summary>
38         /// Outputter implementation for XML output method
39         /// </summary>
40         internal class XmlOutputter : Outputter {
41                 private XmlWriter _writer;
42                 private Hashtable _outputs;
43                 private XslOutput _currentOutput;
44
45                 public XmlOutputter(XmlWriter w, Hashtable o) {
46                         _writer = w;
47                         _outputs = o;
48                         _currentOutput = (XslOutput)o[String.Empty];
49                 }
50
51                 public XmlOutputter(TextWriter w, Hashtable o)
52                         : this(new XmlTextWriter(w), o) {}
53
54                 public override void WriteStartDocument() {
55                         if (_currentOutput != null && _currentOutput.OmitXmlDeclaration)
56                                 return;
57                         if (_currentOutput == null || _currentOutput.Standalone == null)
58                                 _writer.WriteStartDocument();
59                         else 
60                                 _writer.WriteStartDocument(_currentOutput.Standalone == "yes");         
61                 }
62                 
63                 public override void WriteEndDocument() {
64                         _writer.WriteEndDocument();             
65                 }
66
67                 public override void WriteStartElement(string prefix, string localName, string nsURI) {
68                         _writer.WriteStartElement(prefix, localName, nsURI);
69                 }
70
71                 public override void WriteEndElement() {
72                         _writer.WriteEndElement();
73                 }
74
75                 public override void WriteAttributeString(string prefix, string localName, string nsURI, string value) {
76                         _writer.WriteAttributeString(prefix, localName, nsURI, value);
77                 }
78
79                 public override void WriteStartAttribute(string prefix, string localName, string nsURI) {
80                         _writer.WriteStartAttribute(prefix, localName, nsURI);
81                 }
82
83                 public override void WriteEndAttribute() {
84                         _writer.WriteEndAttribute();    
85                 }
86
87                 public override void WriteComment(string text) {
88                         _writer.WriteComment(text);
89                 }
90
91                 public override void WriteProcessingInstruction(string name, string text) {
92                         _writer.WriteProcessingInstruction(name, text);
93                 }
94
95                 public override void WriteString(string text) {
96                         _writer.WriteString(text);
97                 }
98
99                 public override void WriteRaw(string data) {
100                         _writer.WriteRaw(data);
101                 }
102
103                 public override void Done () {
104                         _writer.Flush ();
105                 }
106         }
107 }