Class w3c.jigsaw.resources.DirectoryResource
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.jigsaw.resources.DirectoryResource

java.lang.Object
   |
   +----w3c.jigsaw.resources.AttributeHolder
           |
           +----w3c.jigsaw.resources.Resource
                   |
                   +----w3c.jigsaw.resources.HTTPResource
                           |
                           +----w3c.jigsaw.resources.ContainerResource
                                   |
                                   +----w3c.jigsaw.resources.FilteredResource
                                           |
                                           +----w3c.jigsaw.resources.DirectoryResource

public class DirectoryResource
extends FilteredResource
implements ResourceStoreHolder
A simple, and reasonably efficient directory resource. This directory resource embeds its own resource store object to keep track of its next children (wich might themselves be DirectoryResource). It is reasonably efficient in the sense that it won't overload the memory with unused informations. However, stay tuned for a really efficient file based directory resource (tuned to serve only files).

Variable Index

 o ATTR_DIRECTORY
Attribute index - The index for our directory attribute.
 o ATTR_DIRSTAMP
Attribute index - The last we we physically visited the directory.
 o ATTR_EXTENSIBLE
Attribute index - The index of wether we are extensible.
 o ATTR_ICONDIR
Attribute index - The icon directory to use in dir listing.
 o ATTR_INDEX
Attribute index - our index resource name.
 o ATTR_NEGOTIABLE
Attribute index - Should this directory support content negotiation.
 o ATTR_RELOCATE
Attribute index - The index for our relocate attribute.
 o ATTR_STOREID
Attribute index - The index of our store identifier.
 o children
Our children resource store.
 o listing
Our current (cached) directory listing.
 o listing_stamp
The time at which we generated the directory index.
 o repository
Get the children resource store repository.

Constructor Index

 o DirectoryResource()

Method Index

 o acquireChildren()
Acquire the directory resource store.
 o createDefaultResource(String)
Try creating a default resource having the given name.
 o enumerateResourceIdentifiers()
Enumerate all available children resource identifiers.
 o get(Request)
GET on a directory, generate a directory listing.
 o getDirectory()
Get the physical directory exported by this resource.
 o getDirectoryListing(Request)
Reply with an HTML doc listing the resources of this directory.
 o getDirStamp()
Get the absolute time at which we examined the physicall directory.
 o getExtensibleFlag()
Get the extensible flag value.
 o getIconDirectory()
Get the optional icon directory.
 o getIndex()
Get the optinal index name for this directory listing.
 o getNegotiableFlag()
Get the negotiable flag for this directory.
 o getRelocateFlag()
Should we relocate invalid requests to this directory.
 o getRepository()
 o getStoreIdentifier()
Get our children resource store identifier.
 o initialize(Object[])
Initialize this directory resource with the given set of attributes.
 o lookup(LookupState)
Lookup the next component of this lookup state in here.
 o lookup(String)
Lookup the resource having the given name in this directory.
 o lookupStore(String)
Lookup our store for a child of the given name.
 o main(String[])
Create an empty resource store, and store a default resource directory in it.
 o notifyStoreShutdown(ResourceStore)
The resource store asks us to shutdown our associated store.
 o notifyStoreStabilize(ResourceStore)
The resource store asks us to save our store.
 o notifyStoreUnload(ResourceStore)
The resource store manager asks us to get rid of our store.
 o notifyUnload()
We are being unloaded.
 o perform(Request)
Perform requests on a directory.
 o registerResource(String, Resource, Hashtable)
Register a new resource into this directory.
 o save()
Save the current state of the children resource stroe.
 o unregisterResource(String)
Unregister the resource.
 o updateNegotiableResource(String)

Variables

 o ATTR_DIRECTORY
  protected static int ATTR_DIRECTORY
Attribute index - The index for our directory attribute.
 o ATTR_STOREID
  protected static int ATTR_STOREID
Attribute index - The index of our store identifier.
 o ATTR_RELOCATE
  protected static int ATTR_RELOCATE
Attribute index - The index for our relocate attribute.
 o ATTR_EXTENSIBLE
  protected static int ATTR_EXTENSIBLE
Attribute index - The index of wether we are extensible.
 o ATTR_INDEX
  protected static int ATTR_INDEX
Attribute index - our index resource name.
 o ATTR_ICONDIR
  protected static int ATTR_ICONDIR
Attribute index - The icon directory to use in dir listing.
 o ATTR_DIRSTAMP
  protected static int ATTR_DIRSTAMP
Attribute index - The last we we physically visited the directory.
 o ATTR_NEGOTIABLE
  protected static int ATTR_NEGOTIABLE
Attribute index - Should this directory support content negotiation.
 o children
  protected ResourceStore children
Our children resource store.
 o listing
  protected HtmlGenerator listing
Our current (cached) directory listing.
 o repository
  protected File repository
Get the children resource store repository.
 o listing_stamp
  protected long listing_stamp
The time at which we generated the directory index.

Constructors

 o DirectoryResource
  public DirectoryResource()

Methods

 o getRepository
  protected File getRepository()
 o acquireChildren
  protected synchronized void acquireChildren()
Acquire the directory resource store. Should only be called from a synchronized method.
 o updateNegotiableResource
  public synchronized void updateNegotiableResource(String name)
 o createDefaultResource
  public synchronized HTTPResource createDefaultResource(String name)
