net.ontopia.infoset.utils
Class DiskPreloader

java.lang.Object
  extended by net.ontopia.infoset.utils.DiskPreloader
All Implemented Interfaces:
LocatorReaderFactoryIF, PreloaderIF

public class DiskPreloader
extends java.lang.Object
implements PreloaderIF, LocatorReaderFactoryIF

INTERNAL: A preloader that stores its preloaded documents on the file system.

The preloader also implements LocatorReaderFactoryIF because it is capable of creating readers from the locators returned by its preload method.

This class is able to cache the result of preloaded locators. Caching is on by default. The caching is useful to avoid duplicate preloads of identical locators.

A URLLocatorReaderFactory is used by default if not specified in the constructor.


Field Summary
protected  boolean force_download
           
protected  LocatorReaderFactoryIF lrf
           
protected  java.lang.String preloader_path
           
 
Constructor Summary
DiskPreloader(java.lang.String preloader_path)
           
DiskPreloader(java.lang.String preloader_path, LocatorReaderFactoryIF lrf)
           
 
Method Summary
protected  LocatorIF createLocator(java.lang.String fileid)
           
 java.io.Reader createReader(LocatorIF locator)
          INTERNAL: Returns a reader that can read the contents of the resource referenced by the locator.
protected  java.lang.String getFileId(LocatorIF locator)
           
protected  java.lang.String getFilename(java.lang.String fileid)
           
 boolean getForceDownload()
          PUBLIC: Returns true if the preloader shouldn't use its internal cache, but rather force a new preload.
 java.lang.String getPreloaderPath()
          PUBLIC: Returns the directory in which the preloaded resources will be stored.
protected  java.io.Reader getReader(java.net.URL url)
           
 boolean needsPreloading(LocatorIF locator)
          INTERNAL: Can be used to figure out if it is necessary to preload the resource referenced by the locator.
 LocatorIF preload(LocatorIF locator)
          PUBLIC: Preloads the resource pointed to by the given locator.
 void setForceDownload(boolean force_download)
          PUBLIC: Sets the force download flag.
 void setPreloaderPath(java.lang.String preloader_path)
          PUBLIC: Sets the directory in which the preloaded resources will be stored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lrf

protected LocatorReaderFactoryIF lrf

preloader_path

protected java.lang.String preloader_path

force_download

protected boolean force_download
Constructor Detail

DiskPreloader

public DiskPreloader(java.lang.String preloader_path)

DiskPreloader

public DiskPreloader(java.lang.String preloader_path,
                     LocatorReaderFactoryIF lrf)
Method Detail

getForceDownload

public boolean getForceDownload()
PUBLIC: Returns true if the preloader shouldn't use its internal cache, but rather force a new preload. The default is true.


setForceDownload

public void setForceDownload(boolean force_download)
PUBLIC: Sets the force download flag.


getPreloaderPath

public java.lang.String getPreloaderPath()
PUBLIC: Returns the directory in which the preloaded resources will be stored.


setPreloaderPath

public void setPreloaderPath(java.lang.String preloader_path)
PUBLIC: Sets the directory in which the preloaded resources will be stored.


getFileId

protected java.lang.String getFileId(LocatorIF locator)

getFilename

protected java.lang.String getFilename(java.lang.String fileid)

getReader

protected java.io.Reader getReader(java.net.URL url)
                            throws java.io.IOException
Throws:
java.io.IOException

createLocator

protected LocatorIF createLocator(java.lang.String fileid)

preload

public LocatorIF preload(LocatorIF locator)
                  throws java.io.IOException
PUBLIC: Preloads the resource pointed to by the given locator.

Specified by:
preload in interface PreloaderIF
Returns:
A URL locator
Throws:
java.io.IOException

needsPreloading

public boolean needsPreloading(LocatorIF locator)
Description copied from interface: PreloaderIF
INTERNAL: Can be used to figure out if it is necessary to preload the resource referenced by the locator.

Specified by:
needsPreloading in interface PreloaderIF

createReader

public java.io.Reader createReader(LocatorIF locator)
                            throws java.io.IOException
Description copied from interface: LocatorReaderFactoryIF
INTERNAL: Returns a reader that can read the contents of the resource referenced by the locator.

Specified by:
createReader in interface LocatorReaderFactoryIF
Returns:
A reader for the locator. An IOException is thrown if a reader cannot be created.
Throws:
java.io.IOException


Copyright © 2000-2012 Ontopia.