aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorDiva Canto2010-11-29 08:43:33 -0800
committerDiva Canto2010-11-29 08:43:33 -0800
commitf86c438653fc3c8356a8f0c43a055b1928183f02 (patch)
treeb8ad05db04efde6385eeaed48dcbe4e896133ad5 /OpenSim/Framework
parentChanged the parser for InventoryItem deserialization. Moved some utility func... (diff)
downloadopensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.zip
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.gz
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.bz2
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.xz
Preservation of creator information now also working in IARs. Cleaned up usage help. Moved Osp around, deleted unnecessary OspInventoryWrapperPlugin, added manipulation of SOP's xml representation in a generic ExternalRepresentationUtils function.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs104
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs87
-rw-r--r--OpenSim/Framework/Serialization/External/OspResolver.cs (renamed from OpenSim/Framework/Communications/Osp/OspResolver.cs)2
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs39
-rw-r--r--OpenSim/Framework/Util.cs20
5 files changed, 139 insertions, 113 deletions
diff --git a/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs b/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs
deleted file mode 100644
index bcd1eee..0000000
--- a/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs
+++ /dev/null
@@ -1,104 +0,0 @@
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 */
27
28using System.Collections.Generic;
29using OpenSim.Data;
30using OpenMetaverse;
31using OpenSim.Services.Interfaces;
32
33namespace OpenSim.Framework.Communications.Osp
34{
35 /// <summary>
36 /// Wrap other inventory data plugins so that we can perform OSP related post processing for items
37 /// </summary>
38 public class OspInventoryWrapperPlugin : IInventoryDataPlugin
39 {
40 protected IInventoryDataPlugin m_wrappedPlugin;
41 //protected CommunicationsManager m_commsManager;
42 protected IUserAccountService m_userAccountService;
43
44 public OspInventoryWrapperPlugin(IInventoryDataPlugin wrappedPlugin, IUserAccountService userService)
45 {
46 m_wrappedPlugin = wrappedPlugin;
47 m_userAccountService = userService;
48 }
49
50 public string Name { get { return "OspInventoryWrapperPlugin"; } }
51 public string Version { get { return "0.1"; } }
52 public void Initialise() {}
53 public void Initialise(string connect) {}
54 public void Dispose() {}
55
56 public InventoryItemBase getInventoryItem(UUID item)
57 {
58 return PostProcessItem(m_wrappedPlugin.getInventoryItem(item));
59 }
60
61 // XXX: Why on earth does this exist as it appears to duplicate getInventoryItem?
62 public InventoryItemBase queryInventoryItem(UUID item)
63 {
64 return PostProcessItem(m_wrappedPlugin.queryInventoryItem(item));
65 }
66
67 public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
68 {
69 List<InventoryItemBase> items = m_wrappedPlugin.getInventoryInFolder(folderID);
70
71 foreach (InventoryItemBase item in items)
72 PostProcessItem(item);
73
74 return items;
75 }
76
77 public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
78 {
79 return m_wrappedPlugin.fetchActiveGestures(avatarID);
80
81 // Presuming that no post processing is needed here as gestures don't refer to creator information (?)
82 }
83
84 protected InventoryItemBase PostProcessItem(InventoryItemBase item)
85 {
86 item.CreatorIdAsUuid = OspResolver.ResolveOspa(item.CreatorId, m_userAccountService);
87 return item;
88 }
89
90 public List<InventoryFolderBase> getFolderHierarchy(UUID parentID) { return m_wrappedPlugin.getFolderHierarchy(parentID); }
91 public List<InventoryFolderBase> getUserRootFolders(UUID user) { return m_wrappedPlugin.getUserRootFolders(user); }
92 public InventoryFolderBase getUserRootFolder(UUID user) { return m_wrappedPlugin.getUserRootFolder(user); }
93 public List<InventoryFolderBase> getInventoryFolders(UUID parentID) { return m_wrappedPlugin.getInventoryFolders(parentID); }
94 public InventoryFolderBase getInventoryFolder(UUID folder) { return m_wrappedPlugin.getInventoryFolder(folder); }
95 public void addInventoryItem(InventoryItemBase item) { m_wrappedPlugin.addInventoryItem(item); }
96 public void updateInventoryItem(InventoryItemBase item) { m_wrappedPlugin.updateInventoryItem(item); }
97 public void deleteInventoryItem(UUID item) { m_wrappedPlugin.deleteInventoryItem(item); }
98 public InventoryFolderBase queryInventoryFolder(UUID folder) { return m_wrappedPlugin.queryInventoryFolder(folder); }
99 public void addInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.addInventoryFolder(folder); }
100 public void updateInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.updateInventoryFolder(folder); }
101 public void moveInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.moveInventoryFolder(folder); }
102 public void deleteInventoryFolder(UUID folder) { m_wrappedPlugin.deleteInventoryFolder(folder); }
103 }
104}
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
new file mode 100644
index 0000000..5c0630c
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -0,0 +1,87 @@
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 public class ExternalRepresentationUtils
38 {
39 public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID)
40 {
41 if (xml == string.Empty || profileURL == string.Empty || userService == null)
42 return xml;
43
44 XmlDocument doc = new XmlDocument();
45 doc.LoadXml(xml);
46 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
47
48 foreach (XmlNode sop in sops)
49 {
50 UserAccount creator = null;
51 bool hasCreatorData = false;
52 XmlNodeList nodes = sop.ChildNodes;
53 foreach (XmlNode node in nodes)
54 {
55 if (node.Name == "CreatorID")
56 {
57 UUID uuid = UUID.Zero;
58 UUID.TryParse(node.InnerText, out uuid);
59 creator = userService.GetUserAccount(scopeID, uuid);
60 }
61 if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
62 hasCreatorData = true;
63
64 //if (node.Name == "OwnerID")
65 //{
66 // UserAccount owner = GetUser(node.InnerText);
67 // if (owner != null)
68 // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
69 //}
70 }
71 if (!hasCreatorData && creator != null)
72 {
73 XmlElement creatorData = doc.CreateElement("CreatorData");
74 creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
75 sop.AppendChild(creatorData);
76 }
77 }
78
79 using (StringWriter wr = new StringWriter())
80 {
81 doc.Save(wr);
82 return wr.ToString();
83 }
84
85 }
86 }
87}
diff --git a/OpenSim/Framework/Communications/Osp/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs
index 24ea64d..53c35ff 100644
--- a/OpenSim/Framework/Communications/Osp/OspResolver.cs
+++ b/OpenSim/Framework/Serialization/External/OspResolver.cs
@@ -32,7 +32,7 @@ using OpenMetaverse;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
34 34
35namespace OpenSim.Framework.Communications.Osp 35namespace OpenSim.Framework.Serialization
36{ 36{
37 /// <summary> 37 /// <summary>
38 /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for 38 /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index df9af32..d5e84c7 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -35,6 +35,7 @@ using System.Xml;
35using log4net; 35using log4net;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Services.Interfaces;
38 39
39namespace OpenSim.Framework.Serialization.External 40namespace OpenSim.Framework.Serialization.External
40{ 41{
@@ -56,6 +57,8 @@ namespace OpenSim.Framework.Serialization.External
56 m_InventoryItemXmlProcessors.Add("ID", ProcessID); 57 m_InventoryItemXmlProcessors.Add("ID", ProcessID);
57 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); 58 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
58 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); 59 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
60 m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID);
61 m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData);
59 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); 62 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
60 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); 63 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
61 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); 64 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
@@ -94,6 +97,12 @@ namespace OpenSim.Framework.Serialization.External
94 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); 97 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty);
95 } 98 }
96 99
100 private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader)
101 {
102 // when it exists, this overrides the previous
103 item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty);
104 }
105
97 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) 106 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader)
98 { 107 {
99 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); 108 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
@@ -161,12 +170,12 @@ namespace OpenSim.Framework.Serialization.External
161 170
162 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) 171 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader)
163 { 172 {
164 //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); 173 item.GroupOwned = Util.ReadBoolean(reader);
165 // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, 174 }
166 // and they may not be lower case 175
167 reader.ReadStartElement(); // GroupOwned 176 private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader)
168 item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); 177 {
169 reader.ReadEndElement(); 178 item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
170 } 179 }
171 180
172 #endregion 181 #endregion
@@ -231,7 +240,7 @@ namespace OpenSim.Framework.Serialization.External
231 240
232 } 241 }
233 242
234 public static string Serialize(InventoryItemBase inventoryItem) 243 public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService)
235 { 244 {
236 StringWriter sw = new StringWriter(); 245 StringWriter sw = new StringWriter();
237 XmlTextWriter writer = new XmlTextWriter(sw); 246 XmlTextWriter writer = new XmlTextWriter(sw);
@@ -250,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External
250 writer.WriteString(inventoryItem.InvType.ToString()); 259 writer.WriteString(inventoryItem.InvType.ToString());
251 writer.WriteEndElement(); 260 writer.WriteEndElement();
252 writer.WriteStartElement("CreatorUUID"); 261 writer.WriteStartElement("CreatorUUID");
253 writer.WriteString(inventoryItem.CreatorId); 262 writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService));
254 writer.WriteEndElement(); 263 writer.WriteEndElement();
255 writer.WriteStartElement("CreationDate"); 264 writer.WriteStartElement("CreationDate");
256 writer.WriteString(inventoryItem.CreationDate.ToString()); 265 writer.WriteString(inventoryItem.CreationDate.ToString());
@@ -294,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External
294 writer.WriteStartElement("GroupOwned"); 303 writer.WriteStartElement("GroupOwned");
295 writer.WriteString(inventoryItem.GroupOwned.ToString()); 304 writer.WriteString(inventoryItem.GroupOwned.ToString());
296 writer.WriteEndElement(); 305 writer.WriteEndElement();
306 if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty)
307 writer.WriteElementString("CreatorData", inventoryItem.CreatorData);
308 else if (options.ContainsKey("profile"))
309 {
310 if (userAccountService != null)
311 {
312 UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid);
313 if (account != null)
314 {
315 writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName);
316 }
317 writer.WriteElementString("CreatorID", inventoryItem.CreatorId);
318 }
319 }
297 320
298 writer.WriteEndElement(); 321 writer.WriteEndElement();
299 322
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 101ece4..8d1671a 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1558,6 +1558,16 @@ namespace OpenSim.Framework
1558 return string.Empty; 1558 return string.Empty;
1559 } 1559 }
1560 1560
1561 #region Xml Serialization Utilities
1562 public static bool ReadBoolean(XmlTextReader reader)
1563 {
1564 reader.ReadStartElement();
1565 bool result = Boolean.Parse(reader.ReadContentAsString().ToLower());
1566 reader.ReadEndElement();
1567
1568 return result;
1569 }
1570
1561 public static UUID ReadUUID(XmlTextReader reader, string name) 1571 public static UUID ReadUUID(XmlTextReader reader, string name)
1562 { 1572 {
1563 UUID id; 1573 UUID id;
@@ -1619,5 +1629,15 @@ namespace OpenSim.Framework
1619 return quat; 1629 return quat;
1620 } 1630 }
1621 1631
1632 public static T ReadEnum<T>(XmlTextReader reader, string name)
1633 {
1634 string value = reader.ReadElementContentAsString(name, String.Empty);
1635 // !!!!! to deal with flags without commas
1636 if (value.Contains(" ") && !value.Contains(","))
1637 value = value.Replace(" ", ", ");
1638
1639 return (T)Enum.Parse(typeof(T), value); ;
1640 }
1641 #endregion
1622 } 1642 }
1623} 1643}