com.ecyrd.jspwiki.providers
Class CachingAttachmentProvider

java.lang.Object
  extended by com.ecyrd.jspwiki.providers.CachingAttachmentProvider
All Implemented Interfaces:
WikiAttachmentProvider, WikiProvider

public class CachingAttachmentProvider
extends Object
implements WikiAttachmentProvider

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.
Author:
Janne Jalkanen

Field Summary
static String DIR_EXTENSION
           
static String PROP_STORAGEDIR
           
 
Fields inherited from interface com.ecyrd.jspwiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
CachingAttachmentProvider()
           
 
Method Summary
 void deleteAttachment(Attachment att)
          Removes an entire page from the repository.
 void deleteVersion(Attachment att)
          Removes a specific version from the repository.
 Collection findAttachments(QueryItem[] query)
          Finds attachments based on the query.
 InputStream getAttachmentData(Attachment att)
          Get attachment data.
 Attachment getAttachmentInfo(WikiPage page, String name, int version)
          Returns info about an attachment.
 String getProviderInfo()
          Return a valid HTML string for information.
 WikiAttachmentProvider getRealProvider()
           
 List getVersionHistory(Attachment att)
          Returns version history.
 void initialize(WikiEngine engine, Properties properties)
          Initializes the page provider.
 List listAllChanged(Date timestamp)
          Lists changed attachments since given date.
 Collection listAttachments(WikiPage page)
          Lists all attachments attached to a page.
 void moveAttachmentsForPage(String oldParent, String newParent)
          Move all the attachments for a given page so that they are attached to a new page.
 void putAttachmentData(Attachment att, InputStream data)
          Put new attachment data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_EXTENSION

public static final String DIR_EXTENSION
See Also:
Constant Field Values

PROP_STORAGEDIR

public static final String PROP_STORAGEDIR
See Also:
Constant Field Values
Constructor Detail

CachingAttachmentProvider

public CachingAttachmentProvider()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties properties)
                throws NoRequiredPropertyException,
                       IOException
Description copied from interface: WikiProvider
Initializes the page provider.

Specified by:
initialize in interface WikiProvider
Throws:
NoRequiredPropertyException
IOException

putAttachmentData

public void putAttachmentData(Attachment att,
                              InputStream data)
                       throws ProviderException,
                              IOException
Description copied from interface: WikiAttachmentProvider
Put new attachment data.

Specified by:
putAttachmentData in interface WikiAttachmentProvider
Throws:
ProviderException
IOException

getAttachmentData

public InputStream getAttachmentData(Attachment att)
                              throws ProviderException,
                                     IOException
Description copied from interface: WikiAttachmentProvider
Get attachment data.

Specified by:
getAttachmentData in interface WikiAttachmentProvider
Throws:
ProviderException
IOException

listAttachments

public Collection listAttachments(WikiPage page)
                           throws ProviderException
Description copied from interface: WikiAttachmentProvider
Lists all attachments attached to a page.

Specified by:
listAttachments in interface WikiAttachmentProvider
Returns:
A collection of Attachment objects. May be empty, but never null.
Throws:
ProviderException

findAttachments

public Collection findAttachments(QueryItem[] query)
Description copied from interface: WikiAttachmentProvider
Finds attachments based on the query.

Specified by:
findAttachments in interface WikiAttachmentProvider

listAllChanged

public List listAllChanged(Date timestamp)
                    throws ProviderException
Description copied from interface: WikiAttachmentProvider
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:
listAllChanged in interface WikiAttachmentProvider
Parameters:
timestamp - List all files from this date onward.
Returns:
A List of Attachment objects, in most-recently-changed first order.
Throws:
ProviderException

getAttachmentInfo

public Attachment getAttachmentInfo(WikiPage page,
                                    String name,
                                    int version)
                             throws ProviderException
Description copied from interface: WikiAttachmentProvider
Returns info about an attachment.

Specified by:
getAttachmentInfo in interface WikiAttachmentProvider
Throws:
ProviderException

getVersionHistory

public List getVersionHistory(Attachment att)
Returns version history. Each element should be an Attachment.

Specified by:
getVersionHistory in interface WikiAttachmentProvider

deleteVersion

public void deleteVersion(Attachment att)
                   throws ProviderException
Description copied from interface: WikiAttachmentProvider
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:
deleteVersion in interface WikiAttachmentProvider
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

public void deleteAttachment(Attachment att)
                      throws ProviderException
Description copied from interface: WikiAttachmentProvider
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:
deleteAttachment in interface WikiAttachmentProvider
Parameters:
att - Attachment to delete.
Throws:
ProviderException - If the page could not be removed for some reason.

getProviderInfo

public String getProviderInfo()
Description copied from interface: WikiProvider
Return a valid HTML string for information. May be anything.

Specified by:
getProviderInfo in interface WikiProvider

getRealProvider

public WikiAttachmentProvider getRealProvider()

moveAttachmentsForPage

public void moveAttachmentsForPage(String oldParent,
                                   String newParent)
                            throws ProviderException
Description copied from interface: WikiAttachmentProvider
Move all the attachments for a given page so that they are attached to a new page.

Specified by:
moveAttachmentsForPage in interface WikiAttachmentProvider
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.