org.apache.wiki.providers
Class BasicAttachmentProvider

java.lang.Object
  extended by org.apache.wiki.providers.BasicAttachmentProvider
All Implemented Interfaces:
WikiAttachmentProvider, WikiProvider

public class BasicAttachmentProvider
extends Object
implements WikiAttachmentProvider

Provides basic, versioning attachments.

   Structure is as follows:
      attachment_dir/
         ThisPage/
            attachment.doc/
               attachment.properties
               1.doc
               2.doc
               3.doc
            picture.png/
               attachment.properties
               1.png
               2.png
         ThatPage/
            picture.png/
               attachment.properties
               1.png
             
  
The names of the directories will be URLencoded.

"attachment.properties" consists of the following items:


Nested Class Summary
static class BasicAttachmentProvider.AttachmentFilter
          Returns only those directories that contain attachments.
static class BasicAttachmentProvider.AttachmentVersionFilter
          Accepts only files that are actual versions, no control files.
 
Field Summary
static String ATTDIR_EXTENSION
          The default extension for the attachment directory.
static String DIR_EXTENSION
          The default extension for the page attachment directory name.
static String PROP_DISABLECACHE
          The property name for specifying which attachments are not cached.
static String PROP_STORAGEDIR
          The property name for where the attachments should be stored.
static String PROPERTY_FILE
          The name of the property file.
 
Fields inherited from interface org.apache.wiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
BasicAttachmentProvider()
           
 
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.
protected static String getFileExtension(String filename)
          Returns the file extension.
 String getProviderInfo()
          Return a valid HTML string for information.
 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

PROP_STORAGEDIR

public static final String PROP_STORAGEDIR
The property name for where the attachments should be stored. Value is "jspwiki.basicAttachmentProvider.storageDir".

See Also:
Constant Field Values

PROP_DISABLECACHE

public static final String PROP_DISABLECACHE
The property name for specifying which attachments are not cached. Value is "jspwiki.basicAttachmentProvider.disableCache".

See Also:
Constant Field Values

PROPERTY_FILE

public static final String PROPERTY_FILE
The name of the property file.

See Also:
Constant Field Values

DIR_EXTENSION

public static final String DIR_EXTENSION
The default extension for the page attachment directory name.

See Also:
Constant Field Values

ATTDIR_EXTENSION

public static final String ATTDIR_EXTENSION
The default extension for the attachment directory.

See Also:
Constant Field Values
Constructor Detail

BasicAttachmentProvider

public BasicAttachmentProvider()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties properties)
                throws NoRequiredPropertyException,
                       IOException
Initializes the page provider.

Specified by:
initialize in interface WikiProvider
Parameters:
engine - WikiEngine to own this provider
properties - A set of properties used to initialize this provider
Throws:
NoRequiredPropertyException - If the provider needs a property which is not found in the property set
IOException - If there is an IO problem

getFileExtension

protected static String getFileExtension(String filename)
Returns the file extension. For example "test.png" returns "png".

If file has no extension, will return "bin"

Parameters:
filename - The file name to check
Returns:
The extension. If no extension is found, returns "bin".

putAttachmentData

public void putAttachmentData(Attachment att,
                              InputStream data)
                       throws ProviderException,
                              IOException
Put new attachment data.

Specified by:
putAttachmentData in interface WikiAttachmentProvider
Parameters:
att - Attachment object to add new data to
data - The stream from which the provider should read the data
Throws:
ProviderException - If there are other errors.
IOException - If writing fails

getProviderInfo

public String getProviderInfo()
Return a valid HTML string for information. May be anything.

Specified by:
getProviderInfo in interface WikiProvider
Returns:
A string describing the provider.

getAttachmentData

public InputStream getAttachmentData(Attachment att)
                              throws IOException,
                                     ProviderException
Get attachment data.

Specified by:
getAttachmentData in interface WikiAttachmentProvider
Parameters:
att - The attachment
Returns:
An InputStream which you contains the raw data of the object. It's your responsibility to close it.
Throws:
IOException - If the attachment cannot be opened
ProviderException - If the attachment cannot be found

listAttachments

public Collection listAttachments(WikiPage page)
                           throws ProviderException
Lists all attachments attached to a page.

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

public Collection findAttachments(QueryItem[] query)
Finds attachments based on the query.

Specified by:
findAttachments in interface WikiAttachmentProvider
Parameters:
query - An array of QueryItem objects to search for
Returns:
A Collection of Attachment objects. May be empty, but never null.

listAllChanged

public List listAllChanged(Date timestamp)
                    throws ProviderException
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 - If something goes wrong.

getAttachmentInfo

public Attachment getAttachmentInfo(WikiPage page,
                                    String name,
                                    int version)
                             throws ProviderException
Returns info about an attachment.

Specified by:
getAttachmentInfo in interface WikiAttachmentProvider
Parameters:
page - The parent page
name - The name of the attachment
version - 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

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

Specified by:
getVersionHistory in interface WikiAttachmentProvider
Parameters:
att - The attachment for which to find the version history for.
Returns:
A List of Attachment objects.

deleteVersion

public void deleteVersion(Attachment att)
                   throws ProviderException
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
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.

moveAttachmentsForPage

public void moveAttachmentsForPage(String oldParent,
                                   String newParent)
                            throws ProviderException
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.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.