aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs99
1 files changed, 99 insertions, 0 deletions
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
new file mode 100644
index 0000000..6e8c2ee
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -0,0 +1,99 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Xml;
31
32using OpenMetaverse;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Framework.Serialization.External
36{
37 /// <summary>
38 /// Utilities for manipulating external representations of data structures in OpenSim
39 /// </summary>
40 public class ExternalRepresentationUtils
41 {
42 /// <summary>
43 /// Takes a XML representation of a SceneObjectPart and returns another XML representation
44 /// with creator data added to it.
45 /// </summary>
46 /// <param name="xml">The SceneObjectPart represented in XML2</param>
47 /// <param name="profileURL">The URL of the profile service for the creator</param>
48 /// <param name="userService">The service for retrieving user account information</param>
49 /// <param name="scopeID">The scope of the user account information (Grid ID)</param>
50 /// <returns>The SceneObjectPart represented in XML2</returns>
51 public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID)
52 {
53 if (xml == string.Empty || profileURL == string.Empty || userService == null)
54 return xml;
55
56 XmlDocument doc = new XmlDocument();
57 doc.LoadXml(xml);
58 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
59
60 foreach (XmlNode sop in sops)
61 {
62 UserAccount creator = null;
63 bool hasCreatorData = false;
64 XmlNodeList nodes = sop.ChildNodes;
65 foreach (XmlNode node in nodes)
66 {
67 if (node.Name == "CreatorID")
68 {
69 UUID uuid = UUID.Zero;
70 UUID.TryParse(node.InnerText, out uuid);
71 creator = userService.GetUserAccount(scopeID, uuid);
72 }
73 if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
74 hasCreatorData = true;
75
76 //if (node.Name == "OwnerID")
77 //{
78 // UserAccount owner = GetUser(node.InnerText);
79 // if (owner != null)
80 // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
81 //}
82 }
83 if (!hasCreatorData && creator != null)
84 {
85 XmlElement creatorData = doc.CreateElement("CreatorData");
86 creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
87 sop.AppendChild(creatorData);
88 }
89 }
90
91 using (StringWriter wr = new StringWriter())
92 {
93 doc.Save(wr);
94 return wr.ToString();
95 }
96
97 }
98 }
99}