From 900a6564203b69851cf43fc87eb7190c82acec38 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 31 Jul 2008 18:23:17 +0000 Subject: * refactor: rearrange path inventory manipulation so that input tidying can be used for item paths as well --- .../Communications/Cache/InventoryFolderImpl.cs | 55 ++++++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs') diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index ee3fc55..96853f0 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs @@ -108,7 +108,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// 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 /// /// /// null if the item is not found @@ -197,7 +197,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// 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 /// /// /// 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. /// - /// + /// null if the folder is not found 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; } + + /// + /// 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. + /// + /// + /// The path to the required item. + /// + /// null if the item is not found + 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; + } /// /// Return a copy of the list of child items in this folder @@ -256,7 +301,7 @@ namespace OpenSim.Framework.Communications.Cache } /// - /// 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. /// public List RequestListOfFolders() { -- cgit v1.1