29 using System.Collections.Generic;
31 using System.Reflection;
37 using OpenSim.Framework;
38 using OpenSim.Services.Interfaces;
40 namespace OpenSim.Framework.Serialization.External
49 private static Dictionary<string, Action<InventoryItemBase, XmlReader>> m_InventoryItemXmlProcessors
50 =
new Dictionary<string, Action<InventoryItemBase, XmlReader>>();
52 #region InventoryItemBase Processor initialization
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(
"CreatorID", ProcessCreatorID);
60 m_InventoryItemXmlProcessors.Add(
"CreatorData", ProcessCreatorData);
61 m_InventoryItemXmlProcessors.Add(
"CreationDate", ProcessCreationDate);
62 m_InventoryItemXmlProcessors.Add(
"Owner", ProcessOwner);
63 m_InventoryItemXmlProcessors.Add(
"Description", ProcessDescription);
64 m_InventoryItemXmlProcessors.Add(
"AssetType", ProcessAssetType);
65 m_InventoryItemXmlProcessors.Add(
"AssetID", ProcessAssetID);
66 m_InventoryItemXmlProcessors.Add(
"SaleType", ProcessSaleType);
67 m_InventoryItemXmlProcessors.Add(
"SalePrice", ProcessSalePrice);
68 m_InventoryItemXmlProcessors.Add(
"BasePermissions", ProcessBasePermissions);
69 m_InventoryItemXmlProcessors.Add(
"CurrentPermissions", ProcessCurrentPermissions);
70 m_InventoryItemXmlProcessors.Add(
"EveryOnePermissions", ProcessEveryOnePermissions);
71 m_InventoryItemXmlProcessors.Add(
"NextPermissions", ProcessNextPermissions);
72 m_InventoryItemXmlProcessors.Add(
"Flags", ProcessFlags);
73 m_InventoryItemXmlProcessors.Add(
"GroupID", ProcessGroupID);
74 m_InventoryItemXmlProcessors.Add(
"GroupOwned", ProcessGroupOwned);
78 #region InventoryItemBase Processors
81 item.Name = reader.ReadElementContentAsString(
"Name", String.Empty);
86 item.ID = Util.ReadUUID(reader,
"ID");
91 item.InvType = reader.ReadElementContentAsInt(
"InvType", String.Empty);
96 item.CreatorId = reader.ReadElementContentAsString(
"CreatorUUID", String.Empty);
102 item.CreatorId = reader.ReadElementContentAsString(
"CreatorID", String.Empty);
105 private static void ProcessCreationDate(
InventoryItemBase item, XmlReader reader)
107 item.CreationDate = reader.ReadElementContentAsInt(
"CreationDate", String.Empty);
112 item.Owner = Util.ReadUUID(reader,
"Owner");
117 item.Description = reader.ReadElementContentAsString(
"Description", String.Empty);
122 item.AssetType = reader.ReadElementContentAsInt(
"AssetType", String.Empty);
127 item.AssetID = Util.ReadUUID(reader,
"AssetID");
132 item.SaleType = (byte)reader.ReadElementContentAsInt(
"SaleType", String.Empty);
137 item.SalePrice = reader.ReadElementContentAsInt(
"SalePrice", String.Empty);
140 private static void ProcessBasePermissions(
InventoryItemBase item, XmlReader reader)
142 item.BasePermissions = (uint)reader.ReadElementContentAsInt(
"BasePermissions", String.Empty);
145 private static void ProcessCurrentPermissions(
InventoryItemBase item, XmlReader reader)
147 item.CurrentPermissions = (uint)reader.ReadElementContentAsInt(
"CurrentPermissions", String.Empty);
150 private static void ProcessEveryOnePermissions(
InventoryItemBase item, XmlReader reader)
152 item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt(
"EveryOnePermissions", String.Empty);
155 private static void ProcessNextPermissions(
InventoryItemBase item, XmlReader reader)
157 item.NextPermissions = (uint)reader.ReadElementContentAsInt(
"NextPermissions", String.Empty);
162 item.Flags = (uint)reader.ReadElementContentAsInt(
"Flags", String.Empty);
167 item.GroupID = Util.ReadUUID(reader,
"GroupID");
172 item.GroupOwned = Util.ReadBoolean(reader);
177 item.CreatorData = reader.ReadElementContentAsString(
"CreatorData", String.Empty);
190 return Deserialize(Encoding.ASCII.GetString(serialization, 0, serialization.Length));
203 using (XmlTextReader reader =
new XmlTextReader(
new StringReader(serialization)))
205 reader.ReadStartElement(
"InventoryItem");
208 item, m_InventoryItemXmlProcessors, reader);
210 reader.ReadEndElement();
219 StringWriter sw =
new StringWriter();
220 XmlTextWriter writer =
new XmlTextWriter(sw);
221 writer.Formatting = Formatting.Indented;
222 writer.WriteStartDocument();
224 writer.WriteStartElement(
"InventoryItem");
226 writer.WriteStartElement(
"Name");
227 writer.WriteString(inventoryItem.Name);
228 writer.WriteEndElement();
229 writer.WriteStartElement(
"ID");
230 writer.WriteString(inventoryItem.ID.ToString());
231 writer.WriteEndElement();
232 writer.WriteStartElement(
"InvType");
233 writer.WriteString(inventoryItem.InvType.ToString());
234 writer.WriteEndElement();
235 writer.WriteStartElement(
"CreatorUUID");
236 writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService));
237 writer.WriteEndElement();
238 writer.WriteStartElement(
"CreationDate");
239 writer.WriteString(inventoryItem.CreationDate.ToString());
240 writer.WriteEndElement();
241 writer.WriteStartElement(
"Owner");
242 writer.WriteString(inventoryItem.Owner.ToString());
243 writer.WriteEndElement();
244 writer.WriteStartElement(
"Description");
245 writer.WriteString(inventoryItem.Description);
246 writer.WriteEndElement();
247 writer.WriteStartElement(
"AssetType");
248 writer.WriteString(inventoryItem.AssetType.ToString());
249 writer.WriteEndElement();
250 writer.WriteStartElement(
"AssetID");
251 writer.WriteString(inventoryItem.AssetID.ToString());
252 writer.WriteEndElement();
253 writer.WriteStartElement(
"SaleType");
254 writer.WriteString(inventoryItem.SaleType.ToString());
255 writer.WriteEndElement();
256 writer.WriteStartElement(
"SalePrice");
257 writer.WriteString(inventoryItem.SalePrice.ToString());
258 writer.WriteEndElement();
259 writer.WriteStartElement(
"BasePermissions");
260 writer.WriteString(inventoryItem.BasePermissions.ToString());
261 writer.WriteEndElement();
262 writer.WriteStartElement(
"CurrentPermissions");
263 writer.WriteString(inventoryItem.CurrentPermissions.ToString());
264 writer.WriteEndElement();
265 writer.WriteStartElement(
"EveryOnePermissions");
266 writer.WriteString(inventoryItem.EveryOnePermissions.ToString());
267 writer.WriteEndElement();
268 writer.WriteStartElement(
"NextPermissions");
269 writer.WriteString(inventoryItem.NextPermissions.ToString());
270 writer.WriteEndElement();
271 writer.WriteStartElement(
"Flags");
272 writer.WriteString(inventoryItem.Flags.ToString());
273 writer.WriteEndElement();
274 writer.WriteStartElement(
"GroupID");
275 writer.WriteString(inventoryItem.GroupID.ToString());
276 writer.WriteEndElement();
277 writer.WriteStartElement(
"GroupOwned");
278 writer.WriteString(inventoryItem.GroupOwned.ToString());
279 writer.WriteEndElement();
280 if (options.ContainsKey(
"creators") && !string.IsNullOrEmpty(inventoryItem.CreatorData))
281 writer.WriteElementString(
"CreatorData", inventoryItem.CreatorData);
282 else if (options.ContainsKey(
"home"))
284 if (userAccountService != null)
286 UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid);
289 string creatorData = ExternalRepresentationUtils.CalcCreatorData((string)options[
"home"], inventoryItem.
CreatorIdAsUuid, account.
FirstName +
" " + account.
LastName);
290 writer.WriteElementString(
"CreatorData", creatorData);
292 writer.WriteElementString(
"CreatorID", inventoryItem.CreatorId);
296 writer.WriteEndElement();
301 return sw.ToString();
static InventoryItemBase Deserialize(string serialization)
Deserialize settings
Serialize and deserialize user inventory items as an external format.
static InventoryItemBase Deserialize(byte[] serialization)
Deserialize item
Inventory Item - contains all the properties associated with an individual inventory piece...
static string Serialize(InventoryItemBase inventoryItem, Dictionary< string, object > options, IUserAccountService userAccountService)