Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.database
Class DbAttachmentManager

java.lang.Object
  extended by com.jivesoftware.forum.database.DbAttachmentManager
All Implemented Interfaces:
JiveManager, AttachmentManager

public class DbAttachmentManager
extends java.lang.Object
implements AttachmentManager, JiveManager

Database implementation of the AttachmentManager interface. Support for storing attachments can be enabled by setting the attachments.databaseModeEnabled property to true. When the database attachment mode is enabled, attachments will be cached on the file system in the attachment directory of jiveHome. Cached attachments on the file system will be deleted after 30 days. Therefore, care should be taken if switching between file system and database mode since file system attachments will be assumed to be out-dated cached items and then deleted (possibly before you have a chance to copy attachments into the database).


Nested Class Summary
static class DbAttachmentManager.AttachmentSettingsTask
           
 
Method Summary
 void addAllowedType(java.lang.String contentType)
          Adds a content type to the list of explicitly allowed types.
 void addDisallowedType(java.lang.String contentType)
          Adds a content type to the list of explicitly disallowed types.
protected  void addToAttachDirSize(long size)
          Adds to the size of the attachment directory.
 java.util.Iterator allowedTypes()
          Returns an Iterator for the list of explicitly allowed types.
 void destroy()
          Notifies the manager to release any resources that may be holding on too.
 java.util.Iterator disallowedTypes()
          Returns an Iterator for the list of explicitly disallowed types.
 boolean getAllowAllByDefault()
          Returns true if in the "allow all content types by default" mode.
static java.io.File getAttachmentDir()
          Returns the directory that attachments are stored in.
 long getAttachmentDirectorySize()
          Returns the size (in bytes) of the attachment directory on the file system.
 int getImagePreviewMaxSize()
          Returns the max dimension of generated thumbnails (ie, the max value for the width or height).
static DbAttachmentManager getInstance()
           
 int getMaxAttachmentSize()
          Returns the maximum size of an individual attachment in kilobytes.
 int getMaxAttachmentsPerMessage()
          Returns the maximum number of attachments per message.
 long getMaxFilesystemCacheSize()
          Returns the maximum amount of storage (in bytes) that will be used by the file system cache when database attachment mode is enabled.
static java.lang.String getThumbnailImage(java.lang.String contentType)
          Returns a Map for the list of content types to image names.
 void initialize()
          Initialize the manager.
 boolean isDatabaseModeEnabled()
          Returns true if the binary attachment data is stored in the database.
 boolean isImagePreviewEnabled()
          Returns true if image preview support is enabled.
 boolean isImagePreviewRatioEnabled()
          Returns true if the aspect ratio of thumbnails should be preserved.
 boolean isValidType(java.lang.String contentType)
          Returns true if the content type is valid based on the current settings of the allowAllByDefault flag and the allowed and disallowed types list.
 void removeAllowedType(java.lang.String contentType)
          Removes a content type fromt he list of explicitly allowed types.
 void removeDisallowedType(java.lang.String contentType)
          Removes a content type from the list of explicitly disallowed types.
 void setAllowAllByDefault(boolean allowAllByDefault)
          Sets the default allowed content types mode.
 void setDatabaseModeEnabled(boolean enabled)
          Enables or disables storage of binary attachment data in the database.
 void setDatabaseModeEnabled(boolean enabled, boolean synchronous)
          Enables or disables storage of binary attachment data in the database.
 void setImagePreviewEnabled(boolean imagePreviewEnabled)
          Toggles whether image preview support is enabled.
 void setImagePreviewMaxSize(int imagePreviewMaxSize)
          Sets the max dimension of generated thumbnails (ie, the max value for the width or height).
 void setImagePreviewRatioEnabled(boolean imagePreviewRatioEnabled)
          Toggles whether the aspect ratio of thumbnails should be preserved.
 void setMaxAttachmentSize(int maxAttachmentSize)
          Sets the maximum size of an individual attachment in kilobytes.
 void setMaxAttachmentsPerMessage(int maxAttachmentsPerMessage)
          Sets the maximum number of attachments per message.
 void setMaxFilesystemCacheSize(long maxSize)
          Sets the maximum amount of storage (in bytes) that will be used by the file system cache when database attachment mode is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DbAttachmentManager getInstance()