Try creating a default resource having the given name. This method will make its best effort to create a default resource having this name in the directory. If a file with this name exists, it will check the pre-defined admin extensions and look for a match. If a directory with this name exists, and admin allows to do so, it will create a sub-directory resource.
Parameters:
name - The name of the resource to try to create.
Returns:
A Resource instance, if possible, null otherwise.
 o registerResource
  public synchronized void registerResource(String identifier,
                                            Resource resource,
                                            Hashtable defs)
Register a new resource into this directory.
Parameters:
resource - The uninitialized resource to be added.
 o unregisterResource
  public synchronized void unregisterResource(String identifier)
Unregister the resource. If the resource identifier by the given identifier was a child resource of this directory resource, it wil lbe removed.
Parameters:
identifier - The identifier of the child to remove.
 o save
  public synchronized void save()
Save the current state of the children resource stroe.
 o getDirectory
  public File getDirectory()
Get the physical directory exported by this resource.
Returns:
A non-null File object giving the directory of this resource.
 o getStoreIdentifier
  public String getStoreIdentifier()
Get our children resource store identifier.
Returns:
A non-null String object, used as our children resource store identifier.
 o getRelocateFlag
  public boolean getRelocateFlag()
Should we relocate invalid requests to this directory.
Returns:
A boolean true if we should relocate.
 o getExtensibleFlag
  public boolean getExtensibleFlag()
Get the extensible flag value. A DirectoryResource is extensible, if it is allowed to create new resources out of the file system knowledge on the fly.

Setting this flag might slow down the server. It unfortunatelly defaults to true until I have a decent admin program.

Returns:
A boolean true if the directory is extensible.
 o getIndex
  public String getIndex()
Get the optinal index name for this directory listing.
 o getIconDirectory
  public String getIconDirectory()
Get the optional icon directory.
 o getDirStamp
  public long getDirStamp()
Get the absolute time at which we examined the physicall directory.
 o getNegotiableFlag
  public boolean getNegotiableFlag()
Get the negotiable flag for this directory. When turned to true, this flag indicates to the directory resource that it should automatically build negotiated resources ont op of all existing resources.

You should know, at least, that truning this flag on has some not so small cost in terms of the size of the index files, and some not so small costs in CPU time when detecting not found documents. Otherwise, in all other situations its cost is probably negligible.

 o initialize
  public void initialize(Object values[])
Initialize this directory resource with the given set of attributes.
Parameters:
values - The attribute values.
Overrides:
initialize in class FilteredResource
 o notifyStoreUnload
  public synchronized boolean notifyStoreUnload(ResourceStore store)
The resource store manager asks us to get rid of our store. The resource store manager has decided that our store hasn't been used enough in the past to be worth keeping around. Shut it down and get rid of any pointers we have to it, so that the garbage collector will really get rid of it.

We can still defer this operation by returning false in case a user is editing the store for example.

Parameters:
store - The store that has to be freed.
Returns:
A boolean true if the resource store has been shutdown properly, false otherwise.
 o notifyStoreShutdown
  public synchronized void notifyStoreShutdown(ResourceStore store)
The resource store asks us to shutdown our associated store.
Parameters:
store - The store to shutdown.
 o notifyStoreStabilize
  public synchronized boolean notifyStoreStabilize(ResourceStore store)
The resource store asks us to save our store. Our store has probably been modified recently, save it.
Parameters:
store - The store to save.
Returns:
A boolean true if success.
 o enumerateResourceIdentifiers
  public synchronized Enumeration enumerateResourceIdentifiers()
Enumerate all available children resource identifiers. This method requires that we create all our pending resources if we are in the extensible mode...too bad !
Returns:
An enumeration of all our resources.
 o lookupStore
  public synchronized HTTPResource lookupStore(String name)
Lookup our store for a child of the given name. This methods may trigger, on its first call, the creation of the children ResourceStore wich is done is a lazy way, so that areas not often visited don't get their store loaded.
Parameters:
name - The name of the child to lookup.
Returns:
A Resource instance, or null if no match was found.
 o lookup
  public HTTPResource lookup(String name)
Lookup the resource having the given name in this directory.
Parameters:
name - The name of the resource.
Returns:
A resource instance, or null.
 o lookup
  public HTTPResource lookup(LookupState state) throws HTTPException
Lookup the next component of this lookup state in here.
Parameters:
state - The current lookup state.
Returns:
A resource instance, or null if no match was found.
Overrides:
lookup in class ContainerResource
 o getDirectoryListing
  public Reply getDirectoryListing(Request request) throws HTTPException
Reply with an HTML doc listing the resources of this directory. This function takes special care not to regenerate a directory listing when one is available. It also caches the date of the directory listing, so that it can win big with NOT_MODIFIED.

Using a modem, I know that each place I can reply with an NOT_MODIFIED, is a big win.

Parameters:
request - The request to handle.
Throws: HTTPException
If processsing the request failed.
 o get
  public Reply get(Request request) throws HTTPException
GET on a directory, generate a directory listing.
Parameters:
request - The request to handle.
Overrides:
get in class HTTPResource
 o notifyUnload
  public synchronized void notifyUnload()
We are being unloaded. Cleanup-up our attribute values, and make sure our store is closed.
Overrides:
notifyUnload in class Resource
 o perform
  public Reply perform(Request request) throws HTTPException
Perform requests on a directory. If an index has been given , this method delegates the actual handling of the request to it.
Parameters:
request - The request to handle.
Overrides:
perform in class FilteredResource
 o main
  public static void main(String args[]) throws Exception
Create an empty resource store, and store a default resource directory in it.

All Packages  Class Hierarchy  This Package  Previous  Next  Index