More working tests.
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail / XmlExtension.cs
blob9f9a830d358116ff5f44efd87fbfb412d9160ef1
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Views.Brail
17 using System.Collections;
18 using System.IO;
19 using System.Xml;
20 using Boo.Lang;
22 public class XmlExtension : IDslLanguageExtension
24 private readonly TextWriter output = null;
25 private readonly XmlWriter writer;
27 public XmlExtension(TextWriter output)
29 this.output = output;
30 writer = XmlWriter.Create(this.output);
33 public TextWriter Output
35 get { return output; }
38 #region IDslLanguageExtension Members
40 public void Tag(string name)
42 BlockTag(name, null, null);
45 public void Tag(string name, ICallable block)
47 BlockTag(name, null, block);
50 public void Tag(string name, IDictionary attributes, ICallable block)
52 BlockTag(name, attributes, block);
55 public void Flush()
57 writer.Flush();
60 #endregion
62 public void text(string text)
64 writer.WriteString(text);
67 private void BlockTag(string tag, IDictionary attributes, ICallable block)
69 writer.WriteStartElement(tag);
71 if (null != attributes)
73 foreach(DictionaryEntry entry in attributes)
75 writer.WriteAttributeString((string) entry.Key, (string) entry.Value);
79 if (block != null)
81 block.Call(null);
83 writer.WriteEndElement();