From c2925dcd404312b1751a03045ddcd35a7c84cd58 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Thu, 29 May 2008 13:55:01 +0000 Subject: cleaning up returned XML REST doclet (no more xsi, xsd) --- .../ApplicationPlugins/Rest/Regions/GETHandler.cs | 2 +- .../Rest/Regions/RegionDetails.cs | 2 +- .../Rest/Regions/RestRegionPlugin.cs | 5 ++ OpenSim/ApplicationPlugins/Rest/RestPlugin.cs | 5 +- OpenSim/ApplicationPlugins/Rest/RestXmlWriter.cs | 56 ++++++++++++++++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 OpenSim/ApplicationPlugins/Rest/RestXmlWriter.cs diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs index 81eb5bd..a605d09 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs @@ -129,7 +129,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions { // complete region details requested XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); - xs.Serialize(XmlWriter, details); + xs.Serialize(XmlWriter, details, _xmlNs); return XmlWriterResult; } diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs index 681b99f..67af7b5 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/RegionDetails.cs @@ -35,7 +35,7 @@ using OpenSim.Region.Environment.Scenes; namespace OpenSim.ApplicationPlugins.Rest.Regions { - [XmlRoot(ElementName="region")] + [XmlRoot(ElementName="region", IsNullable = false)] public class RegionDetails { public string region_name; diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs index 24bed99..fa5f117 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs @@ -56,6 +56,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions [Extension("/OpenSim/Startup")] public partial class RestRegionPlugin : RestPlugin { + private static XmlSerializerNamespaces _xmlNs; + #region overriding properties public override string Name { @@ -88,6 +90,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions return; } m_log.InfoFormat("{0} REST region plugin enabled", MsgID); + + _xmlNs = new XmlSerializerNamespaces(); + _xmlNs.Add(String.Empty, String.Empty); // add REST method handlers AddRestStreamHandler("GET", "/regions/", GetHandler); diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs index e395840..8373ea2 100644 --- a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs +++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs @@ -66,7 +66,7 @@ namespace OpenSim.ApplicationPlugins.Rest // which all REST URLs // are living private StringWriter _sw = null; - private XmlTextWriter _xw = null; + private RestXmlWriter _xw = null; private string _godkey; private int _reqk; @@ -159,7 +159,7 @@ namespace OpenSim.ApplicationPlugins.Rest if (null == _xw) { _sw = new StringWriter(); - _xw = new XmlTextWriter(_sw); + _xw = new RestXmlWriter(_sw); _xw.Formatting = Formatting.Indented; } return _xw; } @@ -170,6 +170,7 @@ namespace OpenSim.ApplicationPlugins.Rest get { _xw.Flush(); + _xw.Close(); _xw = null; return _sw.ToString(); diff --git a/OpenSim/ApplicationPlugins/Rest/RestXmlWriter.cs b/OpenSim/ApplicationPlugins/Rest/RestXmlWriter.cs new file mode 100644 index 0000000..da37647 --- /dev/null +++ b/OpenSim/ApplicationPlugins/Rest/RestXmlWriter.cs @@ -0,0 +1,56 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.IO; +using System.Text; +using System.Xml; + +namespace OpenSim.ApplicationPlugins.Rest +{ + public class RestXmlWriter: XmlTextWriter + { + public RestXmlWriter(TextWriter textWriter) : base(textWriter) + { + } + + public RestXmlWriter(Stream stream) : this(stream, Encoding.UTF8) + { + } + + public RestXmlWriter(Stream stream, Encoding enc) : base(stream, enc) + { + } + + public override void WriteStartDocument() + { + } + + public override void WriteStartDocument(bool standalone) + { + } + } +} -- cgit v1.1