From ca8d0157333823b549c7ae36b40ea3c05045fc25 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 27 Nov 2010 11:40:54 -0800 Subject: Changed the parser for InventoryItem deserialization. Moved some utility functions around. --- .../External/UserInventoryItemSerializer.cs | 198 +++++++++++++++++---- 1 file changed, 168 insertions(+), 30 deletions(-) (limited to 'OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs') 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 @@ */ using System; +using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; using System.Xml; + +using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -40,6 +44,133 @@ namespace OpenSim.Framework.Serialization.External /// XXX: Please do not use yet. public class UserInventoryItemSerializer { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader); + private static Dictionary m_InventoryItemXmlProcessors = new Dictionary(); + + #region InventoryItemBase Processor initialization + static UserInventoryItemSerializer() + { + m_InventoryItemXmlProcessors.Add("Name", ProcessName); + m_InventoryItemXmlProcessors.Add("ID", ProcessID); + m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); + m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); + m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); + m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); + m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); + m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType); + m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID); + m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType); + m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice); + m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions); + m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions); + m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions); + m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions); + m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags); + m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID); + m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned); + } + #endregion + + #region InventoryItemBase Processors + private static void ProcessName(InventoryItemBase item, XmlTextReader reader) + { + item.Name = reader.ReadElementContentAsString("Name", String.Empty); + } + + private static void ProcessID(InventoryItemBase item, XmlTextReader reader) + { + item.ID = Util.ReadUUID(reader, "ID"); + } + + private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader) + { + item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty); + } + + private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader) + { + item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); + } + + private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) + { + item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); + } + + private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader) + { + item.Owner = Util.ReadUUID(reader, "Owner"); + } + + private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader) + { + item.Description = reader.ReadElementContentAsString("Description", String.Empty); + } + + private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader) + { + item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty); + } + + private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader) + { + item.AssetID = Util.ReadUUID(reader, "AssetID"); + } + + private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader) + { + item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty); + } + + private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader) + { + item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty); + } + + private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader) + { + item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty); + } + + private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader) + { + item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty); + } + + private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader) + { + item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty); + } + + private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader) + { + item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty); + } + + private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader) + { + item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty); + } + + private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader) + { + item.GroupID = Util.ReadUUID(reader, "GroupID"); + } + + private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) + { + //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); + // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, + // and they may not be lower case + reader.ReadStartElement(); // GroupOwned + item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); + reader.ReadEndElement(); + } + + #endregion + /// /// Deserialize item /// @@ -60,37 +191,44 @@ namespace OpenSim.Framework.Serialization.External public static InventoryItemBase Deserialize(string serialization) { InventoryItemBase item = new InventoryItemBase(); - - StringReader sr = new StringReader(serialization); - XmlTextReader xtr = new XmlTextReader(sr); - - xtr.ReadStartElement("InventoryItem"); - - item.Name = xtr.ReadElementString("Name"); - item.ID = UUID.Parse( xtr.ReadElementString("ID")); - item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType")); - item.CreatorId = xtr.ReadElementString("CreatorUUID"); - item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate")); - item.Owner = UUID.Parse( xtr.ReadElementString("Owner")); - item.Description = xtr.ReadElementString("Description"); - item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType")); - item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID")); - item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType")); - item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); - item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); - item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); - item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions")); - item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); - item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); - item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); - item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned")); - - xtr.ReadEndElement(); - - xtr.Close(); - sr.Close(); - + + using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization))) + { + reader.ReadStartElement("InventoryItem"); + + string nodeName = string.Empty; + while (reader.NodeType != XmlNodeType.EndElement) + { + nodeName = reader.Name; + InventoryItemXmlProcessor p = null; + if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p)) + { + //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); + try + { + p(item, reader); + } + catch (Exception e) + { + m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e); + if (reader.NodeType == XmlNodeType.EndElement) + reader.Read(); + } + } + else + { + // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName); + reader.ReadOuterXml(); // ignore + } + + } + + reader.ReadEndElement(); // InventoryItem + } + + //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); return item; + } public static string Serialize(InventoryItemBase inventoryItem) -- cgit v1.1 From f86c438653fc3c8356a8f0c43a055b1928183f02 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 29 Nov 2010 08:43:33 -0800 Subject: 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. --- .../External/UserInventoryItemSerializer.cs | 39 +++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs') 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; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Services.Interfaces; namespace OpenSim.Framework.Serialization.External { @@ -56,6 +57,8 @@ namespace OpenSim.Framework.Serialization.External m_InventoryItemXmlProcessors.Add("ID", ProcessID); m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); + m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID); + m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData); m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); @@ -94,6 +97,12 @@ namespace OpenSim.Framework.Serialization.External item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); } + private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader) + { + // when it exists, this overrides the previous + item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty); + } + private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) { item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); @@ -161,12 +170,12 @@ namespace OpenSim.Framework.Serialization.External private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) { - //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); - // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, - // and they may not be lower case - reader.ReadStartElement(); // GroupOwned - item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); - reader.ReadEndElement(); + item.GroupOwned = Util.ReadBoolean(reader); + } + + private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader) + { + item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); } #endregion @@ -231,7 +240,7 @@ namespace OpenSim.Framework.Serialization.External } - public static string Serialize(InventoryItemBase inventoryItem) + public static string Serialize(InventoryItemBase inventoryItem, Dictionary options, IUserAccountService userAccountService) { StringWriter sw = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(sw); @@ -250,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External writer.WriteString(inventoryItem.InvType.ToString()); writer.WriteEndElement(); writer.WriteStartElement("CreatorUUID"); - writer.WriteString(inventoryItem.CreatorId); + writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService)); writer.WriteEndElement(); writer.WriteStartElement("CreationDate"); writer.WriteString(inventoryItem.CreationDate.ToString()); @@ -294,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External writer.WriteStartElement("GroupOwned"); writer.WriteString(inventoryItem.GroupOwned.ToString()); writer.WriteEndElement(); + if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) + writer.WriteElementString("CreatorData", inventoryItem.CreatorData); + else if (options.ContainsKey("profile")) + { + if (userAccountService != null) + { + UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid); + if (account != null) + { + writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName); + } + writer.WriteElementString("CreatorID", inventoryItem.CreatorId); + } + } writer.WriteEndElement(); -- cgit v1.1