Package org.apache.wiki.providers
Class CachingAttachmentProvider
java.lang.Object
org.apache.wiki.providers.CachingAttachmentProvider
- All Implemented Interfaces:
AttachmentProvider,WikiProvider
public class CachingAttachmentProvider extends Object implements AttachmentProvider
Provides a caching attachment provider. This class rests on top of a real provider class and provides a cache to speed things up.
Only the Attachment objects are cached; the actual attachment contents are fetched always from the provider.
- Since:
- 2.1.64.
-
Field Summary
Fields Modifier and Type Field Description static StringATTCACHE_NAMEName of the attachment cache.static StringATTCOLLCACHE_NAMEName of the attachment cache.static StringDIR_EXTENSIONThe extension to append to directory names to denote an attachment directory.static intm_capacityDefault cache capacity for now.Fields inherited from interface org.apache.wiki.api.providers.AttachmentProvider
PROP_STORAGEDIRFields inherited from interface org.apache.wiki.api.providers.WikiProvider
LATEST_VERSION -
Constructor Summary
Constructors Constructor Description CachingAttachmentProvider() -
Method Summary
Modifier and Type Method Description voiddeleteAttachment(Attachment att)Removes an entire page from the repository.voiddeleteVersion(Attachment att)Removes a specific version from the repository.Collection<Attachment>findAttachments(QueryItem[] query)Finds attachments based on the query.InputStreamgetAttachmentData(Attachment att)Get attachment data.AttachmentgetAttachmentInfo(Page page, String name, int version)Returns info about an attachment.StringgetProviderInfo()Gets the provider class name, and cache statistics (misscount and,hitcount of the attachment cache).AttachmentProvidergetRealProvider()Returns the WikiAttachmentProvider that this caching provider delegates to.List<Attachment>getVersionHistory(Attachment att)Returns version history.voidinitialize(Engine engine, Properties properties)Initializes the page provider.List<Attachment>listAllChanged(Date timestamp)Lists changed attachments since given date.List<Attachment>listAttachments(Page page)Lists all attachments attached to a page.voidmoveAttachmentsForPage(String oldParent, String newParent)Move all the attachments for a given page so that they are attached to a new page.voidputAttachmentData(Attachment att, InputStream data)Put new attachment data.
-
Field Details
-
m_capacity
Default cache capacity for now.- See Also:
- Constant Field Values
-
ATTCACHE_NAME
Name of the attachment cache.- See Also:
- Constant Field Values
-
ATTCOLLCACHE_NAME
Name of the attachment cache.- See Also:
- Constant Field Values
-
DIR_EXTENSION
The extension to append to directory names to denote an attachment directory.- See Also:
- Constant Field Values
-
-
Constructor Details
-
CachingAttachmentProvider
public CachingAttachmentProvider()
-
-
Method Details
-
initialize
public void initialize(Engine engine, Properties properties) throws NoRequiredPropertyException, IOExceptionInitializes the page provider.- Specified by:
initializein interfaceWikiProvider- Parameters:
engine- Engine to own this providerproperties- A set of properties used to initialize this provider- Throws:
NoRequiredPropertyException- If the provider needs a property which is not found in the property setIOException- If there is an IO problem
-
putAttachmentData
public void putAttachmentData(Attachment att, InputStream data) throws ProviderException, IOExceptionPut new attachment data.- Specified by:
putAttachmentDatain interfaceAttachmentProvider- Parameters:
att- Attachment object to add new data todata- The stream from which the provider should read the data- Throws:
ProviderException- If there are other errors.IOException- If writing fails
-
getAttachmentData
Get attachment data.- Specified by:
getAttachmentDatain interfaceAttachmentProvider- Parameters:
att- The attachment- Returns:
- An InputStream which you contains the raw data of the object. It's your responsibility to close it.
- Throws:
ProviderException- If the attachment cannot be foundIOException- If the attachment cannot be opened
-
listAttachments
Lists all attachments attached to a page.- Specified by:
listAttachmentsin interfaceAttachmentProvider- Parameters:
page- The page to list the attachments from.- Returns:
- A collection of Attachment objects. May be empty, but never null.
- Throws:
ProviderException- If something goes wrong when listing the attachments.
-
findAttachments
Finds attachments based on the query.- Specified by:
findAttachmentsin interfaceAttachmentProvider- Parameters:
query- An array of QueryItem objects to search for- Returns:
- A Collection of Attachment objects. May be empty, but never null.
-
listAllChanged
Lists changed attachments since given date. Can also be used to fetch a list of all pages.This is different from WikiPageProvider, where you basically get a list of all pages, then sort them locally. However, since some providers can be more efficient in locating recently changed files (like any database) than our non-optimized Java code, it makes more sense to fetch the whole list this way.
To get all files, call this with Date(0L);
- Specified by:
listAllChangedin interfaceAttachmentProvider- Parameters:
timestamp- List all files from this date onward.- Returns:
- A List of Attachment objects, in most-recently-changed first order.
- Throws:
ProviderException- If something goes wrong.
-
getAttachmentInfo
Returns info about an attachment.- Specified by:
getAttachmentInfoin interfaceAttachmentProvider- Parameters:
page- The parent pagename- The name of the attachmentversion- The version of the attachment (it's okay to use WikiPage.LATEST_VERSION to find the latest one)- Returns:
- An attachment object
- Throws:
ProviderException- If the attachment cannot be found or some other error occurs.
-
getVersionHistory
Returns version history. Each element should be an Attachment.- Specified by:
getVersionHistoryin interfaceAttachmentProvider- Parameters:
att- The attachment for which to find the version history for.- Returns:
- A List of Attachment objects.
-
deleteVersion
Removes a specific version from the repository. The implementations should really do no more security checks, since that is the domain of the AttachmentManager. Just delete it as efficiently as you can.- Specified by:
deleteVersionin interfaceAttachmentProvider- Parameters:
att- Attachment to be removed. The version field is checked, and thus only that version is removed.- Throws:
ProviderException- If the attachment cannot be removed for some reason.
-
deleteAttachment
Removes an entire page from the repository. The implementations should really do no more security checks, since that is the domain of the AttachmentManager. Just delete it as efficiently as you can. You should also delete any auxiliary files and directories that belong to this attachment, IF they were created by this provider.- Specified by:
deleteAttachmentin interfaceAttachmentProvider- Parameters:
att- Attachment to delete.- Throws:
ProviderException- If the page could not be removed for some reason.
-
getProviderInfo
Gets the provider class name, and cache statistics (misscount and,hitcount of the attachment cache).- Specified by:
getProviderInfoin interfaceWikiProvider- Returns:
- A plain string with all the above mentioned values.
-
getRealProvider
Returns the WikiAttachmentProvider that this caching provider delegates to.- Returns:
- The real provider underneath this one.
-
moveAttachmentsForPage
Move all the attachments for a given page so that they are attached to a new page.- Specified by:
moveAttachmentsForPagein interfaceAttachmentProvider- Parameters:
oldParent- Name of the page we are to move the attachments from.newParent- Name of the page we are to move the attachments to.- Throws:
ProviderException- If the attachments could not be moved for some reason.
-