initialize

public void initialize()
Description copied from interface: JiveManager
Initialize the manager. It is within this method that it is ok to create, access and/or otherwise use external classes (including caches). Until this method is called implementation should not access any external classes that could possibly either access one of the main Factory classes or any caches since doing so can cause deadlocks and possible clustering issues during startup.

This method is used internally by Jive during application startup and should not be called during normal usage of the class.

Specified by:
initialize in interface JiveManager

destroy

public void destroy()
Description copied from interface: JiveManager
Notifies the manager to release any resources that may be holding on too. This could also be used to clear out the managers caches, etc.

This method is used internally by Jive during application startup and should not be called during normal usage of the class.

Specified by:
destroy in interface JiveManager

isDatabaseModeEnabled

public boolean isDatabaseModeEnabled()
Description copied from interface: AttachmentManager
Returns true if the binary attachment data is stored in the database. If false, attachments are stored on the file system. Not all databases may support storing attachment data in the database, so the mode is disabled by default. Those using clustering, or a database that does work with database attachments may wish to turn this mode on.

When database attachment mode is enabled, attachment data will be cached on the file system in the attachment directory in order to relieve load on the database.

Specified by:
isDatabaseModeEnabled in interface AttachmentManager
Returns:
true if database attachment mode is enabled.

setDatabaseModeEnabled

public void setDatabaseModeEnabled(boolean enabled)
Description copied from interface: AttachmentManager
Enables or disables storage of binary attachment data in the database. If false, attachments are stored on the file system. Not all databases may support storing attachment data in the database, so the mode is disabled by default. Those using clustering, or a database that does work with database attachments may wish to turn this mode on.

When database attachment mode is enabled, attachment data will be cached on the file system in the attachment directory in order to relieve load on the database.

Specified by:
setDatabaseModeEnabled in interface AttachmentManager
Parameters:
enabled - true if attachment data should be stored in the database.

setDatabaseModeEnabled

public void setDatabaseModeEnabled(boolean enabled,
                                   boolean synchronous)
Enables or disables storage of binary attachment data in the database. If false, attachments are stored on the file system. Not all databases may support storing attachment data in the database, so the mode is disabled by default. Those using clustering, or a database that does work with database attachments may wish to turn this mode on.

When database attachment mode is enabled, attachment data will be cached on the file system in the attachment directory in order to relieve load on the database.

This version of the method can be invoked synchronously, which means that the mode will be changed before this method returns.

Parameters:
enabled - true if attachment data should be stored in the database.
synchronous - true to execute this method synchronously.

getAttachmentDirectorySize

public long getAttachmentDirectorySize()
                                throws UnauthorizedException
Description copied from interface: AttachmentManager
Returns the size (in bytes) of the attachment directory on the file system. When in file system storage mode, the attachment directory is where all binary data is stored. In database attachment mode, the attachment directory is used as a cache for attachment data in order to relieve load on the database.

The size of the attachment directory is computed asynchronously at system startup. Therefore, when the the size of the directory is not known, this method will return -1.

Specified by:
getAttachmentDirectorySize in interface AttachmentManager
Returns:
the size of the attachment directory in bytes, or -1 if the size of the directory is not known..
Throws:
UnauthorizedException - if not a system administrator.

getMaxFilesystemCacheSize

public long getMaxFilesystemCacheSize()
                               throws UnauthorizedException
Description copied from interface: AttachmentManager
Returns the maximum amount of storage (in bytes) that will be used by the file system cache when database attachment mode is enabled. The default maximum size is 512 MB. When the cache size is exceeded, files will be deleted until at least 10% of the cache is free.

Specified by:
getMaxFilesystemCacheSize in interface AttachmentManager
Returns:
the max size of the file system cache for attachment data (in bytes).
Throws:
UnauthorizedException - if not a system administrator.

