From 2ad8710e190b7543989cdb96a5268d21d2b5cefb Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Mon, 18 May 2009 09:34:30 +0000 Subject: fixing XmlWriter problem --- .../ApplicationPlugins/Rest/Regions/GETHandler.cs | 53 +++++++------ .../Rest/Regions/GETRegionInfoHandler.cs | 86 +++++++++++----------- .../ApplicationPlugins/Rest/Regions/POSTHandler.cs | 14 ++-- 3 files changed, 81 insertions(+), 72 deletions(-) (limited to 'OpenSim/ApplicationPlugins/Rest/Regions') diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs index 3fc7c06..ced3e5c 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETHandler.cs @@ -65,29 +65,33 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions public string GetHandlerRegions(OSHttpResponse httpResponse) { - XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); + + rxw.WriteStartElement(String.Empty, "regions", String.Empty); foreach (Scene s in App.SceneManager.Scenes) { - XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty); - XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); - XmlWriter.WriteEndElement(); + rxw.WriteStartElement(String.Empty, "uuid", String.Empty); + rxw.WriteString(s.RegionInfo.RegionID.ToString()); + rxw.WriteEndElement(); } - XmlWriter.WriteEndElement(); + rxw.WriteEndElement(); - return XmlWriterResult; + return rxw.ToString(); } protected string ShortRegionInfo(string key, string value) { + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); + if (String.IsNullOrEmpty(value) || String.IsNullOrEmpty(key)) return null; - XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); - XmlWriter.WriteStartElement(String.Empty, key, String.Empty); - XmlWriter.WriteString(value); - XmlWriter.WriteEndDocument(); + rxw.WriteStartElement(String.Empty, "region", String.Empty); + rxw.WriteStartElement(String.Empty, key, String.Empty); + rxw.WriteString(value); + rxw.WriteEndDocument(); - return XmlWriterResult; + return rxw.ToString(); } public string GetHandlerRegion(OSHttpResponse httpResponse, string param) @@ -114,9 +118,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions if (1 == comps.Length) { // complete region details requested + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); - xs.Serialize(XmlWriter, details, _xmlNs); - return XmlWriterResult; + xs.Serialize(rxw, details, _xmlNs); + return rxw.ToString(); } if (2 == comps.Length) @@ -185,20 +190,22 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions int users = scene.GetAvatars().Count; int objects = scene.Entities.Count - users; - XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); - XmlWriter.WriteStartElement(String.Empty, "stats", String.Empty); + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); + + rxw.WriteStartElement(String.Empty, "region", String.Empty); + rxw.WriteStartElement(String.Empty, "stats", String.Empty); - XmlWriter.WriteStartElement(String.Empty, "users", String.Empty); - XmlWriter.WriteString(users.ToString()); - XmlWriter.WriteEndElement(); + rxw.WriteStartElement(String.Empty, "users", String.Empty); + rxw.WriteString(users.ToString()); + rxw.WriteEndElement(); - XmlWriter.WriteStartElement(String.Empty, "objects", String.Empty); - XmlWriter.WriteString(objects.ToString()); - XmlWriter.WriteEndElement(); + rxw.WriteStartElement(String.Empty, "objects", String.Empty); + rxw.WriteString(objects.ToString()); + rxw.WriteEndElement(); - XmlWriter.WriteEndDocument(); + rxw.WriteEndDocument(); - return XmlWriterResult; + return rxw.ToString(); } protected string RegionPrims(OSHttpResponse httpResponse, Scene scene, Vector3 min, Vector3 max) diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/GETRegionInfoHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/GETRegionInfoHandler.cs index b49c5e9..5f83885 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/GETRegionInfoHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/GETRegionInfoHandler.cs @@ -66,78 +66,78 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions public string GetRegionInfoHandlerRegions(OSHttpResponse httpResponse) { + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); + // regions info - XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); + rxw.WriteStartElement(String.Empty, "regions", String.Empty); { // regions info: number of regions - XmlWriter.WriteStartAttribute(String.Empty, "number", String.Empty); - XmlWriter.WriteValue(App.SceneManager.Scenes.Count); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "number", String.Empty); + rxw.WriteValue(App.SceneManager.Scenes.Count); + rxw.WriteEndAttribute(); // regions info: max number of regions - XmlWriter.WriteStartAttribute(String.Empty, "max", String.Empty); + rxw.WriteStartAttribute(String.Empty, "max", String.Empty); if (App.ConfigSource.Source.Configs["RemoteAdmin"] != null) { - XmlWriter.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1)); + rxw.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1)); } else { - XmlWriter.WriteValue(-1); + rxw.WriteValue(-1); } - XmlWriter.WriteEndAttribute(); + rxw.WriteEndAttribute(); // regions info: region foreach (Scene s in App.SceneManager.Scenes) { - XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); + rxw.WriteStartElement(String.Empty, "region", String.Empty); - XmlWriter.WriteStartAttribute(String.Empty, "uuid", String.Empty); - XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "uuid", String.Empty); + rxw.WriteString(s.RegionInfo.RegionID.ToString()); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "name", String.Empty); - XmlWriter.WriteString(s.RegionInfo.RegionName); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "name", String.Empty); + rxw.WriteString(s.RegionInfo.RegionName); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "x", String.Empty); - XmlWriter.WriteValue(s.RegionInfo.RegionLocX); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "x", String.Empty); + rxw.WriteValue(s.RegionInfo.RegionLocX); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "y", String.Empty); - XmlWriter.WriteValue(s.RegionInfo.RegionLocY); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "y", String.Empty); + rxw.WriteValue(s.RegionInfo.RegionLocY); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "external_hostname", String.Empty); - XmlWriter.WriteString(s.RegionInfo.ExternalHostName); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "external_hostname", String.Empty); + rxw.WriteString(s.RegionInfo.ExternalHostName); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "master_name", String.Empty); - XmlWriter.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName)); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "master_name", String.Empty); + rxw.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName)); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "master_uuid", String.Empty); - XmlWriter.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString()); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "master_uuid", String.Empty); + rxw.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString()); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "ip", String.Empty); - XmlWriter.WriteString(s.RegionInfo.InternalEndPoint.ToString()); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "ip", String.Empty); + rxw.WriteString(s.RegionInfo.InternalEndPoint.ToString()); + rxw.WriteEndAttribute(); int users = s.GetAvatars().Count; - XmlWriter.WriteStartAttribute(String.Empty, "avatars", String.Empty); - XmlWriter.WriteValue(users); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "avatars", String.Empty); + rxw.WriteValue(users); + rxw.WriteEndAttribute(); - XmlWriter.WriteStartAttribute(String.Empty, "objects", String.Empty); - XmlWriter.WriteValue(s.Entities.Count - users); - XmlWriter.WriteEndAttribute(); + rxw.WriteStartAttribute(String.Empty, "objects", String.Empty); + rxw.WriteValue(s.Entities.Count - users); + rxw.WriteEndAttribute(); - XmlWriter.WriteEndElement(); + rxw.WriteEndElement(); } } - XmlWriter.WriteEndElement(); - - return XmlWriterResult; + return rxw.ToString(); } #endregion GET methods } diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs b/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs index 4b8bb5c..58cb102 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/POSTHandler.cs @@ -94,16 +94,18 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions public string CreateRegion(OSHttpRequest request, OSHttpResponse response) { - XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); + RestXmlWriter rxw = new RestXmlWriter(new StringWriter()); + + rxw.WriteStartElement(String.Empty, "regions", String.Empty); foreach (Scene s in App.SceneManager.Scenes) { - XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty); - XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); - XmlWriter.WriteEndElement(); + rxw.WriteStartElement(String.Empty, "uuid", String.Empty); + rxw.WriteString(s.RegionInfo.RegionID.ToString()); + rxw.WriteEndElement(); } - XmlWriter.WriteEndElement(); + rxw.WriteEndElement(); - return XmlWriterResult; + return rxw.ToString(); } public string LoadPrims(string requestBody, OSHttpRequest request, OSHttpResponse response, Scene scene) -- cgit v1.1