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
CACHE_NAME, DEFAULT_CACHECAPACITY, PROP_ALLOWEDEXTENSIONS, PROP_FORBIDDENEXTENSIONS, PROP_FORCEDOWNLOAD, PROP_MAXSIZE, PROP_PROVIDER -
Constructor Summary
Constructors Constructor Description DefaultAttachmentManager(Engine engine, Properties props)Creates a new AttachmentManager. -
Method Summary
Modifier and Type Method Description booleanattachmentsEnabled()Returns true, if attachments are enabled and running.voiddeleteAttachment(Attachment att)Deletes all versions of the given attachment.voiddeleteVersion(Attachment att)Deletes the given attachment version.booleanforceDownload(String name)Check if attachement link should force a download iso opening the attachment in the browser.Collection<Attachment>getAllAttachments()Returns a collection of Attachments, containing each and every attachment that is in this Wiki.AttachmentgetAttachmentInfo(Context context, String attachmentname, int version)Figures out the full attachment name from the context and attachment name.StringgetAttachmentInfoName(Context context, String attachmentname)Figures out the full attachment name from the context and attachment name.InputStreamgetAttachmentStream(Context ctx, Attachment att)Returns an attachment stream using the particular WikiContext.AttachmentProvidergetCurrentProvider()Returns the current attachment provider.DynamicAttachmentgetDynamicAttachment(String name)Finds a DynamicAttachment.List<Attachment>getVersionHistory(String attachmentName)Returns a list of versions of the attachment.List<Attachment>listAttachments(Page wikipage)Returns the list of attachments associated with a given wiki page.voidstoreAttachment(Attachment att, InputStream in)Stores an attachment directly from a stream.voidstoreDynamicAttachment(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, waitMethods inherited from interface org.apache.wiki.attachment.AttachmentManager
getAttachmentInfo, getAttachmentInfo, getAttachmentInfo, getAttachmentStream, hasAttachments, storeAttachment
-
Constructor Details
-
DefaultAttachmentManager
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
Returns true, if attachments are enabled and running.- Specified by:
attachmentsEnabledin interfaceAttachmentManager- Returns:
- A boolean value indicating whether attachment functionality is enabled.
-
getAttachmentInfoName
Figures out the full attachment name from the context and attachment name.- Specified by:
getAttachmentInfoNamein interfaceAttachmentManager- Parameters:
context- The current WikiContextattachmentname- The file name of the attachment.- Returns:
- Attachment, or null, if no such attachment exists.
-
getAttachmentInfo
public Attachment getAttachmentInfo(Context context, String attachmentname, int version) throws ProviderExceptionFigures out the full attachment name from the context and attachment name.- Specified by:
getAttachmentInfoin interfaceAttachmentManager- Parameters:
context- The current WikiContextattachmentname- 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
Returns the list of attachments associated with a given wiki page. If there are no attachments, returns an empty Collection.- Specified by:
listAttachmentsin interfaceAttachmentManager- Parameters:
wikipage- The wiki page from which you are seeking attachments for.- Returns:
- a valid collection of attachments.
- Throws:
ProviderException- If there was something wrong in the backend.
-
forceDownload
Check if attachement link should force a download iso opening the attachment in the browser.- Specified by:
forceDownloadin interfaceAttachmentManager- Parameters:
name- Name of attachment to be checked- Returns:
- true, if the attachment should be downloaded when clicking the link
-
getAttachmentStream
public InputStream getAttachmentStream(Context ctx, Attachment att) throws ProviderException, IOExceptionReturns an attachment stream using the particular WikiContext. This method should be used instead ofAttachmentManager.getAttachmentStream(Attachment), since it also allows the DynamicAttachments to function.- Specified by:
getAttachmentStreamin interfaceAttachmentManager- Parameters:
ctx- The Wiki Contextatt- The Attachment to find- Returns:
- An InputStream. May return null, if attachments are disabled. You must take care of closing it.
- Throws:
ProviderException- If the backend fails due to some reasonIOException- If the stream cannot be opened
-
storeDynamicAttachment
Stores a dynamic attachment. Unlike storeAttachment(), this just stores the attachment in the memory.- Specified by:
storeDynamicAttachmentin interfaceAttachmentManager- Parameters:
ctx- A WikiContextatt- An attachment to store
-
getDynamicAttachment
Finds a DynamicAttachment. Normally, you should just useAttachmentManager.getAttachmentInfo(String), since that will find alsoDynamicAttachments.- Specified by:
getDynamicAttachmentin interfaceAttachmentManager- Parameters:
name- The name of the attachment to look for- Returns:
- An Attachment, or null.
- See Also:
AttachmentManager.getAttachmentInfo(String)
-
storeAttachment
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:
storeAttachmentin interfaceAttachmentManager- 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
Returns a list of versions of the attachment.- Specified by:
getVersionHistoryin interfaceAttachmentManager- 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
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.- Specified by:
getAllAttachmentsin interfaceAttachmentManager- Returns:
- A collection of attachments. If attachments are disabled, will return an empty collection.
- Throws:
ProviderException- If something went wrong with the backend
-
getCurrentProvider
Returns the current attachment provider.- Specified by:
getCurrentProviderin interfaceAttachmentManager- Returns:
- The current provider. May be null, if attachments are disabled.
-
deleteVersion
Deletes the given attachment version.- Specified by:
deleteVersionin interfaceAttachmentManager- Parameters:
att- The attachment to delete- Throws:
ProviderException- If something goes wrong with the backend.
-
deleteAttachment
Deletes all versions of the given attachment.- Specified by:
deleteAttachmentin interfaceAttachmentManager- Parameters:
att- The Attachment to delete.- Throws:
ProviderException- if something goes wrong with the backend.
-