setMaxFilesystemCacheSize

public void setMaxFilesystemCacheSize(long maxSize)
                               throws UnauthorizedException
Description copied from interface: AttachmentManager
Sets the maximum amount of storage (in bytes) that will be used by the file system cache when database attachment mode is enabled. The default maximum size is 512 MB. When the cache size is exceeded, files will be deleted until at least 10% of the cache is free.

Specified by:
setMaxFilesystemCacheSize in interface AttachmentManager
Parameters:
maxSize - the max size of the file system cache for attachment data (in bytes).
Throws:
UnauthorizedException - if not a system administrator.

getMaxAttachmentSize

public int getMaxAttachmentSize()
Description copied from interface: AttachmentManager
Returns the maximum size of an individual attachment in kilobytes. Trying to create an attachment larger than the max size will fail with an exception. The default maximum attachment size is 1 megabyte, or 1,024 K.

Specified by:
getMaxAttachmentSize in interface AttachmentManager
Returns:
the max size in kilobytes of any single attachment.

setMaxAttachmentSize

public void setMaxAttachmentSize(int maxAttachmentSize)
Description copied from interface: AttachmentManager
Sets the maximum size of an individual attachment in kilobytes. Trying to create an attachment larger than the max size will fail with an exception. The default maximum attachment size is 1 megabyte, or 1024 K.

Specified by:
setMaxAttachmentSize in interface AttachmentManager
Parameters:
maxAttachmentSize - the max size in kilobytes of any single attachment.

getMaxAttachmentsPerMessage

public int getMaxAttachmentsPerMessage()
Description copied from interface: AttachmentManager
Returns the maximum number of attachments per message. The default is 5 attachments.

Specified by:
getMaxAttachmentsPerMessage in interface AttachmentManager
Returns:
the max number of attachments allowed per message.

setMaxAttachmentsPerMessage

public void setMaxAttachmentsPerMessage(int maxAttachmentsPerMessage)
Description copied from interface: AttachmentManager
Sets the maximum number of attachments per message. The default is 5 attachments.

Specified by:
setMaxAttachmentsPerMessage in interface AttachmentManager
Parameters:
maxAttachmentsPerMessage - the max number of attachments allowed per message.

isValidType

public boolean isValidType(java.lang.String contentType)
Description copied from interface: AttachmentManager
Returns true if the content type is valid based on the current settings of the allowAllByDefault flag and the allowed and disallowed types list.

Specified by:
isValidType in interface AttachmentManager
Parameters:
contentType - the content type to test.
Returns:
true if the content type is valid.

addAllowedType

public void addAllowedType(java.lang.String contentType)
Description copied from interface: AttachmentManager
Adds a content type to the list of explicitly allowed types.

Specified by:
addAllowedType in interface AttachmentManager
Parameters:
contentType - a content type to add to the explicitly allowed types list.

removeAllowedType

public void removeAllowedType(java.lang.String contentType)
Description copied from interface: AttachmentManager
Removes a content type fromt he list of explicitly allowed types. If the given content type does not exist in the list, this method does nothing.

Specified by:
removeAllowedType in interface AttachmentManager
Parameters:
contentType - a content type to remove from the explicitly allowed types list.

allowedTypes

public java.util.Iterator allowedTypes()
Description copied from interface: AttachmentManager
Returns an Iterator for the list of explicitly allowed types.

Specified by:
allowedTypes in interface AttachmentManager
Returns:
an iterator for the list of all explicitly allowed types.

addDisallowedType

public void addDisallowedType(java.lang.String contentType)
Description copied from interface: AttachmentManager
Adds a content type to the list of explicitly disallowed types.

Specified by:
addDisallowedType in interface AttachmentManager
Parameters:
contentType - a content type to add to the explicitly disallowed types list.

removeDisallowedType

public void removeDisallowedType(java.lang.String contentType)
Description copied from interface: AttachmentManager
Removes a content type from the list of explicitly disallowed types.

Specified by:
removeDisallowedType in interface AttachmentManager
Parameters:
contentType - a content type to remove from the explicitly disallowed types list.

