diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | 209 |
1 files changed, 2 insertions, 207 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index c2010b1..f54298c 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | |||
@@ -35,6 +35,7 @@ using System.Xml; | |||
35 | using log4net; | 35 | using log4net; |
36 | using OpenMetaverse; | 36 | using OpenMetaverse; |
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Serialization.External; | ||
38 | 39 | ||
39 | using OpenSim.Region.Framework.Scenes; | 40 | using OpenSim.Region.Framework.Scenes; |
40 | using OpenSim.Region.Framework.Scenes.Serialization; | 41 | using OpenSim.Region.Framework.Scenes.Serialization; |
@@ -189,217 +190,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
189 | return Utils.StringToBytes(RewriteSOP(xml)); | 190 | return Utils.StringToBytes(RewriteSOP(xml)); |
190 | } | 191 | } |
191 | 192 | ||
192 | protected void TransformXml(XmlReader reader, XmlWriter writer) | ||
193 | { | ||
194 | // m_log.DebugFormat("[HG ASSET MAPPER]: Transforming XML"); | ||
195 | |||
196 | int sopDepth = -1; | ||
197 | UserAccount creator = null; | ||
198 | bool hasCreatorData = false; | ||
199 | |||
200 | while (reader.Read()) | ||
201 | { | ||
202 | // Console.WriteLine("Depth: {0}, name {1}", reader.Depth, reader.Name); | ||
203 | |||
204 | switch (reader.NodeType) | ||
205 | { | ||
206 | case XmlNodeType.Attribute: | ||
207 | // Console.WriteLine("FOUND ATTRIBUTE {0}", reader.Name); | ||
208 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
209 | break; | ||
210 | |||
211 | case XmlNodeType.CDATA: | ||
212 | writer.WriteCData(reader.Value); | ||
213 | break; | ||
214 | |||
215 | case XmlNodeType.Comment: | ||
216 | writer.WriteComment(reader.Value); | ||
217 | break; | ||
218 | |||
219 | case XmlNodeType.DocumentType: | ||
220 | writer.WriteDocType(reader.Name, reader.Value, null, null); | ||
221 | break; | ||
222 | |||
223 | case XmlNodeType.Element: | ||
224 | // m_log.DebugFormat("Depth {0} at element {1}", reader.Depth, reader.Name); | ||
225 | |||
226 | writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); | ||
227 | |||
228 | if (reader.HasAttributes) | ||
229 | { | ||
230 | while (reader.MoveToNextAttribute()) | ||
231 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
232 | |||
233 | reader.MoveToElement(); | ||
234 | } | ||
235 | |||
236 | if (reader.LocalName == "SceneObjectPart") | ||
237 | { | ||
238 | if (sopDepth < 0) | ||
239 | { | ||
240 | sopDepth = reader.Depth; | ||
241 | // m_log.DebugFormat("[HG ASSET MAPPER]: Set sopDepth to {0}", sopDepth); | ||
242 | } | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | if (sopDepth >= 0 && reader.Depth == sopDepth + 1) | ||
247 | { | ||
248 | if (reader.Name == "CreatorID") | ||
249 | { | ||
250 | reader.Read(); | ||
251 | if (reader.NodeType == XmlNodeType.Element && reader.Name == "Guid" || reader.Name == "UUID") | ||
252 | { | ||
253 | reader.Read(); | ||
254 | |||
255 | if (reader.NodeType == XmlNodeType.Text) | ||
256 | { | ||
257 | UUID uuid = UUID.Zero; | ||
258 | UUID.TryParse(reader.Value, out uuid); | ||
259 | creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); | ||
260 | writer.WriteElementString("UUID", reader.Value); | ||
261 | reader.Read(); | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | // If we unexpected run across mixed content in this node, still carry on | ||
266 | // transforming the subtree (this replicates earlier behaviour). | ||
267 | TransformXml(reader, writer); | ||
268 | } | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | // If we unexpected run across mixed content in this node, still carry on | ||
273 | // transforming the subtree (this replicates earlier behaviour). | ||
274 | TransformXml(reader, writer); | ||
275 | } | ||
276 | } | ||
277 | else if (reader.Name == "CreatorData") | ||
278 | { | ||
279 | reader.Read(); | ||
280 | if (reader.NodeType == XmlNodeType.Text) | ||
281 | { | ||
282 | hasCreatorData = true; | ||
283 | writer.WriteString(reader.Value); | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | // If we unexpected run across mixed content in this node, still carry on | ||
288 | // transforming the subtree (this replicates earlier behaviour). | ||
289 | TransformXml(reader, writer); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | if (reader.IsEmptyElement) | ||
296 | { | ||
297 | // m_log.DebugFormat("[HG ASSET MAPPER]: Writing end for empty element {0}", reader.Name); | ||
298 | writer.WriteEndElement(); | ||
299 | } | ||
300 | |||
301 | break; | ||
302 | |||
303 | case XmlNodeType.EndElement: | ||
304 | // m_log.DebugFormat("Depth {0} at EndElement", reader.Depth); | ||
305 | if (sopDepth == reader.Depth) | ||
306 | { | ||
307 | if (!hasCreatorData && creator != null) | ||
308 | writer.WriteElementString(reader.Prefix, "CreatorData", reader.NamespaceURI, string.Format("{0};{1} {2}", m_HomeURI, creator.FirstName, creator.LastName)); | ||
309 | |||
310 | // m_log.DebugFormat("[HG ASSET MAPPER]: Reset sopDepth"); | ||
311 | sopDepth = -1; | ||
312 | creator = null; | ||
313 | hasCreatorData = false; | ||
314 | } | ||
315 | writer.WriteEndElement(); | ||
316 | break; | ||
317 | |||
318 | case XmlNodeType.EntityReference: | ||
319 | writer.WriteEntityRef(reader.Name); | ||
320 | break; | ||
321 | |||
322 | case XmlNodeType.ProcessingInstruction: | ||
323 | writer.WriteProcessingInstruction(reader.Name, reader.Value); | ||
324 | break; | ||
325 | |||
326 | case XmlNodeType.Text: | ||
327 | writer.WriteString(reader.Value); | ||
328 | break; | ||
329 | |||
330 | case XmlNodeType.XmlDeclaration: | ||
331 | // For various reasons, not all serializations have xml declarations (or consistent ones) | ||
332 | // and as it's embedded inside a byte stream we don't need it anyway, so ignore. | ||
333 | break; | ||
334 | |||
335 | default: | ||
336 | m_log.WarnFormat( | ||
337 | "[HG ASSET MAPPER]: Unrecognized node {0} in asset XML transform in {1}", | ||
338 | reader.NodeType, m_scene.Name); | ||
339 | break; | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | |||
344 | protected string RewriteSOP(string xmlData) | 193 | protected string RewriteSOP(string xmlData) |
345 | { | 194 | { |
346 | // Console.WriteLine("Input XML [{0}]", xmlData); | 195 | // Console.WriteLine("Input XML [{0}]", xmlData); |
196 | return ExternalRepresentationUtils.RewriteSOP(xmlData, m_scene.Name, m_HomeURI, m_scene.UserAccountService, m_scene.RegionInfo.ScopeID); | ||
347 | 197 | ||
348 | using (StringWriter sw = new StringWriter()) | ||
349 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
350 | using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) | ||
351 | using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) | ||
352 | { | ||
353 | TransformXml(reader, writer); | ||
354 | |||
355 | // Console.WriteLine("Output: [{0}]", sw.ToString()); | ||
356 | |||
357 | return sw.ToString(); | ||
358 | } | ||
359 | |||
360 | // We are now taking the more complex streaming approach above because some assets can be very large | ||
361 | // and can trigger higher CPU use or possibly memory problems. | ||
362 | // XmlDocument doc = new XmlDocument(); | ||
363 | // doc.LoadXml(xml); | ||
364 | // XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); | ||
365 | // | ||
366 | // foreach (XmlNode sop in sops) | ||
367 | // { | ||
368 | // UserAccount creator = null; | ||
369 | // bool hasCreatorData = false; | ||
370 | // XmlNodeList nodes = sop.ChildNodes; | ||
371 | // foreach (XmlNode node in nodes) | ||
372 | // { | ||
373 | // if (node.Name == "CreatorID") | ||
374 | // { | ||
375 | // UUID uuid = UUID.Zero; | ||
376 | // UUID.TryParse(node.InnerText, out uuid); | ||
377 | // creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); | ||
378 | // } | ||
379 | // if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) | ||
380 | // hasCreatorData = true; | ||
381 | // | ||
382 | // //if (node.Name == "OwnerID") | ||
383 | // //{ | ||
384 | // // UserAccount owner = GetUser(node.InnerText); | ||
385 | // // if (owner != null) | ||
386 | // // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; | ||
387 | // //} | ||
388 | // } | ||
389 | // | ||
390 | // if (!hasCreatorData && creator != null) | ||
391 | // { | ||
392 | // XmlElement creatorData = doc.CreateElement("CreatorData"); | ||
393 | // creatorData.InnerText = m_HomeURI + ";" + creator.FirstName + " " + creator.LastName; | ||
394 | // sop.AppendChild(creatorData); | ||
395 | // } | ||
396 | // } | ||
397 | // | ||
398 | // using (StringWriter wr = new StringWriter()) | ||
399 | // { | ||
400 | // doc.Save(wr); | ||
401 | // return wr.ToString(); | ||
402 | // } | ||
403 | } | 198 | } |
404 | 199 | ||
405 | // TODO: unused | 200 | // TODO: unused |