ModeShape Distribution 3.0.0.Beta4

org.modeshape.jcr.value.binary
Class AbstractBinaryStore

java.lang.Object
  extended by org.modeshape.jcr.value.binary.AbstractBinaryStore
All Implemented Interfaces:
BinaryStore
Direct Known Subclasses:
DatabaseBinaryStore, FileSystemBinaryStore, InfinispanBinaryStore, MongodbBinaryStore

@ThreadSafe
public abstract class AbstractBinaryStore
extends Object
implements BinaryStore

An abstract class for a BinaryStore, with common functionality needed by implementation classes.


Field Summary
protected  Logger logger
           
protected static int MEDIUM_BUFFER_SIZE
           
 
Constructor Summary
AbstractBinaryStore()
           
 
Method Summary
static int bestBufferSize(long fileSize)
           
protected  MimeTypeDetector detector()
          Get the MIME type detector that can be used to find the MIME type for binary content
protected  TextExtractors extractors()
          Get the text extractor that can be used to extract text by this store.
abstract  String getExtractedText(BinaryValue source)
          Returns the extracted text of a binary value, or null if such text hasn't been stored previously (but the binary value can be found in the store)
 String getMimeType(BinaryValue binary, String name)
          Get the MIME type for this binary value, never null.
 long getMinimumBinarySizeInBytes()
          Get the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
protected abstract  String getStoredMimeType(BinaryValue binaryValue)
          Returns the stored mime-type of a binary value.
 String getText(BinaryValue binary)
          Get the text that can be extracted from this binary content.
 void setMimeTypeDetector(MimeTypeDetector mimeTypeDetector)
          Set the MIME type detector that can be used for determining the MIME type for binary content.
 void setMinimumBinarySizeInBytes(long minSizeInBytes)
          Set the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
 void setTextExtractors(TextExtractors textExtractors)
          Set the text extractor that can be used for extracting text from binary content.
 void shutdown()
           
 void start()
          Initialize the store and get ready for use.
abstract  void storeExtractedText(BinaryValue source, String extractedText)
          Stores the extracted text of a binary value into this store.
protected abstract  void storeMimeType(BinaryValue binaryValue, String mimeType)
          Stores the given mime-type for a binary value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.modeshape.jcr.value.binary.BinaryStore
getAllBinaryKeys, getInputStream, markAsUnused, removeValuesUnusedLongerThan, storeValue
 

Field Detail

MEDIUM_BUFFER_SIZE

protected static final int MEDIUM_BUFFER_SIZE
See Also:
Constant Field Values

logger

protected Logger logger
Constructor Detail

AbstractBinaryStore

public AbstractBinaryStore()
Method Detail

bestBufferSize

public static int bestBufferSize(long fileSize)

getMinimumBinarySizeInBytes

public long getMinimumBinarySizeInBytes()
Description copied from interface: BinaryStore
Get the minimum number of bytes that a binary value must contain before it can be stored in the binary store.

Specified by:
getMinimumBinarySizeInBytes in interface BinaryStore
Returns:
the minimum number of bytes for a stored binary value; never negative

setMinimumBinarySizeInBytes

public void setMinimumBinarySizeInBytes(long minSizeInBytes)
Description copied from interface: BinaryStore
Set the minimum number of bytes that a binary value must contain before it can be stored in the binary store.

Specified by:
setMinimumBinarySizeInBytes in interface BinaryStore
Parameters:
minSizeInBytes - the minimum number of bytes for a stored binary value; may not be negative

setTextExtractors

public void setTextExtractors(TextExtractors textExtractors)
Description copied from interface: BinaryStore
Set the text extractor that can be used for extracting text from binary content.

Specified by:
setTextExtractors in interface BinaryStore
Parameters:
textExtractors - a non-null TextExtractors instance

setMimeTypeDetector

public void setMimeTypeDetector(MimeTypeDetector mimeTypeDetector)
Description copied from interface: BinaryStore
Set the MIME type detector that can be used for determining the MIME type for binary content.

Specified by:
setMimeTypeDetector in interface BinaryStore
Parameters:
mimeTypeDetector - the detector

getText

public final String getText(BinaryValue binary)
                     throws BinaryStoreException
Description copied from interface: BinaryStore
Get the text that can be extracted from this binary content. If text extraction isn't enabled (either full text search is not enabled or there aren't any configured extractors), this returns null

If extraction is enabled, this method may block until a text extractor has finished extracting the text.

If there are any problems either with the binary value or during the extraction process, the exception will be logged and null is returned

In general, the implementation from AbstractBinaryStore should be enough and any custom BinaryStore implementations aren't expected to implement this.

Specified by:
getText in interface BinaryStore
Parameters:
binary - the binary content; may not be null
Returns:
the extracted text, or null if none could be extracted
Throws:
BinaryStoreException - if the binary content could not be accessed or if the given binary value cannot be found within the store.

getMimeType

public String getMimeType(BinaryValue binary,
                          String name)
                   throws IOException,
                          BinaryStoreException,
                          RepositoryException
Description copied from interface: BinaryStore
Get the MIME type for this binary value, never null.

If the store has never determined the mime-type of the given binary and the binary can be located in the store, it will attempt to determine it via the configured detectors and store it.

Specified by:
getMimeType in interface BinaryStore
Parameters:
binary - the binary content; may not be null
name - the name of the content, useful for determining the MIME type; may be null if not known
Returns:
the MIME type of the content, as determined by the installed detectors or null if none of the detectors can determine it.
Throws:
IOException - if there is a problem reading the binary content
BinaryStoreException - if the binary value cannot be found in the store
RepositoryException - if any other error occurs.

getStoredMimeType

protected abstract String getStoredMimeType(BinaryValue binaryValue)
                                     throws BinaryStoreException
Returns the stored mime-type of a binary value.

Parameters:
binaryValue - a non-null BinaryValue
Returns:
either a non-empty String if a stored mimetype exists, or null if such a value doesn't exist yet.
Throws:
BinaryStoreException - if there's a problem accessing the binary store or if the binary value cannot be found in the store

storeMimeType

protected abstract void storeMimeType(BinaryValue binaryValue,
                                      String mimeType)
                               throws BinaryStoreException
Stores the given mime-type for a binary value.

Parameters:
binaryValue - a non-null BinaryValue
mimeType - a non-empty String
Throws:
BinaryStoreException - if there's a problem accessing the binary store

storeExtractedText

public abstract void storeExtractedText(BinaryValue source,
                                        String extractedText)
                                 throws BinaryStoreException
Stores the extracted text of a binary value into this store.

Parameters:
source - a non-null BinaryValue instance from which the text was extracted
extractedText - a non-null and non-blank string representing the extracted text
Throws:
BinaryStoreException - if the operation fails or if the extracted text cannot be stored for the given binary value (regardless of the reason)

getExtractedText

public abstract String getExtractedText(BinaryValue source)
                                 throws BinaryStoreException
Returns the extracted text of a binary value, or null if such text hasn't been stored previously (but the binary value can be found in the store)

Parameters:
source - a non-null BinaryValue instance from which the text was extracted
Returns:
a String representing the extracted text, or null if such text hasn't been stored in this store previously.
Throws:
BinaryStoreException - if the binary value cannot be found in the store.

extractors

protected final TextExtractors extractors()
Get the text extractor that can be used to extract text by this store.

Returns:
the text extractor; never null

detector

protected final MimeTypeDetector detector()
Get the MIME type detector that can be used to find the MIME type for binary content

Returns:
the detector; never null

start

public void start()
Initialize the store and get ready for use.


shutdown

public void shutdown()

ModeShape Distribution 3.0.0.Beta4

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.