org.extex.resource
Class LsrFinder

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

public class LsrFinder
extends AbstractFinder
implements PropertyAware, EnvironmentAware

This resource finder searches a file in a ls-R file database as present in a texmf tree. For this purpose the ls-R file databases found are read and stored internally.

Configuration

The lsr finder can be configured to influence its actions. The following example shows a configuration for a lsr finder:
 <Finder class="de.dante.util.resource.LsrFinder"
          default="default"
          capacity="1234567"
          trace="false">
   <path property="extex.font.path"></path>
   <path property="texmf.path"></path>
   <tfm><extension>.tfm</extension></tfm>
   <efm><extension>.efm</extension></efm>
   <pfb><extension>.pfb</extension></pfb>
   <ttf><extension>.ttf</extension></ttf>
   <default><extension/></default>
 </Finder>
 

Whenever a resource is sought the first step is to ensure that the file databases are read in. For this purpose the path tag is used. The path tags name directories which may contain file databases. The file databases have a fixed name ls-R.

path can carry the attribute property. In this case the value is ignored and the value is taken from the property named in the attribute. Otherwise the value of the tag is taken as path. The value taken from the property can contain several paths. They are separated by the separator specified for the platform. For instance on windows the separator ; is used and on Unix the separator : is used.

path can carry the attribute env. In this case the value is ignored and the value is taken from the environment variable named in the attribute. Otherwise the value of the tag is taken as path. The value taken from the environment variable can contain several paths. They are separated by the separator specified for the platform. For instance on windows the separator ; is used and on Unix the separator : is used.

To find a resource 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 extension in arbitrary number. extension contains the extension appended after the resource name.

All combinations of resource name and extension are tried in turn to be found in the file database. If one combination leads to a readable file then an input stream to this file 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 capacity can be used to configure the initial capacity of the internal cache for the file database. If this number is less than one than an internal default is used. This value should be larger than the number of files expected for best performance. The attribute capacity is optional.

Version:
$Revision: 7045 $
Author:
Gerd Neugebauer, Michael Niedermair

Field Summary
 
Fields inherited from class org.extex.resource.AbstractFinder
ATTR_DEFAULT, ATTR_SKIP, ATTR_TRACE, EXTENSION_TAG
 
Constructor Summary
LsrFinder(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.
 void setEnvironment(java.util.Map<java.lang.String,java.lang.String> environment)
          Setter for the environment.
 void setProperties(java.util.Properties prop)
          Setter for the properties.
 
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

LsrFinder

public LsrFinder(Configuration configuration)
          throws ConfigurationMissingException
Creates a new object.

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

findResource

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

Specified by:
findResource in interface ResourceFinder
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)

setEnvironment

public void setEnvironment(java.util.Map<java.lang.String,java.lang.String> environment)
Setter for the environment. The default for the environment is the system environment.

Specified by:
setEnvironment in interface EnvironmentAware
Parameters:
environment - the environment

setProperties

public void setProperties(java.util.Properties prop)
Setter for the properties.

Specified by:
setProperties in interface PropertyAware
Parameters:
prop - the new properties
See Also:
PropertyAware.setProperties( java.util.Properties)