[mapguide-commits] r8565 - in trunk/Tools/Maestro: Maestro.Base/Editor Maestro.Editors/Generic OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.ObjectModels/IO

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Mar 10 05:37:21 PDT 2015


Author: jng
Date: 2015-03-10 05:37:20 -0700 (Tue, 10 Mar 2015)
New Revision: 8565

Removed:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utf8XmlWriter.cs
Modified:
   trunk/Tools/Maestro/Maestro.Base/Editor/FsEditorOptionPanel.cs
   trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/IO/Utf8XmlWriter.cs
Log:
- Remove duplicate Utf8XmlWriter class. The OSGeo.MapGuide.ObjectModels one is the "winner"
- Ensure that an XML prolog with utf-8 encoding is written when formatting an XML document in the generic XML editor
- Only validate well-formedness if validating a configuration document via the generic XML editor

Modified: trunk/Tools/Maestro/Maestro.Base/Editor/FsEditorOptionPanel.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Editor/FsEditorOptionPanel.cs	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/Maestro.Base/Editor/FsEditorOptionPanel.cs	2015-03-10 12:37:20 UTC (rev 8565)
@@ -114,6 +114,7 @@
         {
             var content = _fs.GetConfigurationContent(_edsvc.CurrentConnection);
             var dlg = new XmlEditorDialog(_edsvc);
+            dlg.OnlyValidateWellFormedness = true;
             dlg.XmlContent = content;
             if (dlg.ShowDialog() == DialogResult.OK)
             {

Modified: trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/Maestro.Editors/Generic/XmlEditorCtrl.cs	2015-03-10 12:37:20 UTC (rev 8565)
@@ -24,6 +24,7 @@
 using ICSharpCode.TextEditor.Document;
 using OSGeo.MapGuide.MaestroAPI;
 using OSGeo.MapGuide.ObjectModels;
+using OSGeo.MapGuide.ObjectModels.IO;
 using System;
 using System.Collections.Generic;
 using System.Drawing;
@@ -305,12 +306,25 @@
                 return;
 
             System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
-            doc.LoadXml(txtXmlContent.Text);
-            System.Text.StringBuilder sb = new System.Text.StringBuilder();
-            System.Xml.XmlWriter xw = System.Xml.XmlTextWriter.Create(sb, new System.Xml.XmlWriterSettings() { Indent = true });
-            doc.WriteTo(xw);
-            xw.Flush();
-            txtXmlContent.Text = sb.ToString();
+
+            using (var ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(txtXmlContent.Text)))
+            { 
+                using (var ms2 = Utility.RemoveUTF8BOM(ms))
+                {
+                    doc.Load(ms2);
+                }
+            }
+
+            using (var ms = new MemoryStream())
+            {
+                using (var uw = new Utf8XmlWriter(ms))
+                {
+                    uw.WriteStartDocument();
+                    doc.WriteTo(uw);
+                    uw.Flush();
+                }
+                txtXmlContent.Text = System.Text.Encoding.UTF8.GetString(ms.GetBuffer());
+            }
         }
 
         /// <summary>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2015-03-10 12:37:20 UTC (rev 8565)
@@ -239,7 +239,6 @@
     </Compile>
     <Compile Include="Tile\BatchSettings.cs" />
     <Compile Include="Tile\RenderThread.cs" />
-    <Compile Include="Utf8XmlWriter.cs" />
     <Compile Include="Utility.cs" />
     <Compile Include="WeakEventHandler.cs" />
     <Compile Include="XmlValidator.cs" />

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2015-03-10 12:37:20 UTC (rev 8565)
@@ -33,6 +33,7 @@
 using OSGeo.MapGuide.ObjectModels;
 using OSGeo.MapGuide.ObjectModels.Capabilities;
 using OSGeo.MapGuide.ObjectModels.Common;
