cleaning up returned XML REST doclet (no more xsi, xsd)

0.6.0-stable
Dr Scofield 2008-05-29 13:55:01 +00:00
parent 91b75eda85
commit c2925dcd40
5 changed files with 66 additions and 4 deletions

View File

@ -129,7 +129,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
{ {
// complete region details requested // complete region details requested
XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
xs.Serialize(XmlWriter, details); xs.Serialize(XmlWriter, details, _xmlNs);
return XmlWriterResult; return XmlWriterResult;
} }

View File

@ -35,7 +35,7 @@ using OpenSim.Region.Environment.Scenes;
namespace OpenSim.ApplicationPlugins.Rest.Regions namespace OpenSim.ApplicationPlugins.Rest.Regions
{ {
[XmlRoot(ElementName="region")] [XmlRoot(ElementName="region", IsNullable = false)]
public class RegionDetails public class RegionDetails
{ {
public string region_name; public string region_name;

View File

@ -56,6 +56,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
[Extension("/OpenSim/Startup")] [Extension("/OpenSim/Startup")]
public partial class RestRegionPlugin : RestPlugin public partial class RestRegionPlugin : RestPlugin
{ {
private static XmlSerializerNamespaces _xmlNs;
#region overriding properties #region overriding properties
public override string Name public override string Name
{ {
@ -89,6 +91,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
} }
m_log.InfoFormat("{0} REST region plugin enabled", MsgID); m_log.InfoFormat("{0} REST region plugin enabled", MsgID);
_xmlNs = new XmlSerializerNamespaces();
_xmlNs.Add(String.Empty, String.Empty);
// add REST method handlers // add REST method handlers
AddRestStreamHandler("GET", "/regions/", GetHandler); AddRestStreamHandler("GET", "/regions/", GetHandler);
AddRestStreamHandler("POST", "/regions/", PostHandler); AddRestStreamHandler("POST", "/regions/", PostHandler);

View File

@ -66,7 +66,7 @@ namespace OpenSim.ApplicationPlugins.Rest
// which all REST URLs // which all REST URLs
// are living // are living
private StringWriter _sw = null; private StringWriter _sw = null;
private XmlTextWriter _xw = null; private RestXmlWriter _xw = null;
private string _godkey; private string _godkey;
private int _reqk; private int _reqk;
@ -159,7 +159,7 @@ namespace OpenSim.ApplicationPlugins.Rest
if (null == _xw) if (null == _xw)
{ {
_sw = new StringWriter(); _sw = new StringWriter();
_xw = new XmlTextWriter(_sw); _xw = new RestXmlWriter(_sw);
_xw.Formatting = Formatting.Indented; _xw.Formatting = Formatting.Indented;
} }
return _xw; } return _xw; }
@ -170,6 +170,7 @@ namespace OpenSim.ApplicationPlugins.Rest
get get
{ {
_xw.Flush(); _xw.Flush();
_xw.Close();
_xw = null; _xw = null;
return _sw.ToString(); return _sw.ToString();

View File

@ -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)
{
}
}
}