org.merlotxml.util.xml
Class DTDCache

java.lang.Object
  |
  +--org.merlotxml.util.xml.DTDCache

public class DTDCache
extends java.lang.Object

This singleton class is responsible for loading and caching all DTD's required by the system. This manager can load DTD's from the filesystem, URL's, and zip/jar files (not currently implemented).

Apps should use this class to retrieve all their DTD's for valid documents (non-validating apps usually ignore the DTD anyway, so they don't really need to use this, but if they do get a DTD, it might be a good idea to call into this class.

Here's an example of getting a dtd:
DTDCacheEntry dtdentry = DTDCache.getSharedInstance().findDTD(publicId, systemId);
where publicId is the DOCTYPE's given public identifier (can be null), and systemId is a system designator (file path or URL)

This can also cache DTD's from other entity resolvers via the resolveDTD method.

Version:
$Id: DTDCache.java,v 1.13 2000/08/27 07:39:02 camk Exp $
Author:
Kelly A. Campbell

Field Summary
protected  java.util.Map _dtdEntries
          List of unique dtd entries.
protected  java.util.Map _filepathCache
          key is the file path (including a ! and the path within a jar), val is a DTDCacheEntry
protected static DTDCache _instance
          singleton instance
protected  java.util.Properties _properties
          Properties for getting dtd path, etc.
protected  java.util.Map _publicIdCache
          key is the public id, val is a DTDCacheEntry
protected static java.lang.Object _synchronizer
          synch object for creating the instance
protected  java.util.Map _systemIdCache
          key is the system id, val is a DTDCacheEntry
 
Constructor Summary
protected DTDCache()
           
 
Method Summary
 void checkCacheEntryTimestamp(DTDCacheEntry entry)
          Checks the timestamp associated with a cache entry and reloads the dtd file if it has changed.
protected  void debug(java.lang.String s)
          simple debugging print routine
 DTDCacheEntry findDTD(java.lang.String pubid, java.lang.String sysid, java.lang.String fileLocation)
          find a DTD based on the public id and system id
 DTDCacheEntry findDTDbyPublicId(java.lang.String publicId, java.lang.String systemId)
          Looks in our cache for a file with a given public ID
 DTDCacheEntry findDTDbySystemId(java.lang.String publicId, java.lang.String systemId, java.lang.String fileLocation)
          Finds a dtd given a system identifier.
protected  java.lang.String fixslashes(java.lang.String s)
          make all slashes forward slashes cause windows sucks
 java.util.Collection getCachedDTDEntries()
           
static DTDCache getSharedInstance()
          gets the singleton instance.
 void loadDTDIntoCache(java.io.InputStream is, DTDCacheEntry entry)
          Loads a dtd into a DTDCacheEntry.
 void loadDTDIntoCache(java.io.Reader r, DTDCacheEntry entry)
          Loads a dtd into a DTDCacheEntry.
 void printCache()
           
 DTDCacheEntry resolveDTD(java.lang.String publicId, java.lang.String systemId, org.xml.sax.EntityResolver resolver, java.lang.String fileLocation)
          resolve a dtd from another resolver.
 void setProperties(java.util.Properties props)
          set the properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_publicIdCache

protected java.util.Map _publicIdCache
key is the public id, val is a DTDCacheEntry

_systemIdCache

protected java.util.Map _systemIdCache
key is the system id, val is a DTDCacheEntry

_filepathCache

protected java.util.Map _filepathCache
key is the file path (including a ! and the path within a jar), val is a DTDCacheEntry

_dtdEntries

protected java.util.Map _dtdEntries
List of unique dtd entries. key is the dtd entry, value is not used (null)

_properties

protected java.util.Properties _properties
Properties for getting dtd path, etc. from

_instance

protected static DTDCache _instance
singleton instance

_synchronizer

protected static final java.lang.Object _synchronizer
synch object for creating the instance
Constructor Detail

DTDCache

protected DTDCache()
Method Detail

getSharedInstance

public static DTDCache getSharedInstance()
gets the singleton instance.

setProperties

public void setProperties(java.util.Properties props)
set the properties. should really only be called once by some app initializer

findDTDbySystemId

public DTDCacheEntry findDTDbySystemId(java.lang.String publicId,
                                       java.lang.String systemId,
                                       java.lang.String fileLocation)
Finds a dtd given a system identifier. If it cannot be found, null is returned

findDTDbyPublicId

public DTDCacheEntry findDTDbyPublicId(java.lang.String publicId,
                                       java.lang.String systemId)
Looks in our cache for a file with a given public ID

findDTD

public DTDCacheEntry findDTD(java.lang.String pubid,
                             java.lang.String sysid,
                             java.lang.String fileLocation)
find a DTD based on the public id and system id

resolveDTD

public DTDCacheEntry resolveDTD(java.lang.String publicId,
                                java.lang.String systemId,
                                org.xml.sax.EntityResolver resolver,
                                java.lang.String fileLocation)
                         throws org.xml.sax.SAXException,
                                java.io.IOException
resolve a dtd from another resolver. This way we can cache it locally.

loadDTDIntoCache

public void loadDTDIntoCache(java.io.InputStream is,
                             DTDCacheEntry entry)
                      throws java.io.IOException
Loads a dtd into a DTDCacheEntry.

loadDTDIntoCache

public void loadDTDIntoCache(java.io.Reader r,
                             DTDCacheEntry entry)
                      throws java.io.IOException
Loads a dtd into a DTDCacheEntry. The public and system id's should be set on the dtd entry.

checkCacheEntryTimestamp

public void checkCacheEntryTimestamp(DTDCacheEntry entry)
Checks the timestamp associated with a cache entry and reloads the dtd file if it has changed.

getCachedDTDEntries

public java.util.Collection getCachedDTDEntries()

printCache

public void printCache()

fixslashes

protected java.lang.String fixslashes(java.lang.String s)
make all slashes forward slashes cause windows sucks

debug

protected void debug(java.lang.String s)
simple debugging print routine