org.w3c.tools.resources.indexer
Class SampleResourceIndexer

java.lang.Object
  extended by org.w3c.tools.resources.AttributeHolder
      extended by org.w3c.tools.resources.Resource
          extended by org.w3c.tools.resources.indexer.SampleResourceIndexer
All Implemented Interfaces:
java.lang.Cloneable, ContainerInterface, ResourceIndexer
Direct Known Subclasses:
ConfigResourceIndexer, ContentTypeIndexer, GhostResourceIndexer, ServletIndexer, ZipIndexer

public class SampleResourceIndexer
extends Resource
implements ContainerInterface, ResourceIndexer

A container for directories and templates.


Field Summary
protected static int ATTR_NOT_INDEXED
          Attribute index - the super indexer, if any.
protected static int ATTR_SUPER_INDEXER
          Attribute index - the super indexer, if any.
protected  ResourceReference contentTypes
           
protected static java.lang.String defname
           
protected  ResourceReference directories
           
protected static boolean extCaseSensitive
           
protected  ResourceReference extensions
           
static boolean isWinPlatform
           
 
Fields inherited from class org.w3c.tools.resources.Resource
ATTR_CONTEXT, ATTR_HELP_URL, ATTR_IDENTIFIER, ATTR_LAST_MODIFIED, ATTR_PARENT, ATTR_RESOURCE_FRAMES, ATTR_STORE_ENTRY, ATTR_URL, co, id
 
Fields inherited from class org.w3c.tools.resources.AttributeHolder
attributes, values
 
Constructor Summary
SampleResourceIndexer()
           
SampleResourceIndexer(ResourceContext ctxt)
           
 
Method Summary
protected  Resource createDirectoryResource(java.io.File directory, RequestInterface req, java.lang.String name, java.util.Hashtable defs)
          Create a default container resource for this directory (that exists).
protected  Resource createFileResource(java.io.File directory, RequestInterface req, java.lang.String name, java.util.Hashtable defs)
          Create a default file resource for this file (that exists).
 Resource createResource(ContainerResource container, RequestInterface request, java.io.File directory, java.lang.String name, java.util.Hashtable defs)
          Try to create a resource for the given file.
protected  Resource createVirtualResource(java.io.File directory, RequestInterface req, java.lang.String name, java.util.Hashtable defs)
          Try to create a virtual resource if the real (physical) resource is not there.
 void delete()
          Delete this inexer
 void delete(java.lang.String name)
          Remove a child resource from that container.
 java.util.Enumeration enumerateResourceIdentifiers(boolean all)
          Enumerate children resource identifiers.
protected  ResourceReference getDirectories()
           
protected  ResourceReference getExtensions()
           
protected  java.lang.String[] getFileExtensions(java.lang.String name)
           
protected  java.lang.String getIndexedDirName(java.lang.String name)
           
protected  java.lang.String getIndexedFileName(java.lang.String name)
           
 java.lang.String getIndexedName(java.io.File directory, java.lang.String name)
          Get the name of the resource relative to the given filename.
 java.lang.String getSuperIndexer()
           
protected  ResourceReference getTemplateFor(java.lang.String ext)
          Return the class (if any) that our store defines for given extension.
 long lastModified()
          When was this indexer configuration last modified.
 ResourceReference loadDirectory(java.lang.String name)
          Load a given directory template from the store.
 ResourceReference loadExtension(java.lang.String name)
           
 ResourceReference lookup(java.lang.String name)
          Lookup a children in the container.
protected  java.util.Hashtable mergeDefaultAttributes(Resource template, java.lang.String ext, java.util.Hashtable into)
          Merge the attributes this extension defines, with the provided ones.
protected  void mergeFrameAttributes(ResourceFrame origFrame, java.lang.String ext, ResourceReference frameref)
          Merge the attributes this extension defines, with the provided ones.
 void registerResource(java.lang.String name, Resource resource, java.util.Hashtable defs)
          Initialize and register the given resource within that container.
 
Methods inherited from class org.w3c.tools.resources.Resource
acceptUnload, checkMultipleLock, collectFrames, getClone, getContext, getFrame, getFrames, getHelpURL, getHelpURL, getIdentifier, getLastModified, getParent, getResourceReference, getServer, getSpace, getSpaceEntry, getStoreEntry, getURLPath, getValue, getValue, initialize, initialize, isInitialized, isUnloaded, markModified, notifyUnload, pickleValues, registerFrame, setContext, setContext, setValue, setValue, unregisterFrame, unsafeGetContext, unsafeGetFrame, unsafeGetFrames, unsafeGetIdentifier, unsafeGetResourceReference, unsafeGetURLPath, unsafeGetValue, updateAttributes
 
Methods inherited from class org.w3c.tools.resources.AttributeHolder
definesAttribute, definesAttribute, getAttributes, getBoolean, getChar, getClone, getClone, getDouble, getFloat, getInt, getLong, getString, getValue, lookupAttribute, print, setBoolean, setChar, setDouble, setFloat, setInt, setLong, setString, setValue, unsafeDefinesAttribute, unsafeGetDouble, unsafeGetString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extCaseSensitive

protected static final boolean extCaseSensitive
See Also:
Constant Field Values

defname

protected static final java.lang.String defname
See Also:
Constant Field Values

isWinPlatform

public static boolean isWinPlatform

ATTR_SUPER_INDEXER

protected static int ATTR_SUPER_INDEXER
Attribute index - the super indexer, if any.


ATTR_NOT_INDEXED

protected static int ATTR_NOT_INDEXED
Attribute index - the super indexer, if any.


directories

protected ResourceReference directories

extensions

protected ResourceReference extensions

contentTypes

protected ResourceReference contentTypes
Constructor Detail

SampleResourceIndexer

