aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorDiva Canto2010-11-27 11:40:54 -0800
committerDiva Canto2010-11-27 11:40:54 -0800
commitca8d0157333823b549c7ae36b40ea3c05045fc25 (patch)
tree267f4219ef8447178e494c7637cf7a1d89367460 /OpenSim/Framework
parentCreator information preserved upon HG transfers. (diff)
downloadopensim-SC_OLD-ca8d0157333823b549c7ae36b40ea3c05045fc25.zip
opensim-SC_OLD-ca8d0157333823b549c7ae36b40ea3c05045fc25.tar.gz
opensim-SC_OLD-ca8d0157333823b549c7ae36b40ea3c05045fc25.tar.bz2
opensim-SC_OLD-ca8d0157333823b549c7ae36b40ea3c05045fc25.tar.xz
Changed the parser for InventoryItem deserialization. Moved some utility functions around.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs198
-rw-r--r--OpenSim/Framework/Util.cs61
2 files changed, 229 insertions, 30 deletions
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index 862cc72..df9af32 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -26,9 +26,13 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.IO; 30using System.IO;
31using System.Reflection;
30using System.Text; 32using System.Text;
31using System.Xml; 33using System.Xml;
34
35using log4net;
32using OpenMetaverse; 36using OpenMetaverse;
33using OpenSim.Framework; 37using OpenSim.Framework;
34 38
@@ -40,6 +44,133 @@ namespace OpenSim.Framework.Serialization.External
40 /// XXX: Please do not use yet. 44 /// XXX: Please do not use yet.
41 public class UserInventoryItemSerializer 45 public class UserInventoryItemSerializer
42 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader);
50 private static Dictionary<string, InventoryItemXmlProcessor> m_InventoryItemXmlProcessors = new Dictionary<string, InventoryItemXmlProcessor>();
51
52 #region InventoryItemBase Processor initialization
53 static UserInventoryItemSerializer()
54 {
55 m_InventoryItemXmlProcessors.Add("Name", ProcessName);
56 m_InventoryItemXmlProcessors.Add("ID", ProcessID);
57 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
58 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
59 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
60 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
61 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
62 m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType);
63 m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID);
64 m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType);
65 m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice);
66 m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions);
67 m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions);
68 m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions);
69 m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions);
70 m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags);
71 m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID);
72 m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned);
73 }
74 #endregion
75
76 #region InventoryItemBase Processors
77 private static void ProcessName(InventoryItemBase item, XmlTextReader reader)
78 {
79 item.Name = reader.ReadElementContentAsString("Name", String.Empty);
80 }
81
82 private static void ProcessID(InventoryItemBase item, XmlTextReader reader)
83 {
84 item.ID = Util.ReadUUID(reader, "ID");
85 }
86
87 private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader)
88 {
89 item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
90 }
91
92 private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader)
93 {
94 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty);
95 }
96
97 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader)
98 {
99 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
100 }
101
102 private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader)
103 {
104 item.Owner = Util.ReadUUID(reader, "Owner");
105 }
106
107 private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader)
108 {
109 item.Description = reader.ReadElementContentAsString("Description", String.Empty);
110 }
111
112 private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader)
113 {
114 item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty);
115 }
116
117 private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader)
118 {
119 item.AssetID = Util.ReadUUID(reader, "AssetID");
120 }
121
122 private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader)
123 {
124 item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty);
125 }
126
127 private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader)
128 {
129 item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
130 }
131
132 private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader)
133 {
134 item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
135 }
136
137 private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader)
138 {
139 item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
140 }
141
142 private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader)
143 {
144 item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty);
145 }
146
147 private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader)
148 {
149 item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
150 }
151
152 private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader)
153 {
154 item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
155 }
156
157 private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader)
158 {
159 item.GroupID = Util.ReadUUID(reader, "GroupID");
160 }
161
162 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader)
163 {
164 //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty);
165 // We don't do that, because ReadElementContentAsBoolean assumes lower case strings,
166 // and they may not be lower case
167 reader.ReadStartElement(); // GroupOwned
168 item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower());
169 reader.ReadEndElement();
170 }
171
172 #endregion
173
43 /// <summary> 174 /// <summary>
44 /// Deserialize item 175 /// Deserialize item
45 /// </summary> 176 /// </summary>
@@ -60,37 +191,44 @@ namespace OpenSim.Framework.Serialization.External
60 public static InventoryItemBase Deserialize(string serialization) 191 public static InventoryItemBase Deserialize(string serialization)
61 { 192 {
62 InventoryItemBase item = new InventoryItemBase(); 193 InventoryItemBase item = new InventoryItemBase();
63 194
64 StringReader sr = new StringReader(serialization); 195 using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization)))
65 XmlTextReader xtr = new XmlTextReader(sr); 196 {
66 197 reader.ReadStartElement("InventoryItem");
67 xtr.ReadStartElement("InventoryItem"); 198
68 199 string nodeName = string.Empty;
69 item.Name = xtr.ReadElementString("Name"); 200 while (reader.NodeType != XmlNodeType.EndElement)
70 item.ID = UUID.Parse( xtr.ReadElementString("ID")); 201 {
71 item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType")); 202 nodeName = reader.Name;
72 item.CreatorId = xtr.ReadElementString("CreatorUUID"); 203 InventoryItemXmlProcessor p = null;
73 item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate")); 204 if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p))
74 item.Owner = UUID.Parse( xtr.ReadElementString("Owner")); 205 {
75 item.Description = xtr.ReadElementString("Description"); 206 //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name);
76 item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType")); 207 try
77 item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID")); 208 {
78 item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType")); 209 p(item, reader);
79 item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); 210 }
80 item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); 211 catch (Exception e)
81 item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); 212 {
82 item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions")); 213 m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e);
83 item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); 214 if (reader.NodeType == XmlNodeType.EndElement)
84 item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); 215 reader.Read();
85 item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); 216 }
86 item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned")); 217 }
87 218 else
88 xtr.ReadEndElement(); 219 {
89 220 // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName);
90 xtr.Close(); 221 reader.ReadOuterXml(); // ignore
91 sr.Close(); 222 }
92 223
224 }
225
226 reader.ReadEndElement(); // InventoryItem
227 }
228
229 //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID);
93 return item; 230 return item;
231
94 } 232 }
95 233
96 public static string Serialize(InventoryItemBase inventoryItem) 234 public static string Serialize(InventoryItemBase inventoryItem)
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e8f8e01..101ece4 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1558,5 +1558,66 @@ namespace OpenSim.Framework
1558 return string.Empty; 1558 return string.Empty;
1559 } 1559 }
1560 1560
1561 public static UUID ReadUUID(XmlTextReader reader, string name)
1562 {
1563 UUID id;
1564 string idStr;
1565
1566 reader.ReadStartElement(name);
1567
1568 if (reader.Name == "Guid")
1569 idStr = reader.ReadElementString("Guid");
1570 else if (reader.Name == "UUID")
1571 idStr = reader.ReadElementString("UUID");
1572 else // no leading tag
1573 idStr = reader.ReadContentAsString();
1574 UUID.TryParse(idStr, out id);
1575 reader.ReadEndElement();
1576
1577 return id;
1578 }
1579
1580 public static Vector3 ReadVector(XmlTextReader reader, string name)
1581 {
1582 Vector3 vec;
1583
1584 reader.ReadStartElement(name);
1585 vec.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // X or x
1586 vec.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Y or y
1587 vec.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Z or z
1588 reader.ReadEndElement();
1589
1590 return vec;
1591 }
1592
1593 public static Quaternion ReadQuaternion(XmlTextReader reader, string name)
1594 {
1595 Quaternion quat = new Quaternion();
1596
1597 reader.ReadStartElement(name);
1598 while (reader.NodeType != XmlNodeType.EndElement)
1599 {
1600 switch (reader.Name.ToLower())
1601 {
1602 case "x":
1603 quat.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1604 break;
1605 case "y":
1606 quat.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1607 break;
1608 case "z":
1609 quat.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1610 break;
1611 case "w":
1612 quat.W = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1613 break;
1614 }
1615 }
1616
1617 reader.ReadEndElement();
1618
1619 return quat;
1620 }
1621
1561 } 1622 }
1562} 1623}