XBRLAPI

A Java API for XBRL


org.xbrlapi.cache
Class CacheImpl

java.lang.Object
  extended by org.xbrlapi.cache.CacheImpl
All Implemented Interfaces:
Serializable, Cache

public class CacheImpl
extends Object
implements Cache

Translates 1. original URIs into cache File objects or cache URI objects 2. cache URIs into original URI objects The translation from cache URIs to original URIs is a hack that enables relative URIs in cached files to be identified as such an resolved to obtain the original URI of the resource identified by the relative URI. This class also provides a method for testing if a URI is a cache URI.

Author:
Geoffrey Shuetrim (geoff@galexy.net)
See Also:
Serialized Form

Constructor Summary
CacheImpl(File cacheRoot)
          Constructs a URI translator for usage with a local cache location.
CacheImpl(File cacheRoot, HashMap<URI,URI> uriMap)
          Constructs a URI translator for usage with a local cache location.
 
Method Summary
 void copyToCache(URI originalURI, File cacheFile)
          Copy the original resource into the local cache if the resource exists and is able to be copied into the cache and does nothing otherwise.
 void copyToCache(URI originalURI, String xml)
          Copy the original resource into the local cache.
 boolean equals(Object obj)
           
 List<URI> getAllUris(URI uri)
          This method provides a useful means of getting a list of the URIs for all documents in a branch of the cache.
 File getCacheFile(URI uri)
          Gets the cache file for an original URI.
 File getCacheRoot()
           
 URI getCacheURI(URI uri)
          TODO Modify to use the java.net.URIEncoder and java.net.URIDecoder classes.
 URI getOriginalURI(File file)
           
 URI getOriginalURI(URI uri)
           
 int hashCode()
           
 boolean isCacheURI(URI uri)
          Tests if a URI is a URI of a resource in the local cache.
 void purge(URI uri)
          Delete a resource from the cache.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheImpl

public CacheImpl(File cacheRoot)
          throws XBRLException
Constructs a URI translator for usage with a local cache location.

Parameters:
cacheRoot - The root directory for the cache.
Throws:
XBRLException - if the cacheRoot is null or does not exist or cannot be written to or read from.

CacheImpl

public CacheImpl(File cacheRoot,
                 HashMap<URI,URI> uriMap)
          throws XBRLException
Constructs a URI translator for usage with a local cache location.

Parameters:
cacheRoot -
uriMap - The hash map from original URIs to local URIs.
Throws:
XBRLException - if the cacheRoot is null or does not exist
Method Detail

isCacheURI

public boolean isCacheURI(URI uri)
                   throws XBRLException
Description copied from interface: Cache
Tests if a URI is a URI of a resource in the local cache.

Specified by:
isCacheURI in interface Cache
Parameters:
uri - The URI to be tested to see if it identifies a resource in the local cache.
Returns:
true if and only if the URI is for a resource in the local cache.
Throws:
XBRLException - if the URI status as a cache URI cannot be determined.
See Also:
Cache.isCacheURI(java.net.URI)

getCacheURI

public URI getCacheURI(URI uri)
                throws XBRLException
Description copied from interface: Cache
TODO Modify to use the java.net.URIEncoder and java.net.URIDecoder classes. Adds the resource at the original URI to the cache if it is not already cached.

Specified by:
getCacheURI in interface Cache
Parameters:
uri - The URI to be translated into a cache URI (if necessary).
Returns:
the cache URI corresponding to the provided URI.
Throws:
XBRLException - if the resource cannot be cached.
See Also:
Cache.getCacheURI(java.net.URI)

getOriginalURI

public URI getOriginalURI(URI uri)
                   throws XBRLException
Specified by:
getOriginalURI in interface Cache
Parameters:
uri - The URI to be translated into an original URI (if necessary).
Returns:
the original (non-cache) URI corresponding to the provided URI.
Throws:
XBRLException - if a caching operation fails or if a cache file cannot be translated into a URI.
See Also:
Cache.getOriginalURI(java.net.URI)

getOriginalURI

public URI getOriginalURI(File file)
                   throws XBRLException
Specified by:
getOriginalURI in interface Cache
Parameters:
file - The file to be translated into an original URI (if necessary).
Returns:
the original (non-cache) URI corresponding to the provided file. If the file is not a cache file then the returned URI is just a URI version of the file. Otherwise, the original URI is derived from the file.
Throws:
XBRLException - if a caching operation fails or if a cache file cannot be translated into a URI.
See Also:
Cache.getOriginalURI(File)

getCacheFile

public File getCacheFile(URI uri)
                  throws XBRLException
Description copied from interface: Cache
Gets the cache file for an original URI.

Specified by:
getCacheFile in interface Cache
Parameters:
uri - The URI to obtain the cache file for,
Returns:
The File for the provided URI.
Throws:
XBRLException - if the URI cannot be translated into a location in the local cache.
See Also:
Cache.getCacheFile(java.net.URI)

copyToCache

public void copyToCache(URI originalURI,
                        File cacheFile)
Description copied from interface: Cache
Copy the original resource into the local cache if the resource exists and is able to be copied into the cache and does nothing otherwise. Thus, caching fails silently.

Specified by:
copyToCache in interface Cache
Parameters:
originalURI - the URI of the resource to be copied into the cache.
cacheFile - The file to be used to store the cache version of the resource.
See Also:
Cache.copyToCache(java.net.URI, java.io.File)

copyToCache

public void copyToCache(URI originalURI,
                        String xml)
                 throws XBRLException
Description copied from interface: Cache
Copy the original resource into the local cache.

Specified by:
copyToCache in interface Cache
Parameters:
originalURI - the URI of the resource to be copied into the cache.
xml - The XML to store in the cache at the given URI.
Throws:
XBRLException - if the resource cannot be copied into the local cache.
See Also:
Cache.copyToCache(java.net.URI, java.lang.String)

purge

public void purge(URI uri)
           throws XBRLException
Description copied from interface: Cache
Delete a resource from the cache.

Specified by:
purge in interface Cache
Parameters:
uri - The original or the cache URI.
Throws:
XBRLException - if the cache file cannot be determined.
See Also:
Cache.purge(java.net.URI)

getCacheRoot

public File getCacheRoot()
Returns:
the root directory containing the cache.

getAllUris

public List<URI> getAllUris(URI uri)
                     throws XBRLException
Description copied from interface: Cache
This method provides a useful means of getting a list of the URIs for all documents in a branch of the cache. This can be very helpful when trying to reload the cached documents into a data store.

Specified by:
getAllUris in interface Cache
Parameters:
uri - A URI that corresponds to a directory or file in the cache.
Returns:
the list of original URIs for the files in the specified directory (or the directory containing the specified file) and the original URIs for all of the files in descendant directories of that directory.
Throws:
XBRLException
See Also:
Cache.getAllUris(URI)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

Get Java XBRL API implementation at SourceForge.net.