/// <summary>
        /// Loads a collection of Scriptlet Objects for the given theme and given type from the cache
        /// </summary>
        /// <param name="scriptletType">Type of scriptlets to load</param>
        /// <param name="sortExpression">The sort expression to use for sorting the loaded objects.</param>
        /// <param name="themeId">Theme for which to load the scriptlets</param>
        /// <returns>A collection of Scriptlet objects</returns>
        public static ScriptletCollection CacheLoad(string themeId, ScriptletType scriptletType, string sortExpression)
        {
            ScriptletCollection scriptlets = GetCachedScriptlets(themeId);
            ScriptletCollection subset     = new ScriptletCollection();

            foreach (Scriptlet item in scriptlets)
            {
                if ((scriptletType == ScriptletType.Unspecified) || (item.ScriptletType == scriptletType))
                {
                    subset.Add(item);
                }
            }
            if (sortExpression != string.Empty)
            {
                subset.Sort(sortExpression);
            }
            return(subset);
        }
        /// <summary>
        /// Loads a Scriptlet object with given identifier and type from the database
        /// </summary>
        /// <param name="themeId">Name/Identifier of the theme</param>
        /// <param name="identifier">Identifier of Scriptlet to load</param>
        /// <param name="scriptletType">Type of of Scriptlet to load</param>
        /// <param name="custom">Is the Scriptlet to be loaded a custom scriptlet?</param>
        /// <param name="useCache">If <b>true</b> tries to load the object from cache first</param>
        /// <returns>The Scriptlet object loaded</returns>
        public static Scriptlet Load(string themeId, string identifier, ScriptletType scriptletType, BitFieldState custom, bool useCache)
        {
            if (useCache)
            {
                ScriptletCollection scriptlets = CacheLoad(themeId);
                int index = scriptlets.IndexOf(identifier, scriptletType, custom);
                if (index > -1)
                {
                    return(scriptlets[index]);
                }
                return(null);
            }
            //(DO NOT USE CACHE, LOAD FOR THE NAME)
            Scriptlet s = new Scriptlet();

            if (s.Load(themeId, identifier, scriptletType, custom))
            {
                return(s);
            }
            return(null);
        }
        /// <summary>
        /// Loads all Scriptlet objects for the given theme
        /// </summary>
        /// <returns>A collection of all Scriptlet objects in the store</returns>
        public static ScriptletCollection LoadAll(string themeId)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;
            Hashtable           ht          = new Hashtable();
            ScriptletCollection results     = new ScriptletCollection();
            //LOAD CUSTOM SCRIPTLETS FIRST
            string pathPart;

            if (string.IsNullOrEmpty(themeId))
            {
                pathPart = "App_Data\\Scriptlets";
            }
            else
            {
                pathPart = "App_Themes\\" + themeId + "\\Scriptlets";
                if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart)))
                {
                    pathPart = "App_Data\\Scriptlets";
                }
            }

            DirectoryInfo di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart + "\\Custom"));

            if (di.Exists)
            {
                DirectoryInfo[] folders = di.GetDirectories();
                foreach (DirectoryInfo folder in folders)
                {
                    ScriptletType scriptletType;
                    try
                    {
                        scriptletType = (ScriptletType)Enum.Parse(typeof(ScriptletType), folder.Name, true);
                    }
                    catch (ArgumentException)
                    {
                        //FOLDER IS NOT A RECOGNIZED SCRIPTLET TYPE
                        scriptletType = ScriptletType.Unspecified;
                    }
                    if (scriptletType != ScriptletType.Unspecified)
                    {
                        FileInfo[] files = folder.GetFiles("*.htm");
                        foreach (FileInfo file in files)
                        {
                            string    identifier = Path.GetFileNameWithoutExtension(file.Name);
                            string    hashkey    = scriptletType.ToString() + "_" + identifier;
                            Scriptlet s          = ScriptletDataSource.Load(themeId, identifier, scriptletType, BitFieldState.True, false);
                            if (s != null)
                            {
                                ht.Add(s.ScriptletType + "_" + s.Identifier, true);
                                results.Add(s);
                            }
                        }
                    }
                }
            }
            //LOAD DEFAULT SCRIPTLETS NEXT
            di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart + "\\Default"));
            if (di.Exists)
            {
                DirectoryInfo[] folders = di.GetDirectories();
                foreach (DirectoryInfo folder in folders)
                {
                    ScriptletType scriptletType;
                    try
                    {
                        scriptletType = (ScriptletType)Enum.Parse(typeof(ScriptletType), folder.Name, true);
                    }
                    catch (ArgumentException)
                    {
                        //FOLDER IS NOT A RECOGNIZED SCRIPTLET TYPE
                        scriptletType = ScriptletType.Unspecified;
                    }
                    if (scriptletType != ScriptletType.Unspecified)
                    {
                        FileInfo[] files = folder.GetFiles("*.htm");
                        foreach (FileInfo file in files)
                        {
                            string identifier = Path.GetFileNameWithoutExtension(file.Name);
                            string hashkey    = scriptletType.ToString() + "_" + identifier;
                            if (!ht.ContainsKey(hashkey))
                            {
                                Scriptlet s = ScriptletDataSource.Load(themeId, identifier, scriptletType, BitFieldState.False, false);
                                if (s != null)
                                {
                                    ht.Add(hashkey, true);
                                    results.Add(s);
                                }
                            }
                        }
                    }
                }
            }
            return(results);
        }