public SampleResourceIndexer(ResourceContext ctxt)

SampleResourceIndexer

public SampleResourceIndexer()
Method Detail

getDirectories

protected ResourceReference getDirectories()

getExtensions

protected ResourceReference getExtensions()

lastModified

public long lastModified()
Description copied from interface: ResourceIndexer
When was this indexer configuration last modified.

Specified by:
lastModified in interface ResourceIndexer
Returns:
The date at which that indexer was last modified, as a number of milliseconds since Java epoch.

getSuperIndexer

public java.lang.String getSuperIndexer()

enumerateResourceIdentifiers

public java.util.Enumeration enumerateResourceIdentifiers(boolean all)
Description copied from interface: ContainerInterface
Enumerate children resource identifiers.

Specified by:
enumerateResourceIdentifiers in interface ContainerInterface
Parameters:
all - Should all resources be enumerated ? Resources are often created on demand only, this flag allows the caller to tell the container about wether it is interested only in already created resources, or in all resources (even the one that have not yet been created).
Returns:
An String enumeration, one element per child.

lookup

public ResourceReference lookup(java.lang.String name)
Description copied from interface: ContainerInterface
Lookup a children in the container.

Specified by:
lookup in interface ContainerInterface
Parameters:
name - The name of the children to lookup. the resource from its store.

delete

public void delete()
            throws MultipleLockException
Delete this inexer

Overrides:
delete in class Resource
Throws:
MultipleLockException - if someone else has locked the indexer.

delete

public void delete(java.lang.String name)
Description copied from interface: ContainerInterface
Remove a child resource from that container.

Specified by:
delete in interface ContainerInterface
Parameters:
name - The name of the child to remove.

registerResource

public void registerResource(java.lang.String name,
                             Resource resource,
                             java.util.Hashtable defs)
Description copied from interface: ContainerInterface
Initialize and register the given resource within that container.

Specified by:
registerResource in interface ContainerInterface
Parameters:
name - The identifier for the resource.
resource - An unitialized resource instance.
defs - A default set of init attribute values (may be null).

loadExtension

public ResourceReference loadExtension(java.lang.String name)

getTemplateFor

protected ResourceReference getTemplateFor(java.lang.String ext)
Return the class (if any) that our store defines for given extension.

Parameters:
ext - The extension we want a class for.
Returns:
A Class instance, or null.

mergeDefaultAttributes

protected java.util.Hashtable mergeDefaultAttributes(Resource template,
                                                     java.lang.String ext,
                                                     java.util.Hashtable into)
Merge the attributes this extension defines, with the provided ones.

Parameters:
attrs - The attributes we want to fill with default values.
ext - The extension name.
into - The already built set of default values.
Returns:
A Hashtable, containing the augmented set of default attribute values.

mergeFrameAttributes

protected void mergeFrameAttributes(ResourceFrame origFrame,
                                    java.lang.String ext,
                                    ResourceReference frameref)
Merge the attributes this extension defines, with the provided ones.

Parameters:
origFrame - The original frame
ext - The extension name
into - The ResourceReference of the frame to be merged

getFileExtensions

protected java.lang.String[] getFileExtensions(java.lang.String name)

createFileResource

protected Resource createFileResource(java.io.File directory,
                                      RequestInterface req,
                                      java.lang.String name,
                                      java.util.Hashtable defs)
Create a default file resource for this file (that exists).

Parameters:
directory - The directory of the file.
name - The name of the file.
defs - A set of default attribute values.
Returns:
An instance of Resource, or null if we were unable to create it.

loadDirectory

public ResourceReference loadDirectory(java.lang.String name)
Load a given directory template from the store.

Parameters:
name - The name of the template to load.
Returns:
An instance of ResourceReference, or null.

createDirectoryResource

protected Resource createDirectoryResource(java.io.File directory,
                                           RequestInterface req,
                                           java.lang.String name,
                                           java.util.Hashtable defs)
Create a default container resource for this directory (that exists).

Parameters:
directory - The parent directory.
req - the request that triggered this creation
name - The name of its sub-directory to index.
defaults - A set of default atribute values.
Returns:
A Resource instance, or null if the indexer was unable to build a default resource for the directory.

createVirtualResource

protected Resource createVirtualResource(java.io.File directory,
                                         RequestInterface req,
                                         java.lang.String name,
                                         java.util.Hashtable defs)
Try to create a virtual resource if the real (physical) resource is not there.

Parameters:
directory - The directory the file is in.
req - the request that triggered this creation
name - The name of the file.
defs - Any default attribute values that should be provided to the created resource at initialization time.
Returns:
A Resource instance, or null if the given file can't be truned into a resource given our configuration database.

createResource

public Resource createResource(ContainerResource container,
                               RequestInterface request,
                               java.io.File directory,
                               java.lang.String name,
                               java.util.Hashtable defs)
Try to create a resource for the given file. This method makes its best efforts to try to build a default resource out of a file.

Specified by:
createResource in interface ResourceIndexer
Parameters:
directory - The directory the file is in.
name - The name of the file.
defs - Any default attribute values that should be provided to the created resource at initialization time.
container - The container making the call.
request - The HTTP request that triggered the call to the indexer (may be null).
Returns:
A Resource instance, or null if the given file can't be truned into a resource given our configuration database.

getIndexedName

public java.lang.String getIndexedName(java.io.File directory,
                                       java.lang.String name)
Get the name of the resource relative to the given filename.

Specified by:
getIndexedName in interface ResourceIndexer
Parameters:
name - The name of the file.
Returns:
a String, the resource name.

getIndexedFileName

protected java.lang.String getIndexedFileName(java.lang.String name)

getIndexedDirName

protected java.lang.String getIndexedDirName(java.lang.String name)