Package org.apache.wiki.attachment

# Class DefaultAttachmentManager

java.lang.Object
org.apache.wiki.attachment.DefaultAttachmentManager

All Implemented Interfaces:
  `AttachmentManager`

public class DefaultAttachmentManager extends Object implements AttachmentManager
Default implementation for `AttachmentManager`.

Since:
  1.9.28

## Field Summary

### Fields inherited from interface org.apache.wiki.attachment.AttachmentManager

`PROP_ALLOWEDEXTENSIONS, PROP_FORBIDDENEXTENSIONS, PROP_FORCEDOWNLOAD, PROP_MAXSIZE, PROP_PROVIDER, PROP_PROVIDER_DEPRECATED`

## Constructor Summary

Constructors
Constructor
Description
`DefaultAttachmentManager(org.apache.wiki.api.core.Engine engine, Properties props)`
Creates a new AttachmentManager.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`attachmentsEnabled()`
Returns true, if attachments are enabled and running.
`void`
`deleteAttachment(org.apache.wiki.api.core.Attachment att)`
Deletes all versions of the given attachment.
`void`
`deleteVersion(org.apache.wiki.api.core.Attachment att)`
Deletes the given attachment version.
`boolean`
`forceDownload(String name)`
Check if attachement link should force a download iso opening the attachment in the browser.
`Collection<org.apache.wiki.api.core.Attachment>`
`getAllAttachments()`
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.
`org.apache.wiki.api.core.Attachment`
`getAttachmentInfo(org.apache.wiki.api.core.Context context, String attachmentname, int version)`
Figures out the full attachment name from the context and attachment name.
`String`
`getAttachmentInfoName(org.apache.wiki.api.core.Context context, String attachmentname)`
Figures out the full attachment name from the context and attachment name.
`InputStream`
`getAttachmentStream(org.apache.wiki.api.core.Context ctx, org.apache.wiki.api.core.Attachment att)`
Returns an attachment stream using the particular WikiContext.
`org.apache.wiki.api.providers.AttachmentProvider`
`getCurrentProvider()`
Returns the current attachment provider.
`DynamicAttachment`
`getDynamicAttachment(String name)`
Finds a DynamicAttachment.
`List<org.apache.wiki.api.core.Attachment>`
`getVersionHistory(String attachmentName)`
Returns a list of versions of the attachment.
`List<org.apache.wiki.api.core.Attachment>`
`listAttachments(org.apache.wiki.api.core.Page wikipage)`
Returns the list of attachments associated with a given wiki page.
`void`
`storeAttachment(org.apache.wiki.api.core.Attachment att, InputStream in)`
Stores an attachment directly from a stream.
`void`
`storeDynamicAttachment(org.apache.wiki.api.core.Context ctx, DynamicAttachment att)`
Stores a dynamic attachment.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.wiki.attachment.AttachmentManager

`getAttachmentInfo, getAttachmentInfo, getAttachmentInfo, getAttachmentStream, hasAttachments, storeAttachment`

## Constructor Details

### DefaultAttachmentManager