+using OSGeo.MapGuide.ObjectModels.IO;
 using OSGeo.MapGuide.ObjectModels.LayerDefinition;
 using OSGeo.MapGuide.ObjectModels.LoadProcedure;
 using OSGeo.MapGuide.ObjectModels.MapDefinition;
@@ -42,7 +43,6 @@
 using System.Collections.Specialized;
 using System.IO;
 using System.Text;
-
 using ObjCommon = OSGeo.MapGuide.ObjectModels.Common;
 
 namespace OSGeo.MapGuide.MaestroAPI

Deleted: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utf8XmlWriter.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utf8XmlWriter.cs	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utf8XmlWriter.cs	2015-03-10 12:37:20 UTC (rev 8565)
@@ -1,88 +0,0 @@
-#region Disclaimer / License
-
-// Copyright (C) 2009, Kenneth Skovhede
-// http://www.hexad.dk, opensource at hexad.dk
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-//
-
-#endregion Disclaimer / License
-
-namespace OSGeo.MapGuide.MaestroAPI
-{
-    /// <summary>
-    /// Overrides the default XmlWriter, to ensure that the Xml is Utf8 and with whitespaces, as the MapGuide server requires Utf8
-    /// </summary>
-    public class Utf8XmlWriter : System.Xml.XmlTextWriter
-    {
-        /// <summary>
-        /// Initializes a new instance of the <see cref="Utf8XmlWriter"/> class.
-        /// </summary>
-        /// <param name="s">The s.</param>
-        public Utf8XmlWriter(System.IO.Stream s)
-            //This creation of the UTF8 encoder removes the BOM
-            //Which is required because MapGuide has trouble reading files with a BOM.
-            : base(s, new System.Text.UTF8Encoding(false, true))
-        {
-            Initialize();
-        }
-
-        private void Initialize()
-        {
-            //The MapGuide Studio parser is broken, it can't read Xml without whitespace :)
-            base.Formatting = System.Xml.Formatting.Indented;
-            base.Indentation = 2;
-            base.IndentChar = ' ';
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="Utf8XmlWriter"/> class.
-        /// </summary>
-        /// <param name="w">The TextWriter to write to. It is assumed that the TextWriter is already set to the correct encoding.</param>
-        public Utf8XmlWriter(System.IO.TextWriter w)
-            : base(w)
-        {
-            Initialize();
-        }
-
-        /// <summary>
-        /// Writes the XML declaration with the version "1.0".
-        /// </summary>
-        /// <exception cref="T:System.InvalidOperationException">
-        /// This is not the first write method called after the constructor.
-        /// </exception>
-        public override void WriteStartDocument()
-        {
-            Utf8WriteHeader();
-        }
-
-        /// <summary>
-        /// Writes the XML declaration with the version "1.0" and the standalone attribute.
-        /// </summary>
-        /// <param name="standalone">If true, it writes "standalone=yes"; if false, it writes "standalone=no".</param>
-        /// <exception cref="T:System.InvalidOperationException">
-        /// This is not the first write method called after the constructor.
-        /// </exception>
-        public override void WriteStartDocument(bool standalone)
-        {
-            Utf8WriteHeader();
-        }
-
-        private void Utf8WriteHeader()
-        {
-            base.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); //NOXLATE
-        }
-    }
-}
\ No newline at end of file

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/IO/Utf8XmlWriter.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/IO/Utf8XmlWriter.cs	2015-03-09 01:18:31 UTC (rev 8564)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/IO/Utf8XmlWriter.cs	2015-03-10 12:37:20 UTC (rev 8565)
@@ -30,7 +30,7 @@
     /// <summary>
     /// Overrides the default XmlWriter, to ensure that the Xml is Utf8 and with whitespaces, as the MapGuide server requires Utf8
     /// </summary>
-    internal class Utf8XmlWriter : System.Xml.XmlTextWriter
+    public class Utf8XmlWriter : System.Xml.XmlTextWriter
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="Utf8XmlWriter"/> class.



More information about the mapguide-commits mailing list