aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMelanie2009-09-19 16:57:15 +0100
committerMelanie2009-09-19 16:57:15 +0100
commit97ebdd4607a3d6aa312adb07292b13ae2b120929 (patch)
tree037fb4e62450f4adbf94d5b2bf0041c6ef35356f
parentReorder prebuild and remove one unneeded backward reference (diff)
downloadopensim-SC-97ebdd4607a3d6aa312adb07292b13ae2b120929.zip
opensim-SC-97ebdd4607a3d6aa312adb07292b13ae2b120929.tar.gz
opensim-SC-97ebdd4607a3d6aa312adb07292b13ae2b120929.tar.bz2
opensim-SC-97ebdd4607a3d6aa312adb07292b13ae2b120929.tar.xz
Adding Xml serialization of Dictionary<string, object> where object
is either another Dictionary<string, object> or a value that is convertible to a string.
-rw-r--r--OpenSim/Server/Base/ServerUtils.cs72
-rw-r--r--prebuild.xml1
2 files changed, 73 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
index 0a36bbe..ae7ec0f 100644
--- a/OpenSim/Server/Base/ServerUtils.cs
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -183,5 +183,77 @@ namespace OpenSim.Server.Base
183 183
184 return result; 184 return result;
185 } 185 }
186
187 public static string BuildQueryString(Dictionary<string, string> data)
188 {
189 string qstring = String.Empty;
190
191 foreach(KeyValuePair<string, string> kvp in data)
192 {
193 string part;
194 if (kvp.Value != String.Empty)
195 {
196 part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
197 "=" + System.Web.HttpUtility.UrlEncode(kvp.Value);
198 }
199 else
200 {
201 part = System.Web.HttpUtility.UrlEncode(kvp.Key);
202 }
203
204 if (qstring != String.Empty)
205 qstring += "&";
206
207 qstring += part;
208 }
209
210 return qstring;
211 }
212
213 public static string BuildXmlResponse(Dictionary<string, object> data)
214 {
215 XmlDocument doc = new XmlDocument();
216
217 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
218 "", "");
219
220 doc.AppendChild(xmlnode);
221
222 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
223 "");
224
225 doc.AppendChild(rootElement);
226
227 BuildXmlData(rootElement, data);
228
229 return doc.InnerXml;
230 }
231
232 private static void BuildXmlData(XmlElement parent, Dictionary<string, object> data)
233 {
234 foreach (KeyValuePair<string, object> kvp in data)
235 {
236 XmlElement elem = parent.OwnerDocument.CreateElement("",
237 kvp.Key, "");
238
239 if (kvp.Value is Dictionary<string, object>)
240 {
241 XmlAttribute type = parent.OwnerDocument.CreateAttribute("",
242 "type", "");
243 type.Value = "List";
244
245 elem.Attributes.Append(type);
246
247 BuildXmlData(elem, (Dictionary<string, object>)kvp.Value);
248 }
249 else
250 {
251 elem.AppendChild(parent.OwnerDocument.CreateTextNode(
252 kvp.Value.ToString()));
253 }
254
255 parent.AppendChild(elem);
256 }
257 }
186 } 258 }
187} 259}
diff --git a/prebuild.xml b/prebuild.xml
index ecb0b62..2265b09 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -1213,6 +1213,7 @@
1213 <Reference name="OpenSim.Framework.Communications"/> 1213 <Reference name="OpenSim.Framework.Communications"/>
1214 <Reference name="OpenSim.Framework.Console"/> 1214 <Reference name="OpenSim.Framework.Console"/>
1215 <Reference name="OpenSim.Framework.Servers.HttpServer"/> 1215 <Reference name="OpenSim.Framework.Servers.HttpServer"/>
1216 <Reference name="OpenSim.Server.Base"/>
1216 <Reference name="Nini.dll" /> 1217 <Reference name="Nini.dll" />
1217 <Reference name="log4net.dll"/> 1218 <Reference name="log4net.dll"/>
1218 <Reference name="XMLRPC.dll" /> 1219 <Reference name="XMLRPC.dll" />