fixing XmlWriter problem

0.6.6-post-fixes
Dr Scofield 2009-05-18 09:34:30 +00:00
parent 7a8a481f88
commit 2ad8710e19
5 changed files with 122 additions and 97 deletions

View File

@ -65,29 +65,33 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
public string GetHandlerRegions(OSHttpResponse httpResponse) 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) foreach (Scene s in App.SceneManager.Scenes)
{ {
XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty); rxw.WriteStartElement(String.Empty, "uuid", String.Empty);
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); rxw.WriteString(s.RegionInfo.RegionID.ToString());
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
} }
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
return XmlWriterResult; return rxw.ToString();
} }
protected string ShortRegionInfo(string key, string value) protected string ShortRegionInfo(string key, string value)
{ {
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
if (String.IsNullOrEmpty(value) || if (String.IsNullOrEmpty(value) ||
String.IsNullOrEmpty(key)) return null; String.IsNullOrEmpty(key)) return null;
XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); rxw.WriteStartElement(String.Empty, "region", String.Empty);
XmlWriter.WriteStartElement(String.Empty, key, String.Empty); rxw.WriteStartElement(String.Empty, key, String.Empty);
XmlWriter.WriteString(value); rxw.WriteString(value);
XmlWriter.WriteEndDocument(); rxw.WriteEndDocument();
return XmlWriterResult; return rxw.ToString();
} }
public string GetHandlerRegion(OSHttpResponse httpResponse, string param) public string GetHandlerRegion(OSHttpResponse httpResponse, string param)
@ -114,9 +118,10 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
if (1 == comps.Length) if (1 == comps.Length)
{ {
// complete region details requested // complete region details requested
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
XmlSerializer xs = new XmlSerializer(typeof(RegionDetails)); XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
xs.Serialize(XmlWriter, details, _xmlNs); xs.Serialize(rxw, details, _xmlNs);
return XmlWriterResult; return rxw.ToString();
} }
if (2 == comps.Length) if (2 == comps.Length)
@ -185,20 +190,22 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
int users = scene.GetAvatars().Count; int users = scene.GetAvatars().Count;
int objects = scene.Entities.Count - users; int objects = scene.Entities.Count - users;
XmlWriter.WriteStartElement(String.Empty, "region", String.Empty); RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
XmlWriter.WriteStartElement(String.Empty, "stats", String.Empty);
XmlWriter.WriteStartElement(String.Empty, "users", String.Empty); rxw.WriteStartElement(String.Empty, "region", String.Empty);
XmlWriter.WriteString(users.ToString()); rxw.WriteStartElement(String.Empty, "stats", String.Empty);
XmlWriter.WriteEndElement();
XmlWriter.WriteStartElement(String.Empty, "objects", String.Empty); rxw.WriteStartElement(String.Empty, "users", String.Empty);
XmlWriter.WriteString(objects.ToString()); rxw.WriteString(users.ToString());
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
XmlWriter.WriteEndDocument(); rxw.WriteStartElement(String.Empty, "objects", String.Empty);
rxw.WriteString(objects.ToString());
rxw.WriteEndElement();
return XmlWriterResult; rxw.WriteEndDocument();
return rxw.ToString();
} }
protected string RegionPrims(OSHttpResponse httpResponse, Scene scene, Vector3 min, Vector3 max) protected string RegionPrims(OSHttpResponse httpResponse, Scene scene, Vector3 min, Vector3 max)

View File

