//=-- ResourceManager.h - Contexts we can load resources from ----*- C++ -*---=
//
//  The ResourceManager class provides a context for loading themes and other 
//  resources.  If AllowUserResources is true (set only by the server 
//  configuration file), then this class first searches the user's local 
//  resource directories for files.  If it is not found there or if 
//  AllowUserResources is false, then the Server Resource locations are 
//  checked.  If the file is not found there either, then an error is returned.
//
//  It is possible for the user to specify many locations in the filesystem to
//  load resources (themes/plugins) from.  Each filesystem location has a 
//  unique location in the filesystem as well as in web server space.  Thus,
//  each location has a path and a URL that corresponds to it.  This class
//  keeps track of this kind of information.
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-1999 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H

#include "MSString.h"
#include "Table.h"
#include "LinkedList.h"

class MSFilename;

class ResourceManager {
public :
  static int AllowUserResources;

  ResourceManager();
  ~ResourceManager();

  // PrintThemes - Print out all of the themes (with interesting info) in a
  // nice format, used for the -T commandline parameter.
  //
  static void PrintThemes();

  // FindTheme - Searches the user and server paths and returns the filename 
  // of the theme.  If the theme isn't found, an nonzero value is returned.
  // The result of the search is contained in the ReturnPath and ReturnURL
  // parameters...
  //
  static int FindTheme(const String &ThemeName,
                       String &ReturnPath, String &ReturnURL);

  // FindPlugin - Searches the user and server paths and returns the filename 
  // of the specified plugin.  If the plugin isn't found, an nonzero value is 
  // returned.  The result of the search is passed back in the ReturnPath and 
  // ReturnURL parameters...
  //
  static int FindPlugin(const String &ThemeName,
                        String &ReturnPath, String &ReturnURL);

  // GetPluginFiles - Get a list of all of the plugins found in resource 
  // directories...  the primary element of the DataPair is the Filename,
  // the secondary portion is the URL of the directory.
  //
  static LinkedList<DataPair<MSFilename,String> > GetPluginFiles();

  // AddResourceLocation - The URL field may contain a variable "%u" that is 
  // expanded to the current user name.  This is not valid, however, in user 
  // config files.  Use the ($ms.Username) variable instead.
  //
  static int AddResourceLocation(const MSFilename &ResPath, const String &URL, 
                                 int ServerResource);

  // PrintResourcePaths - Print out all of the resource paths currently being 
  // used.  Each path is printed on a seperate line with "Indent" spaces before
  // each.
  static void PrintResourcePaths(int Indent);

  // Index into the ThemeFound and PluginsFound array's below... 
  // also passed to AddResourceLocation
  //
  enum { UserResource = 0, ServerResource = 1 };

private :
  static String CurrentUserName; // Value to expand %u into.  Set by constructor

  // Keep track of directories already checked.
  static LinkedList<String> *ResourcesSearched;

  // The Key is the Theme name.  The first part of the value is the Path, the 
  // second portion is the Theme URL.
  //
  static Table<CSString, DataPair<MSFilename,String> > *ThemesFound[2];

  // The Key is the Plugin name.  The first part of the value is the Path, the 
  // second portion is the Plugin URL.
  //
  static Table<CSString, DataPair<MSFilename,String> > *PluginsFound[2];
};

#endif
