diff options
author | Diva Canto | 2015-05-05 20:59:09 -0700 |
---|---|---|
committer | Diva Canto | 2015-05-05 20:59:09 -0700 |
commit | 1abbad71b4603245e5481c11e3ce55f57b64935f (patch) | |
tree | 694b750495216edbb16a2822a546e7617eff2c66 /OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs | |
parent | Revert "Patch llCastRay fully-simplified to V2." for further review. (diff) | |
download | opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.zip opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.gz opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.bz2 opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.xz |
Refactored some code that is used in two different dlls related to SOP rewriting. Also added some unit tests that relate to mantis #7514
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs | 184 |
1 files changed, 183 insertions, 1 deletions
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 6debf65..64de18b 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs | |||
@@ -125,7 +125,8 @@ namespace OpenSim.Framework.Serialization.External | |||
125 | /// <param name="userService">The service for retrieving user account information</param> | 125 | /// <param name="userService">The service for retrieving user account information</param> |
126 | /// <param name="scopeID">The scope of the user account information (Grid ID)</param> | 126 | /// <param name="scopeID">The scope of the user account information (Grid ID)</param> |
127 | /// <returns>The SceneObjectPart represented in XML2</returns> | 127 | /// <returns>The SceneObjectPart represented in XML2</returns> |
128 | public static string RewriteSOP(string xml, string homeURL, IUserAccountService userService, UUID scopeID) | 128 | [Obsolete("This method is deprecated. Use RewriteSOP instead.")] |
129 | public static string RewriteSOP_Old(string xml, string homeURL, IUserAccountService userService, UUID scopeID) | ||
129 | { | 130 | { |
130 | if (xml == string.Empty || homeURL == string.Empty || userService == null) | 131 | if (xml == string.Empty || homeURL == string.Empty || userService == null) |
131 | return xml; | 132 | return xml; |
@@ -173,6 +174,187 @@ namespace OpenSim.Framework.Serialization.External | |||
173 | } | 174 | } |
174 | } | 175 | } |
175 | 176 | ||
177 | /// <summary> | ||
178 | /// Takes a XML representation of a SceneObjectPart and returns another XML representation | ||
179 | /// with creator data added to it. | ||
180 | /// </summary> | ||
181 | /// <param name="xml">The SceneObjectPart represented in XML2</param> | ||
182 | /// <param name="sceneName">An identifier for the component that's calling this function</param> | ||
183 | /// <param name="homeURL">The URL of the user agents service (home) for the creator</param> | ||
184 | /// <param name="userService">The service for retrieving user account information</param> | ||
185 | /// <param name="scopeID">The scope of the user account information (Grid ID)</param> | ||
186 | /// <returns>The SceneObjectPart represented in XML2</returns> | ||
187 | public static string RewriteSOP(string xmlData, string sceneName, string homeURL, IUserAccountService userService, UUID scopeID) | ||
188 | { | ||
189 | // Console.WriteLine("Input XML [{0}]", xmlData); | ||
190 | if (xmlData == string.Empty || homeURL == string.Empty || userService == null) | ||
191 | return xmlData; | ||
192 | |||
193 | using (StringWriter sw = new StringWriter()) | ||
194 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
195 | using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) | ||
196 | using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) | ||
197 | { | ||
198 | TransformXml(reader, writer, sceneName, homeURL, userService, scopeID); | ||
199 | |||
200 | // Console.WriteLine("Output: [{0}]", sw.ToString()); | ||
201 | |||
202 | return sw.ToString(); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | protected static void TransformXml(XmlReader reader, XmlWriter writer, string sceneName, string homeURI, IUserAccountService userAccountService, UUID scopeID) | ||
207 | { | ||
208 | // m_log.DebugFormat("[HG ASSET MAPPER]: Transforming XML"); | ||
209 | |||
210 | int sopDepth = -1; | ||
211 | UserAccount creator = null; | ||
212 | bool hasCreatorData = false; | ||
213 | |||
214 | while (reader.Read()) | ||
215 | { | ||
216 | // Console.WriteLine("Depth: {0}, name {1}", reader.Depth, reader.Name); | ||
217 | |||
218 | switch (reader.NodeType) | ||
219 | { | ||
220 | case XmlNodeType.Attribute: | ||
221 | // Console.WriteLine("FOUND ATTRIBUTE {0}", reader.Name); | ||
222 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
223 | break; | ||
224 | |||
225 | case XmlNodeType.CDATA: | ||
226 | writer.WriteCData(reader.Value); | ||
227 | break; | ||
228 | |||
229 | case XmlNodeType.Comment: | ||
230 | writer.WriteComment(reader.Value); | ||
231 | break; | ||
232 | |||
233 | case XmlNodeType.DocumentType: | ||
234 | writer.WriteDocType(reader.Name, reader.Value, null, null); | ||
235 | break; | ||
236 | |||
237 | case XmlNodeType.Element: | ||
238 | // m_log.DebugFormat("Depth {0} at element {1}", reader.Depth, reader.Name); | ||
239 | |||
240 | writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); | ||
241 | |||
242 | if (reader.HasAttributes) | ||
243 | { | ||
244 | while (reader.MoveToNextAttribute()) | ||
245 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
246 | |||
247 | reader.MoveToElement(); | ||
248 | } | ||
249 | |||
250 | if (reader.LocalName == "SceneObjectPart") | ||
251 | { | ||
252 | if (sopDepth < 0) | ||
253 | { | ||
254 | sopDepth = reader.Depth; | ||
255 | // m_log.DebugFormat("[HG ASSET MAPPER]: Set sopDepth to {0}", sopDepth); | ||
256 | } | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | if (sopDepth >= 0 && reader.Depth == sopDepth + 1) | ||
261 | { | ||
262 | if (reader.Name == "CreatorID") | ||
263 | { | ||
264 | reader.Read(); | ||
265 | if (reader.NodeType == XmlNodeType.Element && reader.Name == "Guid" || reader.Name == "UUID") | ||
266 | { | ||
267 | reader.Read(); | ||
268 | |||
269 | if (reader.NodeType == XmlNodeType.Text) | ||
270 | { | ||
271 | UUID uuid = UUID.Zero; | ||
272 | UUID.TryParse(reader.Value, out uuid); | ||
273 | creator = userAccountService.GetUserAccount(scopeID, uuid); | ||
274 | writer.WriteElementString("UUID", reader.Value); | ||
275 | reader.Read(); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | // If we unexpected run across mixed content in this node, still carry on | ||
280 | // transforming the subtree (this replicates earlier behaviour). | ||
281 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | // If we unexpected run across mixed content in this node, still carry on | ||
287 | // transforming the subtree (this replicates earlier behaviour). | ||
288 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
289 | } | ||
290 | } | ||
291 | else if (reader.Name == "CreatorData") | ||
292 | { | ||
293 | reader.Read(); | ||
294 | if (reader.NodeType == XmlNodeType.Text) | ||
295 | { | ||
296 | hasCreatorData = true; | ||
297 | writer.WriteString(reader.Value); | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | // If we unexpected run across mixed content in this node, still carry on | ||
302 | // transforming the subtree (this replicates earlier behaviour). | ||
303 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | |||
309 | if (reader.IsEmptyElement) | ||
310 | { | ||
311 | // m_log.DebugFormat("[HG ASSET MAPPER]: Writing end for empty element {0}", reader.Name); | ||
312 | writer.WriteEndElement(); | ||
313 | } | ||
314 | |||
315 | break; | ||
316 | |||
317 | case XmlNodeType.EndElement: | ||
318 | // m_log.DebugFormat("Depth {0} at EndElement", reader.Depth); | ||
319 | if (sopDepth == reader.Depth) | ||
320 | { | ||
321 | if (!hasCreatorData && creator != null) | ||
322 | writer.WriteElementString(reader.Prefix, "CreatorData", reader.NamespaceURI, string.Format("{0};{1} {2}", homeURI, creator.FirstName, creator.LastName)); | ||
323 | |||
324 | // m_log.DebugFormat("[HG ASSET MAPPER]: Reset sopDepth"); | ||
325 | sopDepth = -1; | ||
326 | creator = null; | ||
327 | hasCreatorData = false; | ||
328 | } | ||
329 | writer.WriteEndElement(); | ||
330 | break; | ||
331 | |||
332 | case XmlNodeType.EntityReference: | ||
333 | writer.WriteEntityRef(reader.Name); | ||
334 | break; | ||
335 | |||
336 | case XmlNodeType.ProcessingInstruction: | ||
337 | writer.WriteProcessingInstruction(reader.Name, reader.Value); | ||
338 | break; | ||
339 | |||
340 | case XmlNodeType.Text: | ||
341 | writer.WriteString(reader.Value); | ||
342 | break; | ||
343 | |||
344 | case XmlNodeType.XmlDeclaration: | ||
345 | // For various reasons, not all serializations have xml declarations (or consistent ones) | ||
346 | // and as it's embedded inside a byte stream we don't need it anyway, so ignore. | ||
347 | break; | ||
348 | |||
349 | default: | ||
350 | m_log.WarnFormat( | ||
351 | "[HG ASSET MAPPER]: Unrecognized node {0} in asset XML transform in {1}", | ||
352 | reader.NodeType, sceneName); | ||
353 | break; | ||
354 | } | ||
355 | } | ||
356 | } | ||
357 | |||
176 | public static string CalcCreatorData(string homeURL, string name) | 358 | public static string CalcCreatorData(string homeURL, string name) |
177 | { | 359 | { |
178 | return homeURL + ";" + name; | 360 | return homeURL + ";" + name; |