com.ecyrd.jspwiki.attachment
Class AttachmentManager

java.lang.Object
  extended by com.ecyrd.jspwiki.attachment.AttachmentManager

public class AttachmentManager
extends Object

Provides facilities for handling attachments. All attachment handling goes through this class.

The AttachmentManager provides a facade towards the current WikiAttachmentProvider that is in use. It is created by the WikiEngine as a singleton object, and can be requested through the WikiEngine.

Since:
1.9.28
Author:
Janne Jalkanen

Field Summary
static String PROP_MAXSIZE
          The maximum size of attachments that can be uploaded.
static String PROP_PROVIDER
          The property name for defining the attachment provider class name.
 
Constructor Summary
AttachmentManager(WikiEngine engine, Properties props)
          Creates a new AttachmentManager.
 
Method Summary
 boolean attachmentsEnabled()
          Returns true, if attachments are enabled and running.
 void deleteAttachment(Attachment att)
          Deletes all versions of the given attachment.
 void deleteVersion(Attachment att)
          Deletes the given attachment version.
 Collection getAllAttachments()
          Returns a collection of Attachments, containing each and every attachment that is in this Wiki.
 Attachment getAttachmentInfo(String name)
          Gets info on a particular attachment, latest version.
 Attachment getAttachmentInfo(String name, int version)
          Gets info on a particular attachment with the given version.
 Attachment getAttachmentInfo(WikiContext context, String attachmentname)
          Figures out the full attachment name from the context and attachment name.
 Attachment getAttachmentInfo(WikiContext context, String attachmentname, int version)
          Figures out the full attachment name from the context and attachment name.
 InputStream getAttachmentStream(Attachment att)
          Finds an attachment from the repository as a stream.
 WikiAttachmentProvider getCurrentProvider()
          Returns the current attachment provider.
 List getVersionHistory(String attachmentName)
          Returns a list of versions of the attachment.
 boolean hasAttachments(WikiPage wikipage)
          Returns true, if the page has any attachments at all.
 Collection listAttachments(WikiPage wikipage)
          Returns the list of attachments associated with a given wiki page.
 void storeAttachment(Attachment att, File source)
          Stores an attachment that lives in the given file.
 void storeAttachment(Attachment att, InputStream in)
          Stores an attachment directly from a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_PROVIDER

public static final String PROP_PROVIDER
The property name for defining the attachment provider class name.

See Also:
Constant Field Values

PROP_MAXSIZE

public static final String PROP_MAXSIZE
The maximum size of attachments that can be uploaded.

See Also:
Constant Field Values
Constructor Detail

AttachmentManager

public AttachmentManager(WikiEngine engine,
                         Properties props)
Creates a new AttachmentManager. Note that creation will never fail, but it's quite likely that attachments do not function.

DO NOT CREATE an AttachmentManager on your own, unless you really know what you're doing. Just use WikiEngine.getAttachmentManager() if you're making a module for JSPWiki.

Parameters:
engine - The wikiengine that owns this attachment manager.
props - A list of properties from which the AttachmentManager will seek its configuration. Typically this is the "jspwiki.properties".
Method Detail

attachmentsEnabled

public boolean attachmentsEnabled()
Returns true, if attachments are enabled and running.


getAttachmentInfo

public Attachment getAttachmentInfo(String name)
                             throws ProviderException
Gets info on a particular attachment, latest version.

Parameters:
name - A full attachment name.
Returns:
Attachment, or null, if no such attachment exists.
Throws:
ProviderException - If something goes wrong.

getAttachmentInfo

public Attachment getAttachmentInfo(String name,
                                    int version)
                             throws ProviderException
Gets info on a particular attachment with the given version.

Parameters:
name - A full attachment name.
version - A version number.
Returns:
Attachment, or null, if no such attachment or version exists.
Throws:
ProviderException - If something goes wrong.

getAttachmentInfo

public Attachment getAttachmentInfo(WikiContext context,
                                    String attachmentname)
                             throws ProviderException
Figures out the full attachment name from the context and attachment name.

Parameters:
context - The current WikiContext
attachmentname - The file name of the attachment.
Returns:
Attachment, or null, if no such attachment exists.
Throws:
ProviderException - If something goes wrong.

getAttachmentInfo

public Attachment getAttachmentInfo(WikiContext context,
                                    String attachmentname,
                                    int version)
                             throws ProviderException
Figures out the full attachment name from the context and attachment name.

Parameters:
context - The current WikiContext
attachmentname - The file name of the attachment.
version - A particular version.
Returns:
Attachment, or null, if no such attachment or version exists.
Throws:
ProviderException - If something goes wrong.

listAttachments

public Collection listAttachments(WikiPage wikipage)
                           throws ProviderException
Returns the list of attachments associated with a given wiki page. If there are no attachments, returns an empty Collection.

Parameters:
wikipage - The wiki page from which you are seeking attachments for.
Returns:
a valid collection of attachments.
Throws:
ProviderException

hasAttachments

public boolean hasAttachments(WikiPage wikipage)
Returns true, if the page has any attachments at all. This is a convinience method.

Parameters:
wikipage - The wiki page from which you are seeking attachments for.
Returns:
True, if the page has attachments, else false.

getAttachmentStream

public InputStream getAttachmentStream(Attachment att)
                                throws IOException,
                                       ProviderException
Finds an attachment from the repository as a stream.

Parameters:
att - Attachment
Returns:
An InputStream to read from. May return null, if attachments are disabled.
Throws:
IOException
ProviderException

storeAttachment

public void storeAttachment(Attachment att,
                            File source)
                     throws IOException,
                            ProviderException
Stores an attachment that lives in the given file. If the attachment did not exist previously, this method will create it. If it did exist, it stores a new version.

Parameters:
att - Attachment to store this under.
source - A file to read from.
Throws:
IOException - If writing the attachment failed.
ProviderException - If something else went wrong.

storeAttachment

public void storeAttachment(Attachment att,
                            InputStream in)
                     throws IOException,
                            ProviderException
Stores an attachment directly from a stream. If the attachment did not exist previously, this method will create it. If it did exist, it stores a new version.

Parameters:
att - Attachment to store this under.
in - InputStream from which the attachment contents will be read.
Throws:
IOException - If writing the attachment failed.
ProviderException - If something else went wrong.

getVersionHistory

public List getVersionHistory(String attachmentName)
                       throws ProviderException
Returns a list of versions of the attachment.

Parameters:
attachmentName - A fully qualified name of the attachment.
Returns:
A list of Attachments. May return null, if attachments are disabled.
Throws:
ProviderException - If the provider fails for some reason.

getAllAttachments

public Collection getAllAttachments()
                             throws ProviderException
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.

Returns:
A collection of attachments. If attachments are disabled, will return an empty collection.
Throws:
ProviderException

getCurrentProvider

public WikiAttachmentProvider getCurrentProvider()
Returns the current attachment provider.

Returns:
The current provider. May be null, if attachments are disabled.

deleteVersion

public void deleteVersion(Attachment att)
                   throws ProviderException
Deletes the given attachment version.

Throws:
ProviderException

deleteAttachment

public void deleteAttachment(Attachment att)
                      throws ProviderException
Deletes all versions of the given attachment.

Throws:
ProviderException