org.mycore.datamodel.ifs
Class MCRContentStore

java.lang.Object
  extended by org.mycore.datamodel.ifs.MCRContentStore
Direct Known Subclasses:
MCRCStoreVFS, MCRCStoreVideoCharger, MCRHIBCStore

public abstract class MCRContentStore
extends Object

Stores the content of MCRFiles in a persistent datastore. This can be a filesystem, IBM Content Manager, video streaming servers like IBM VideoCharger or Real Server, depending on the class that implements this interface. The MCRContentStore provides methods to store, delete and retrieve content. It uses a storage ID and the store ID to identify the place where the content of a file is stored.

Version:
$Revision: 14354 $ $Date: 2008-11-07 15:23:02 +0100 (Fr, 07 Nov 2008) $
Author:
Frank Lützenkirchen

Field Summary
protected static DateFormat formatter
          DateFormat used to construct new unique IDs based on timecode
protected static String lastTimestamp
          The last timestamp that was constructed
protected  String prefix
          The prefix of all properties in mycore.properties for this store
protected  int slotDirDepth
          The depth of slot subdirectories to build
protected  String storeID
          The unique store ID for this MCRContentStore implementation
 
Constructor Summary
MCRContentStore()
          Default constructor *
 
Method Summary
protected static String buildNextID(MCRFileReader file)
          Constructs a new unique ID for storing content
protected static String buildNextTimestamp()
          Helper method for constructing a unique storage ID from a timestamp.
protected  String[] buildSlotPath()
          Some content store implementations store the file's content in a hierarchical directory structure of the server's filesystem.
 void deleteContent(String storageID)
          Deletes the content of an MCRFile object that is stored under the given Storage ID in this store instance.
protected abstract  void doDeleteContent(String storageID)
          Deletes the content of an MCRFile object that is stored under the given Storage ID in this store instance.
protected abstract  InputStream doRetrieveContent(MCRFileReader file)
          Retrieves the content of an MCRFile.
protected abstract  void doRetrieveContent(MCRFileReader file, OutputStream target)
          Deprecated. use doRetrieveContent(MCRFileReader file) instead
protected abstract  String doStoreContent(MCRFileReader file, MCRContentInputStream source)
          Stores the content of an MCRFile by reading from an MCRContentInputStream.
 String getID()
          Returns the unique store ID that was set for this store instance
 void init(String storeID)
          Initializes the store and sets its unique store ID.
 InputStream retrieveContent(MCRFileReader file)
          Retrieves the content of an MCRFile as an InputStream.
 void retrieveContent(MCRFileReader file, OutputStream target)
          Deprecated. use doRetrieveContent(MCRFileReader file) instead
 String storeContent(MCRFileReader file, MCRContentInputStream source)
          Stores the content of an MCRFile by reading from an MCRContentInputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storeID

protected String storeID
The unique store ID for this MCRContentStore implementation


prefix

protected String prefix
The prefix of all properties in mycore.properties for this store


slotDirDepth

protected int slotDirDepth
The depth of slot subdirectories to build


formatter

protected static DateFormat formatter
DateFormat used to construct new unique IDs based on timecode


lastTimestamp

protected static String lastTimestamp
The last timestamp that was constructed

Constructor Detail

MCRContentStore

public MCRContentStore()
Default constructor *

Method Detail

init

public void init(String storeID)
Initializes the store and sets its unique store ID. MCRFiles must remember this ID to indentify the store that holds their file content. The store ID is set by MCRContentStoreFactory when a new store instance is built. Subclasses should override this method.

Parameters:
storeID - the non-null unique store ID for this store instance

getID

public String getID()
Returns the unique store ID that was set for this store instance

Returns:
the unique store ID that was set for this store instance

storeContent

public String storeContent(MCRFileReader file,
                           MCRContentInputStream source)
                    throws MCRPersistenceException
Stores the content of an MCRFile by reading from an MCRContentInputStream. Returns a StorageID to indentify the place where the content was stored.

Parameters:
file - the MCRFile thats content is to be stored
source - the ContentInputStream where the file content is read from
Returns:
an ID that indentifies the place where the content was stored
Throws:
MCRPersistenceException

doStoreContent

protected abstract String doStoreContent(MCRFileReader file,
                                         MCRContentInputStream source)
                                  throws Exception
Stores the content of an MCRFile by reading from an MCRContentInputStream. Returns a StorageID to indentify the place where the content was stored.

Parameters:
file - the MCRFile thats content is to be stored
source - the ContentInputStream where the file content is read from
Returns:
an ID that indentifies the place where the content was stored
Throws:
Exception

deleteContent

public void deleteContent(String storageID)
                   throws MCRException
Deletes the content of an MCRFile object that is stored under the given Storage ID in this store instance.

Parameters:
storageID - the storage ID of the MCRFile object
Throws:
MCRException

doDeleteContent

protected abstract void doDeleteContent(String storageID)
                                 throws Exception
Deletes the content of an MCRFile object that is stored under the given Storage ID in this store instance.

Parameters:
storageID - the storage ID of the MCRFile object
Throws:
Exception

retrieveContent

public void retrieveContent(MCRFileReader file,
                            OutputStream target)
                     throws MCRException
Deprecated. use doRetrieveContent(MCRFileReader file) instead

Retrieves the content of an MCRFile to an OutputStream. Uses the StorageID to indentify the place where the file content was stored in this store instance.

Parameters:
file - the MCRFile thats content should be retrieved
target - the OutputStream to write the file content to
Throws:
MCRException

doRetrieveContent

protected abstract void doRetrieveContent(MCRFileReader file,
                                          OutputStream target)
                                   throws Exception
Deprecated. use doRetrieveContent(MCRFileReader file) instead

Retrieves the content of an MCRFile to an OutputStream. Uses the StorageID to indentify the place where the file content was stored in this store instance.

Parameters:
file - the MCRFile thats content should be retrieved
target - the OutputStream to write the file content to
Throws:
Exception

doRetrieveContent

protected abstract InputStream doRetrieveContent(MCRFileReader file)
                                          throws Exception
Retrieves the content of an MCRFile. Uses the StorageID to indentify the place where the file content was stored in this store instance.

Parameters:
file - the MCRFile thats content should be retrieved
Throws:
Exception
Since:
1.3

retrieveContent

public InputStream retrieveContent(MCRFileReader file)
                            throws MCRException
Retrieves the content of an MCRFile as an InputStream.

Parameters:
file - the MCRFile thats content should be retrieved
Throws:
MCRException

buildNextID

protected static String buildNextID(MCRFileReader file)
Constructs a new unique ID for storing content


buildNextTimestamp

protected static String buildNextTimestamp()
Helper method for constructing a unique storage ID from a timestamp.


buildSlotPath

protected String[] buildSlotPath()
Some content store implementations store the file's content in a hierarchical directory structure of the server's filesystem. Such stores use a directory that contains 100 subdirectories with each 100 subsubdirectories, so that the internal directory operations will scale well for large file collections. The depth of this subdirectory structure can be set by the property SlotDirDepth, default is 2. This helper method randomly chooses the "slot directory" to be used for the next storage.

Returns:
directory names between "00" and "99" that are the "slot" where to store the file's content in the filesystem.