2004-08-25 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / GenericOutputter.cs
index 2444d2e1721bfb18a98fb0cef5d45022ea931d22..17cbffb2668283c4075ff74987c3da2379e65661 100644 (file)
@@ -8,8 +8,30 @@
 // (C) 2003 Oleg Tkachenko, Atsushi Enomoto
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
+using System.Globalization;
 using System.Xml;
 using System.IO;
 using System.Text;
@@ -22,7 +44,7 @@ namespace Mono.Xml.Xsl
        /// Implements attributes dublicate checking, nemaspace stuff and
        /// choosing of right Emitter implementation.
        /// </summary>
-       public class GenericOutputter : Outputter {     
+       internal class GenericOutputter : Outputter {   
                private Hashtable _outputs;
                //Current xsl:output 
                private XslOutput _currentOutput;
@@ -70,7 +92,7 @@ namespace Mono.Xml.Xsl
                        : this (writer, outputs, encoding, false)
                {
                }
-
+                
                internal GenericOutputter (XmlWriter writer, Hashtable outputs, Encoding encoding, bool isVariable)
                        : this (outputs, encoding)
                {
@@ -85,6 +107,17 @@ namespace Mono.Xml.Xsl
                        this.pendingTextWriter = writer;
                }
 
+                
+                internal GenericOutputter (TextWriter writer, Hashtable outputs)
+                        : this (writer, outputs, null)
+                {
+                }
+
+                internal GenericOutputter (XmlWriter writer, Hashtable outputs)
+                        : this (writer, outputs, null)
+                {
+                }
+                
                private Emitter Emitter {
                        get {
                                if (_emitter == null)
@@ -97,8 +130,8 @@ namespace Mono.Xml.Xsl
                {
                        XslOutput xslOutput = (XslOutput)_outputs [String.Empty];
                        switch (xslOutput.Method) {
-                               case OutputMethod.Unknown: //TODO: handle xml vs html
-                                       if (localName != null && localName.ToLower () == "html" && ns == String.Empty)
+                               case OutputMethod.Unknown:
+                                       if (localName != null && String.Compare (localName, "html", true, CultureInfo.InvariantCulture) == 0 && ns == String.Empty)
                                                goto case OutputMethod.HTML;
                                        goto case OutputMethod.XML;
                                case OutputMethod.HTML:
@@ -114,7 +147,7 @@ namespace Mono.Xml.Xsl
                                        _emitter = new TextEmitter (pendingTextWriter);
                                        break;
                                case OutputMethod.Custom:
-                                       throw new NotImplementedException ("Custom output method is not implemented yet.");
+                                       throw new NotSupportedException ("Custom output method is not supported in this version.");
                        }
                        pendingTextWriter = null;
                }
@@ -138,10 +171,11 @@ namespace Mono.Xml.Xsl
                                        Attribute attr = pendingAttributes [i];
                                        string prefix = attr.Prefix;
                                        if (prefix == String.Empty)
-                                               prefix = _nsManager.LookupPrefix (attr.Namespace);
+                                               prefix = _nsManager.LookupPrefix (attr.Namespace, false);
                                        Emitter.WriteAttributeString (prefix, attr.LocalName, attr.Namespace, attr.Value);
                                }
-                               foreach (string prefix in _currentNsPrefixes) {
+                               for (int i = 0; i < _currentNsPrefixes.Count; i++) {
+                                       string prefix = (string) _currentNsPrefixes [i];
                                        string uri = _currentNamespaceDecls [prefix] as string;
                                        if (prefix != String.Empty)
                                                Emitter.WriteAttributeString ("xmlns", prefix, XmlNamespaceManager.XmlnsXmlns, uri);
@@ -262,14 +296,14 @@ namespace Mono.Xml.Xsl
 
                public override void WriteNamespaceDecl (string prefix, string nsUri)
                {
-                       if (_nsManager.LookupNamespace (prefix) == nsUri)
+                       if (_nsManager.LookupNamespace (prefix, false) == nsUri)
                                return;
 
                        if (prefix == String.Empty) {
                                //Default namespace
                                if (_nsManager.DefaultNamespace != nsUri)
                                        _nsManager.AddNamespace (prefix, nsUri);
-                       } else if (_nsManager.LookupPrefix (nsUri) == null)
+                       } else if (_nsManager.LookupPrefix (nsUri, false) == null)
                                //That's new namespace - add it to the collection
                                _nsManager.AddNamespace (prefix, nsUri);