* refactor: rearrange path inventory manipulation so that input tidying can be used for item paths as well

0.6.0-stable
Justin Clarke Casey 2008-07-31 18:23:17 +00:00
parent 465e77b618
commit 900a656420
2 changed files with 73 additions and 18 deletions

View File

@ -108,7 +108,7 @@ namespace OpenSim.Framework.Communications.Cache
}
/// <summary>
/// Returns the item if it exists in this folder or any of this folder's subfolders?
/// Returns the item if it exists in this folder or in any of this folder's descendant folders
/// </summary>
/// <param name="itemID"></param>
/// <returns>null if the item is not found</returns>
@ -197,7 +197,7 @@ namespace OpenSim.Framework.Communications.Cache
}
/// <summary>
/// Find a folder given a PATH_DELIMITOR delimited path.
/// Find a folder given a PATH_DELIMITOR delimited path starting from this folder
///
/// This method does not handle paths that contain multiple delimitors
///
@ -208,9 +208,8 @@ namespace OpenSim.Framework.Communications.Cache
/// </summary>
/// <param name="path">
/// The path to the required folder. It this is empty then this folder itself is returned.
/// If a folder for the given path is not found, then null is returned.
/// </param>
/// <returns></returns>
/// <returns>null if the folder is not found</returns>
public InventoryFolderImpl FindFolderByPath(string path)
{
if (path == string.Empty)
@ -234,6 +233,52 @@ namespace OpenSim.Framework.Communications.Cache
// We didn't find a folder with the given name
return null;
}
/// <summary>
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
///
/// 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>
/// <param name="path">
/// The path to the required item.
/// </param>
/// <returns>null if the item is not found</returns>
public InventoryItemBase FindItemByPath(string path)
{
int delimitorIndex = path.IndexOf(PATH_DELIMITER);
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
if (components.Length == 1)
{
lock (Items)
{
foreach (InventoryItemBase item in Items.Values)
{
if (item.Name == components[0])
return item;
}
}
}
else
{
lock (SubFolders)
{
foreach (InventoryFolderImpl folder in SubFolders.Values)
{
if (folder.Name == components[0])
return folder.FindItemByPath(components[1]);
}
}
}
// We didn't find an item or intermediate folder with the given name
return null;
}
/// <summary>
/// Return a copy of the list of child items in this folder
@ -256,7 +301,7 @@ namespace OpenSim.Framework.Communications.Cache
}
/// <summary>
/// Return a copy of the list of immediate child folders in this folder.
/// Return a copy of the list of child folders in this folder.
/// </summary>
public List<InventoryFolderBase> RequestListOfFolders()
{

View File

@ -698,27 +698,37 @@ namespace OpenSim
}
InventoryFolderImpl inventoryFolder = null;
//InventoryItemBase inventoryItem = null;
if (userInfo.HasReceivedInventory)
{
if (invPath == InventoryFolderImpl.PATH_DELIMITER)
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
// itself (possibly at a small loss in efficiency).
string[] components
= invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
invPath = String.Empty;
foreach (string c in components)
{
invPath += c + InventoryFolderImpl.PATH_DELIMITER;
}
invPath = invPath.Remove(invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
// Annoyingly Split actually returns the original string if the input string consists only of delimiters
// Therefore if we still start with a / after the split, then we need the root folder
if (invPath.StartsWith(InventoryFolderImpl.PATH_DELIMITER))
{
inventoryFolder = userInfo.RootFolder;
}
else
{
// Eliminate double slashes and any leading / on the path. This might be better done within InventoryFolderImpl
// itself (possibly at a small loss in efficiency).
string[] components
= invPath.Split(new string[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);
invPath = String.Empty;
foreach (string c in components)
{
invPath += c + InventoryFolderImpl.PATH_DELIMITER;
}
{
inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath);
}
inventoryFolder = userInfo.RootFolder.FindFolderByPath(invPath);
}
// if (inventoryFolder == null)
// {
//
// }
}
else
{