    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.FilteredResource
                                       |
                                       +----w3c.jigsaw.resources.ContainerResource
                                               |
                                               +----w3c.jigsaw.resources.DirectoryResource

public class DirectoryResource
extends ContainerResource
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).

##

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

##

DirectoryResource()

##

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

##

ATTR_DIRECTORY

      protected static int ATTR_DIRECTORY

  Attribute index - The index for our directory attribute.

ATTR_REPOSITORY

      protected static int ATTR_REPOSITORY

  Attribute index - The index of our store identifier.

ATTR_RELOCATE

      protected static int ATTR_RELOCATE

  Attribute index - The index for our relocate attribute.

ATTR_EXTENSIBLE

      protected static int ATTR_EXTENSIBLE

  Attribute index - The index of wether we are extensible.

ATTR_INDEX

      protected static int ATTR_INDEX

  Attribute index - our index resource name.

ATTR_ICONDIR

      protected static int ATTR_ICONDIR

  Attribute index - The icon directory to use in dir listing.

ATTR_DIRSTAMP

      protected static int ATTR_DIRSTAMP

  Attribute index - The last we we physically visited the directory.

ATTR_NEGOTIABLE

      protected static int ATTR_NEGOTIABLE

  Attribute index - Should this directory support content negotiation.

children

      protected ResourceStore children

  Our children resource store.

listing

      protected HtmlGenerator listing

  Our current (cached) directory listing.

listing_stamp

      protected long listing_stamp

  The time at which we generated the directory index.

##

DirectoryResource

      public DirectoryResource()

##

acquireChildren

      protected synchronized void acquireChildren()

  Acquire the directory resource store. Should only be called from a synchronized method.

getClone

      public Object getClone(Object values[])

  Clone this directory resource. Cloning a directory resource does not clone the underlying resource store.
  Overrides:
    getClone in class FilteredResource

updateNegotiableResource

      public synchronized void updateNegotiableResource(String name)

setValue

      public synchronized void setValue(int idx,
                                        Object value)

  Keep our cached repository value in sync.
  Parameters:
    idx - The index of the attribute to set.
    value - The new value for the attribute.
  Overrides:
    setValue in class HTTPResource

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.
  Overrides:
    createDefaultResource in class ContainerResource

registerResource

      public synchronized void registerResource(String identifier,
                                                Resource resource,
                                                Hashtable defs)

  Initialize and register a new resource into this directory.
  Parameters:
    resource - The uninitialized resource to be added.
  Overrides:
    registerResource in class ContainerResource

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.

save

      public synchronized void save()

  Save the current state of the children resource stroe.

getDirectory

      public File getDirectory()

  Get the physical directory exported by this resource.
  Returns:
    A non-null File object giving the directory of this resource.

getRepository

      public File getRepository()

  Get our children resource store identifier.
  Returns:
    A non-null String object, used as our children resource store identifier.

getRelocateFlag

      public boolean getRelocateFlag()

  Should we relocate invalid requests to this directory.
  Returns:
    A boolean true if we should relocate.

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.

getIndex

      public String getIndex()

  Get the optinal index name for this directory listing.

getIconDirectory

      public String getIconDirectory()

  Get the optional icon directory.

getDirStamp

      public long getDirStamp()

  Get the absolute time at which we examined the physicall directory.

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.

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 AttributeHolder

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.

notifyStoreShutdown

      public synchronized void notifyStoreShutdown(ResourceStore store)

  The resource store asks us to shutdown our associated store.
  Parameters:
    store - The store to shutdown.

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.

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.
  Overrides:
    enumerateResourceIdentifiers in class ContainerResource

lookupStore

      protected synchronized HTTPResource lookupStore(String name,
                                                      Hashtable defs)

  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.
    defs - A set of default attribute values.
  Returns:
    A Resource instance, or null if no match was found.

lookupStore

      protected 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.

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.
  Overrides:
    lookup in class ContainerResource

lookup

      public boolean lookup(LookupState ls,
                            LookupResult lr) throws HTTPException

  Lookup the next component of this lookup state in here.
  Parameters:
    ls - The current lookup state.
    lr - The lookup result under construction.
  Returns:
    A boolean, true if lookup has completed, false if it should be continued by the caller.
  Throws: HTTPException
    If an error occurs.
  Overrides:
    lookup in class ContainerResource

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.

checkIfModifiedSince

      public int checkIfModifiedSince(Request request)

  Check the `If-Modified-Since` condition of that request.
  Parameters:
    request - The request to check.
  Returns:
    An integer, either `COND_FAILED if condition was checked, but failed, `COND_OK` if condition was checked and succeeded, or 0 if the condition was not checked at all (eg because the resource or the request didn't support it).`
  Overrides:
    checkIfModifiedSince in class HTTPResource

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

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

delete

      public synchronized void delete()

  Delete this directory resource, for ever. This method will delete the directory resource, and its associated store, along with any of the sub-resources it contains. Deleting the root directory of your server might take sometime...

  Once the resource is deleted, it is removed from its inital store and will not be unpickleable any more.

  Overrides:
    delete in class HTTPResource

delete

      public void delete(String child)

  Delete a given child of this directory resource.
  Parameters:
    child - The identifier of the child to delete.

perform

      public Reply perform(Request request,
                           HTTPFilter filters[]) throws HTTPException, ClientException

  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 HTTPResource

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