org.extex.resource
Class ClasspathArchiveFinder

java.lang.Object
  extended by org.extex.resource.AbstractFinder
      extended by org.extex.resource.ClasspathArchiveFinder
All Implemented Interfaces:
LogEnabled, ResourceFinder

public class ClasspathArchiveFinder
extends AbstractFinder

This resource finder utilizes the Java class finder to search in the class path for index files and resolve a resource via those. Thus it is possible to find resources in the file system or inside a jar archive.

If a file is not found in any index then the resource is reported as not found. The same holds if the file can be resolved with the index but the resource does not exist.

The sequence in which the different indexes on the class path are consulted is unspecified.

Configuration

The resource finder can be configured to influence its actions. The following example shows a configuration for a resource finder:
 <Finder class="org.extex.util.resource.ClasspathArchiveFinder"
         trace="false"
         toc="META-INF/toc.index"
         default="default">
   <tex>
     <extension></extension>
     <extension>.tex</extension>
   </tex>
   <fmt>
     <extension></extension>
     <extension>.fmt</extension>
   </fmt>
   <default>
     <extension></extension>
   </default>
 </Finder>
 

Whenever a resource is sought its type is used to find the appropriate parameters for the search. If the sub-configuration with the name of the type exists then this sub-configuration is used. For instance if the resource tex with the type fmt is sought then the sub-configuration fmt determines how to find this file.

If no sub-configuration of the given type is present then the attribute default is used to find the default sub-configuration. In the example given above this default configuration is called default. Nevertheless it would also be possible to point the default configuration to another existing configuration. The attribute default is mandatory.

Each sub-configuration takes the tag extension in arbitrary number. extension contains the extension appended after the resource name.

All combinations of resource name and extension are tried in turn. If one combination leads to a readable input stream then it is used.

The attribute trace can be used to force a tracing of the actions in the log file. The tracing is performed only if a logger is present when needed. The tracing flag can be overwritten at run-time. The attribute trace is optional.

The attribute toc determines the file to be used as index. The default is toc.index. The attribute toc is optional. The contents of the index file is described below.

Indexing

To speed up the access to resources an index is used by this resource finder. This index file contains a list of files in the form of a properties file mapping file names to file names with full paths:

 # This is a comment
 file1.tex=texmf/data/file1.tex
 file2.tex=texmf/file2.tex
 

The example above shows such a file. The file names and the path are separated by an equals sign. The hash mark acts as comment character if it occurs as first non white-space.

The path contained in the index is taken relative to the index. This means that you have to be careful to adjust the path if it is not in the root directory.

Version:
$Revision: 7132 $
Author:
Gerd Neugebauer

Field Summary
 
Fields inherited from class org.extex.resource.AbstractFinder
ATTR_DEFAULT, ATTR_SKIP, ATTR_TRACE, EXTENSION_TAG
 
Constructor Summary
ClasspathArchiveFinder(Configuration configuration)
          Creates a new object.
 
Method Summary
 NamedInputStream findResource(java.lang.String name, java.lang.String type)
          Find a resource which can be used for reading.
protected  java.util.Map<java.lang.String,java.net.URL> initialize(java.lang.String tocName)
          Initialize the index for searching.
 
Methods inherited from class org.extex.resource.AbstractFinder
enableLogging, enableTracing, getConfiguration, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathArchiveFinder

public ClasspathArchiveFinder(Configuration configuration)
                       throws ConfigurationException
Creates a new object.

Parameters:
configuration - the encapsulated configuration object
Throws:
ConfigurationException - in case of an error
Method Detail

findResource

public NamedInputStream findResource(java.lang.String name,
                                     java.lang.String type)
                              throws ConfigurationException
Find a resource which can be used for reading. If the search fails then null is returned.

Parameters:
name - the base name of the resource
type - the type, i.e. the extension
Returns:
the file or null if none could be found
Throws:
ConfigurationException - in case of an exception
See Also:
ResourceFinder.findResource( java.lang.String, java.lang.String)

initialize

protected java.util.Map<java.lang.String,java.net.URL> initialize(java.lang.String tocName)
                                                           throws ConfigurationWrapperException
Initialize the index for searching.

Parameters:
tocName - the name of the toc file
Returns:
the cache
Throws:
ConfigurationWrapperException - in case of a configuration problem