@ -66,78 +66,78 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
public string GetRegionInfoHandlerRegions(OSHttpResponse httpResponse) public string GetRegionInfoHandlerRegions(OSHttpResponse httpResponse)
{ {
RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
// regions info // regions info
XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty); rxw.WriteStartElement(String.Empty, "regions", String.Empty);
{ {
// regions info: number of regions // regions info: number of regions
XmlWriter.WriteStartAttribute(String.Empty, "number", String.Empty); rxw.WriteStartAttribute(String.Empty, "number", String.Empty);
XmlWriter.WriteValue(App.SceneManager.Scenes.Count); rxw.WriteValue(App.SceneManager.Scenes.Count);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
// regions info: max number of regions // 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) 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 else
{ {
XmlWriter.WriteValue(-1); rxw.WriteValue(-1);
} }
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
// regions info: region // regions info: region
foreach (Scene s in App.SceneManager.Scenes) 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); rxw.WriteStartAttribute(String.Empty, "uuid", String.Empty);
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); rxw.WriteString(s.RegionInfo.RegionID.ToString());
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "name", String.Empty); rxw.WriteStartAttribute(String.Empty, "name", String.Empty);
XmlWriter.WriteString(s.RegionInfo.RegionName); rxw.WriteString(s.RegionInfo.RegionName);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "x", String.Empty); rxw.WriteStartAttribute(String.Empty, "x", String.Empty);
XmlWriter.WriteValue(s.RegionInfo.RegionLocX); rxw.WriteValue(s.RegionInfo.RegionLocX);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "y", String.Empty); rxw.WriteStartAttribute(String.Empty, "y", String.Empty);
XmlWriter.WriteValue(s.RegionInfo.RegionLocY); rxw.WriteValue(s.RegionInfo.RegionLocY);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "external_hostname", String.Empty); rxw.WriteStartAttribute(String.Empty, "external_hostname", String.Empty);
XmlWriter.WriteString(s.RegionInfo.ExternalHostName); rxw.WriteString(s.RegionInfo.ExternalHostName);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "master_name", String.Empty); rxw.WriteStartAttribute(String.Empty, "master_name", String.Empty);
XmlWriter.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName)); rxw.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName));
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "master_uuid", String.Empty); rxw.WriteStartAttribute(String.Empty, "master_uuid", String.Empty);
XmlWriter.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString()); rxw.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString());
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "ip", String.Empty); rxw.WriteStartAttribute(String.Empty, "ip", String.Empty);
XmlWriter.WriteString(s.RegionInfo.InternalEndPoint.ToString()); rxw.WriteString(s.RegionInfo.InternalEndPoint.ToString());
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
int users = s.GetAvatars().Count; int users = s.GetAvatars().Count;
XmlWriter.WriteStartAttribute(String.Empty, "avatars", String.Empty); rxw.WriteStartAttribute(String.Empty, "avatars", String.Empty);
XmlWriter.WriteValue(users); rxw.WriteValue(users);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteStartAttribute(String.Empty, "objects", String.Empty); rxw.WriteStartAttribute(String.Empty, "objects", String.Empty);
XmlWriter.WriteValue(s.Entities.Count - users); rxw.WriteValue(s.Entities.Count - users);
XmlWriter.WriteEndAttribute(); rxw.WriteEndAttribute();
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
} }
} }
XmlWriter.WriteEndElement(); return rxw.ToString();
return XmlWriterResult;
} }
#endregion GET methods #endregion GET methods
} }

View File

@ -94,16 +94,18 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
public string CreateRegion(OSHttpRequest request, OSHttpResponse response) 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) foreach (Scene s in App.SceneManager.Scenes)
{ {
XmlWriter.WriteStartElement(String.Empty, "uuid", String.Empty); rxw.WriteStartElement(String.Empty, "uuid", String.Empty);
XmlWriter.WriteString(s.RegionInfo.RegionID.ToString()); rxw.WriteString(s.RegionInfo.RegionID.ToString());
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
} }
XmlWriter.WriteEndElement(); rxw.WriteEndElement();
return XmlWriterResult; return rxw.ToString();
} }
public string LoadPrims(string requestBody, OSHttpRequest request, OSHttpResponse response, Scene scene) public string LoadPrims(string requestBody, OSHttpRequest request, OSHttpResponse response, Scene scene)

View File

@ -53,8 +53,8 @@ namespace OpenSim.ApplicationPlugins.Rest
private string _prefix; // URL prefix below private string _prefix; // URL prefix below
// which all REST URLs // which all REST URLs
// are living // are living
private StringWriter _sw = null; // private StringWriter _sw = null;
private RestXmlWriter _xw = null; // private RestXmlWriter _xw = null;
private string _godkey; private string _godkey;
private int _reqk; private int _reqk;
@ -149,31 +149,31 @@ namespace OpenSim.ApplicationPlugins.Rest
/// </summary> /// </summary>
public abstract string ConfigName { get; } public abstract string ConfigName { get; }
public XmlTextWriter XmlWriter // public XmlTextWriter XmlWriter
{ // {
get // get
{ // {
if (null == _xw) // if (null == _xw)
{ // {
_sw = new StringWriter(); // _sw = new StringWriter();
_xw = new RestXmlWriter(_sw); // _xw = new RestXmlWriter(_sw);
_xw.Formatting = Formatting.Indented; // _xw.Formatting = Formatting.Indented;
} // }
return _xw; // return _xw;
} // }
} // }
public string XmlWriterResult // public string XmlWriterResult
{ // {
get // get
{ // {
_xw.Flush(); // _xw.Flush();
_xw.Close(); // _xw.Close();
_xw = null; // _xw = null;
return _sw.ToString(); // return _sw.ToString();
} // }
} // }
#endregion properties #endregion properties

View File

@ -33,6 +33,14 @@ namespace OpenSim.ApplicationPlugins.Rest
{ {
public class RestXmlWriter: XmlTextWriter public class RestXmlWriter: XmlTextWriter
{ {
private StringWriter m_sw = null;
public RestXmlWriter(StringWriter sw) : base(sw)
{
m_sw = sw;
Formatting = Formatting.Indented;
}
public RestXmlWriter(TextWriter textWriter) : base(textWriter) public RestXmlWriter(TextWriter textWriter) : base(textWriter)
{ {
} }
@ -52,5 +60,13 @@ namespace OpenSim.ApplicationPlugins.Rest
public override void WriteStartDocument(bool standalone) public override void WriteStartDocument(bool standalone)
{ {
} }
public override string ToString()
{
WriteEndElement();
Flush();
Close();
return m_sw.ToString();
}
} }
} }