insert an InventoryArchiveUtils.FindItemsByPath() to return multiple items rather than just the first one

bulletsim
Justin Clark-Casey (justincc) 2011-06-04 01:37:01 +01:00
parent 896f039513
commit fe890554fb
3 changed files with 41 additions and 12 deletions

View File

@ -149,14 +149,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from the user's root folder.
///
/// </summary>
/// <remarks>
/// This method does not handle paths that contain multiple delimitors
///
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </summary>
/// </remarks>
///
/// <param name="inventoryService">
/// Inventory service to query
@ -178,7 +179,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return FindItemByPath(inventoryService, rootFolder, path);
}
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
/// </summary>
@ -190,14 +191,43 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </remarks>
///
/// <param name="inventoryService">Inventory service to query</param>
/// <param name="startFolder">The folder from which the path starts</param>
/// <param name="path">The path to the required item.</param>
/// <returns>null if the item is not found</returns>
public static InventoryItemBase FindItemByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{
List<InventoryItemBase> foundItems = FindItemsByPath(inventoryService, startFolder, path);
if (foundItems.Count != 0)
return foundItems[0];
else
return null;
}
/// <summary>
/// Find items that match a given PATH_DELIMITOR delimited path starting from this folder.
/// </summary>
/// <remarks>
/// This method does not handle paths that contain multiple delimiters
///
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
/// XPath like expression
///
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
/// </remarks>
///
/// <param name="inventoryService">Inventory service to query</param>
/// <param name="startFolder">The folder from which the path starts</param>
/// <param name="path">The path to the required item.</param>
/// <returns>null if the item is not found</returns>
public static InventoryItemBase FindItemByPath(
/// <returns>The items that were found with this path. An empty list if no items were found.</returns>
public static List<InventoryItemBase> FindItemsByPath(
IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
{
List<InventoryItemBase> foundItems = new List<InventoryItemBase>();
// If the path isn't just / then trim any starting extraneous slashes
path = path.TrimStart(new char[] { PATH_DELIMITER });
@ -221,7 +251,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// m_log.DebugFormat("[INVENTORY ARCHIVE UTILS]: Inspecting item {0} {1}", item.Name, item.ID);
if (item.Name == components[0])
return item;
foundItems.Add(item);
}
}
else
@ -233,12 +263,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
foreach (InventoryFolderBase folder in contents.Folders)
{
if (folder.Name == components[0])
return FindItemByPath(inventoryService, folder, components[1]);
foundItems.AddRange(FindItemsByPath(inventoryService, folder, components[1]));
}
}
// We didn't find an item or intermediate folder with the given name
return null;
return foundItems;
}
/// <summary>

View File

@ -255,10 +255,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
// The path may point to an item instead
if (inventoryFolder == null)
{
inventoryItem = InventoryArchiveUtils.FindItemByPath(m_scene.InventoryService, rootFolder, m_invPath);
//inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
}
if (null == inventoryFolder && null == inventoryItem)
{

View File

@ -69,6 +69,9 @@ namespace OpenSim.Region.Framework.Tests
= UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Objects/item1");
Assert.That(retrievedItem1, Is.Not.Null);
// Try giving back the freshly received item
//scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID);
}
[Test]