public DefaultAttachmentManager(org.apache.wiki.api.core.Engine 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.getManager( AttachmentManager.class ) 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 Details

### attachmentsEnabled

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

Specified by:
  `attachmentsEnabled` in interface `AttachmentManager`
Returns:
  A boolean value indicating whether attachment functionality is enabled.

### getAttachmentInfoName

public String getAttachmentInfoName(org.apache.wiki.api.core.Context context, String attachmentname)
Figures out the full attachment name from the context and attachment name.

Specified by:
  `getAttachmentInfoName` in interface `AttachmentManager`
Parameters:
  `context` - The current WikiContext
  `attachmentname` - The file name of the attachment.
Returns:
  Attachment, or null, if no such attachment exists.

### getAttachmentInfo

public org.apache.wiki.api.core.Attachment getAttachmentInfo(org.apache.wiki.api.core.Context context, String attachmentname, int version) throws org.apache.wiki.api.exceptions.ProviderException
Figures out the full attachment name from the context and attachment name.

Specified by:
  `getAttachmentInfo` in interface `AttachmentManager`
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:
  `org.apache.wiki.api.exceptions.ProviderException` - If something goes wrong.

### listAttachments

public List<org.apache.wiki.api.core.Attachment> listAttachments(org.apache.wiki.api.core.Page wikipage) throws org.apache.wiki.api.exceptions.ProviderException
Returns the list of attachments associated with a given wiki page. If there are no attachments, returns an empty Collection.

Specified by:
  `listAttachments` in interface `AttachmentManager`
Parameters:
  `wikipage` - The wiki page from which you are seeking attachments for.
Returns:
  a valid collection of attachments.
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - If there was something wrong in the backend.

### forceDownload

public boolean forceDownload(String name)
Check if attachement link should force a download iso opening the attachment in the browser.

Specified by:
  `forceDownload` in interface `AttachmentManager`
Parameters:
  `name` - Name of attachment to be checked
Returns:
  true, if the attachment should be downloaded when clicking the link

### getAttachmentStream

public InputStream getAttachmentStream(org.apache.wiki.api.core.Context ctx, org.apache.wiki.api.core.Attachment att) throws org.apache.wiki.api.exceptions.ProviderException, IOException
Returns an attachment stream using the particular WikiContext. This method should be used instead of `AttachmentManager.getAttachmentStream(Attachment)`, since it also allows the DynamicAttachments to function.

Specified by:
  `getAttachmentStream` in interface `AttachmentManager`
Parameters:
  `ctx` - The Wiki Context
  `att` - The Attachment to find
Returns:
  An InputStream. May return null, if attachments are disabled. You must take care of closing it.
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - If the backend fails due to some reason
  `IOException` - If the stream cannot be opened

### storeDynamicAttachment

public void storeDynamicAttachment(org.apache.wiki.api.core.Context ctx, DynamicAttachment att)
Stores a dynamic attachment. Unlike storeAttachment(), this just stores the attachment in the memory.

Specified by:
  `storeDynamicAttachment` in interface `AttachmentManager`
Parameters:
  `ctx` - A WikiContext
  `att` - An attachment to store

### getDynamicAttachment

public DynamicAttachment getDynamicAttachment(String name)
Finds a DynamicAttachment. Normally, you should just use `AttachmentManager.getAttachmentInfo(String)` , since that will find also `DynamicAttachment`s.

Specified by:
  `getDynamicAttachment` in interface `AttachmentManager`
Parameters:
  `name` - The name of the attachment to look for
Returns:
  An Attachment, or null.
See Also:
  - `AttachmentManager.getAttachmentInfo(String)`

### storeAttachment

public void storeAttachment(org.apache.wiki.api.core.Attachment att, InputStream in) throws IOException, org.apache.wiki.api.exceptions.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.

Specified by:
  `storeAttachment` in interface `AttachmentManager`
Parameters:
  `att` - Attachment to store this under.
  `in` - InputStream from which the attachment contents will be read.
Throws:
  `IOException` - If writing the attachment failed.
  `org.apache.wiki.api.exceptions.ProviderException` - If something else went wrong.

### getVersionHistory

public List<org.apache.wiki.api.core.Attachment> getVersionHistory(String attachmentName) throws org.apache.wiki.api.exceptions.ProviderException
Returns a list of versions of the attachment.

Specified by:
  `getVersionHistory` in interface `AttachmentManager`
Parameters:
  `attachmentName` - A fully qualified name of the attachment.
Returns:
  A list of Attachments. May return null, if attachments are disabled.
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - If the provider fails for some reason.

### getAllAttachments

public Collection<org.apache.wiki.api.core.Attachment> getAllAttachments() throws org.apache.wiki.api.exceptions.ProviderException
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.

Specified by:
  `getAllAttachments` in interface `AttachmentManager`
Returns:
  A collection of attachments. If attachments are disabled, will return an empty collection.
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - If something went wrong with the backend

### getCurrentProvider

public org.apache.wiki.api.providers.AttachmentProvider getCurrentProvider()
Returns the current attachment provider.

Specified by:
  `getCurrentProvider` in interface `AttachmentManager`
Returns:
  The current provider. May be null, if attachments are disabled.

### deleteVersion

public void deleteVersion(org.apache.wiki.api.core.Attachment att) throws org.apache.wiki.api.exceptions.ProviderException
Deletes the given attachment version.

Specified by:
  `deleteVersion` in interface `AttachmentManager`
Parameters:
  `att` - The attachment to delete
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - If something goes wrong with the backend.

### deleteAttachment

public void deleteAttachment(org.apache.wiki.api.core.Attachment att) throws org.apache.wiki.api.exceptions.ProviderException
Deletes all versions of the given attachment.

Specified by:
  `deleteAttachment` in interface `AttachmentManager`
Parameters:
  `att` - The Attachment to delete.
Throws:
  `org.apache.wiki.api.exceptions.ProviderException` - if something goes wrong with the backend.