disallowedTypes

public java.util.Iterator disallowedTypes()
Description copied from interface: AttachmentManager
Returns an Iterator for the list of explicitly disallowed types.

Specified by:
disallowedTypes in interface AttachmentManager
Returns:
an iterator for the list of all explicitly disallowed types.

getAllowAllByDefault

public boolean getAllowAllByDefault()
Description copied from interface: AttachmentManager
Returns true if in the "allow all content types by default" mode. The alternative is that all content types are disallowed unless they're on the "allowed" list.

Specified by:
getAllowAllByDefault in interface AttachmentManager
Returns:
true if all content types are allowed by default.

setAllowAllByDefault

public void setAllowAllByDefault(boolean allowAllByDefault)
Description copied from interface: AttachmentManager
Sets the default allowed content types mode. The value true means that all content types will be allowed unless they're on the "disallowed list". If false, no content types will be allowed unless on the "allowed list".

Specified by:
setAllowAllByDefault in interface AttachmentManager
Parameters:
allowAllByDefault - true if all content types should be allowed by default.

isImagePreviewEnabled

public boolean isImagePreviewEnabled()
Description copied from interface: AttachmentManager
Returns true if image preview support is enabled. When enabled, the JiveServlet will generate thumbnails for image attachments. False by default.

Specified by:
isImagePreviewEnabled in interface AttachmentManager
Returns:
true if thumbnail support is enabled.

setImagePreviewEnabled

public void setImagePreviewEnabled(boolean imagePreviewEnabled)
Description copied from interface: AttachmentManager
Toggles whether image preview support is enabled. When enabled, the JiveServlet will generate thumbnails for image attachments. False by default.

Specified by:
setImagePreviewEnabled in interface AttachmentManager
Parameters:
imagePreviewEnabled - true if thumbnail support should be enabled.

getImagePreviewMaxSize

public int getImagePreviewMaxSize()
Description copied from interface: AttachmentManager
Returns the max dimension of generated thumbnails (ie, the max value for the width or height). The default value is 25.

Specified by:
getImagePreviewMaxSize in interface AttachmentManager
Returns:
the max dimension of a thumbnail.

setImagePreviewMaxSize

public void setImagePreviewMaxSize(int imagePreviewMaxSize)
Description copied from interface: AttachmentManager
Sets the max dimension of generated thumbnails (ie, the max value for the width or height). The default value is 25.

Specified by:
setImagePreviewMaxSize in interface AttachmentManager
Parameters:
imagePreviewMaxSize - the max dimension of a thumbnail.

isImagePreviewRatioEnabled

public boolean isImagePreviewRatioEnabled()
Description copied from interface: AttachmentManager
Returns true if the aspect ratio of thumbnails should be preserved. When enabled, the aspect ratio of the original image will be preserved when generating the thumbnail. When false, the thumbnail will always be a square (which may distort the image). The default is true..

Specified by:
isImagePreviewRatioEnabled in interface AttachmentManager
Returns:
true if the aspect ration should be preserved.

setImagePreviewRatioEnabled

public void setImagePreviewRatioEnabled(boolean imagePreviewRatioEnabled)
Description copied from interface: AttachmentManager
Toggles whether the aspect ratio of thumbnails should be preserved. When enabled, the aspect ratio of the original image will be preserved when generating the thumbnail. When false, the thumbnail will always be a square (which may distort the image). The default is true..

Specified by:
setImagePreviewRatioEnabled in interface AttachmentManager
Parameters:
imagePreviewRatioEnabled - true if the aspect ration should be preserved.

getThumbnailImage

public static java.lang.String getThumbnailImage(java.lang.String contentType)
Returns a Map for the list of content types to image names. The JiveServlet class uses this method.


getAttachmentDir

public static java.io.File getAttachmentDir()
Returns the directory that attachments are stored in.


addToAttachDirSize

protected void addToAttachDirSize(long size)
Adds to the size of the attachment directory. Pass in a negative value to subtract from the total directory size.

Parameters:
size - size of the attachment.

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.