Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.merlotxml.util.xml
Class DTDCache  view DTDCache download DTDCache.java

java.lang.Object
  extended byorg.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.4 2002/11/05 13:43:32 flament Exp $

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, e.g.
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, e.g.
protected static java.lang.String FILE_PROTOCOL_NAME
          url prefix to know we're working with a local file
 
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
protected  DTDCacheEntry findCacheEntryBySystemID(java.lang.String systemID)
           
 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.io.InputStream findDTDFromClassLoader(java.lang.String publicID, java.lang.String systemID)
           
protected  java.io.InputStream findDTDFromDTDPath(java.lang.String publicID, java.lang.String systemID)
           
protected  java.io.InputStream findDTDFromFile(java.lang.String systemID)
          see if the systemID exists as-is (is the absolute path embedded in the xml?)
protected  java.io.InputStream findDTDFromFile(java.lang.String systemID, java.lang.String fileLocation)
           
protected  java.io.InputStream findDTDFromPlugins(java.lang.String publicID, java.lang.String systemID)
           
protected  java.io.InputStream findDTDFromURL(java.lang.String publicID, java.lang.String systemID)
           
protected  java.lang.String fixslashes(java.lang.String s)
          Deprecated. use fixSlashes instead
protected  java.lang.String fixSlashes(java.lang.String s)
          make all slashes forward slashes cause windows sucks
protected  java.lang.String formatFileName(java.lang.String originalFileName)
           
 java.util.Collection getCachedDTDEntries()
           
protected  java.lang.String getDTDPath()
           
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.
protected  DTDCacheEntry setupCacheEntryFromClassLoader(java.lang.String publicID, java.lang.String systemID)
           
protected  DTDCacheEntry setupCacheEntryFromFile(java.lang.String publicID, java.lang.String systemID)
           
protected  DTDCacheEntry setupCacheEntryFromPlugins(java.lang.String publicID, java.lang.String systemID)
           
protected  DTDCacheEntry setupCacheEntryFromURL(java.lang.String publicID, java.lang.String systemID)
           
 
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, e.g. (publicId, DTDCacheEntry)


_systemIdCache

protected java.util.Map _systemIdCache
key is the system id, val is a DTDCacheEntry, e.g. (systemId, 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


FILE_PROTOCOL_NAME

protected static final java.lang.String FILE_PROTOCOL_NAME
url prefix to know we're working with a local file

See Also:
Constant Field Values
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


findCacheEntryBySystemID

protected DTDCacheEntry findCacheEntryBySystemID(java.lang.String systemID)

setupCacheEntryFromFile

protected DTDCacheEntry setupCacheEntryFromFile(java.lang.String publicID,
                                                java.lang.String systemID)

setupCacheEntryFromClassLoader

protected DTDCacheEntry setupCacheEntryFromClassLoader(java.lang.String publicID,
                                                       java.lang.String systemID)

setupCacheEntryFromPlugins

protected DTDCacheEntry setupCacheEntryFromPlugins(java.lang.String publicID,
                                                   java.lang.String systemID)

setupCacheEntryFromURL

protected DTDCacheEntry setupCacheEntryFromURL(java.lang.String publicID,
                                               java.lang.String systemID)

findDTDFromFile

protected java.io.InputStream findDTDFromFile(java.lang.String systemID)
see if the systemID exists as-is (is the absolute path embedded in the xml?)


findDTDFromFile

protected java.io.InputStream findDTDFromFile(java.lang.String systemID,
                                              java.lang.String fileLocation)

findDTDFromURL

protected java.io.InputStream findDTDFromURL(java.lang.String publicID,
                                             java.lang.String systemID)

findDTDFromClassLoader

protected java.io.InputStream findDTDFromClassLoader(java.lang.String publicID,
                                                     java.lang.String systemID)

findDTDFromPlugins

protected java.io.InputStream findDTDFromPlugins(java.lang.String publicID,
                                                 java.lang.String systemID)

findDTDFromDTDPath

protected java.io.InputStream findDTDFromDTDPath(java.lang.String publicID,
                                                 java.lang.String systemID)

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)
Deprecated. use fixSlashes instead


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


formatFileName

protected java.lang.String formatFileName(java.lang.String originalFileName)

getDTDPath

protected java.lang.String getDTDPath()