Package org.apache.wiki.attachment
Class DefaultAttachmentManager
- java.lang.Object
-
- org.apache.wiki.attachment.DefaultAttachmentManager
-
- All Implemented Interfaces:
AttachmentManager
public class DefaultAttachmentManager extends java.lang.Object implements AttachmentManager
Default implementation forAttachmentManager
.- 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(Engine engine, java.util.Properties props)
Creates a new AttachmentManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.boolean
forceDownload(java.lang.String name)
Check if attachement link should force a download iso opening the attachment in the browser.java.util.Collection<Attachment>
getAllAttachments()
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.Attachment
getAttachmentInfo(Context context, java.lang.String attachmentname, int version)
Figures out the full attachment name from the context and attachment name.java.lang.String
getAttachmentInfoName(Context context, java.lang.String attachmentname)
Figures out the full attachment name from the context and attachment name.java.io.InputStream
getAttachmentStream(Context ctx, Attachment att)
Returns an attachment stream using the particular WikiContext.AttachmentProvider
getCurrentProvider()
Returns the current attachment provider.DynamicAttachment
getDynamicAttachment(java.lang.String name)
Finds a DynamicAttachment.java.util.List<Attachment>
getVersionHistory(java.lang.String attachmentName)
Returns a list of versions of the attachment.java.util.List<Attachment>
listAttachments(Page wikipage)
Returns the list of attachments associated with a given wiki page.void
storeAttachment(Attachment att, java.io.InputStream in)
Stores an attachment directly from a stream.void
storeDynamicAttachment(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 Detail
-
DefaultAttachmentManager
public DefaultAttachmentManager(Engine engine, java.util.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 Detail
-
attachmentsEnabled
public boolean attachmentsEnabled()
Returns true, if attachments are enabled and running.- Specified by:
attachmentsEnabled
in interfaceAttachmentManager
- Returns:
- A boolean value indicating whether attachment functionality is enabled.
-
getAttachmentInfoName
public java.lang.String getAttachmentInfoName(Context context, java.lang.String attachmentname)
Figures out the full attachment name from the context and attachment name.- Specified by:
getAttachmentInfoName
in 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, java.lang.String attachmentname, int version) throws ProviderException
Figures out the full attachment name from the context and attachment name.- Specified by:
getAttachmentInfo
in 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
public java.util.List<Attachment> listAttachments(Page wikipage) throws 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 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
public boolean forceDownload(java.lang.String name)
Check if attachement link should force a download iso opening the attachment in the browser.- Specified by:
forceDownload
in interfaceAttachmentManager
- Parameters:
name
- Name of attachment to be checked- Returns:
- true, if the attachment should be downloaded when clicking the link
-
getAttachmentStream
public java.io.InputStream getAttachmentStream(Context ctx, Attachment att) throws ProviderException, java.io.IOException
Returns 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:
getAttachmentStream
in 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 reasonjava.io.IOException
- If the stream cannot be opened
-
storeDynamicAttachment
public void storeDynamicAttachment(Context ctx, DynamicAttachment att)
Stores a dynamic attachment. Unlike storeAttachment(), this just stores the attachment in the memory.- Specified by:
storeDynamicAttachment
in interfaceAttachmentManager
- Parameters:
ctx
- A WikiContextatt
- An attachment to store
-
getDynamicAttachment
public DynamicAttachment getDynamicAttachment(java.lang.String name)
Finds a DynamicAttachment. Normally, you should just useAttachmentManager.getAttachmentInfo(String)
, since that will find alsoDynamicAttachment
s.- Specified by:
getDynamicAttachment
in interfaceAttachmentManager
- Parameters:
name
- The name of the attachment to look for- Returns:
- An Attachment, or null.
- See Also:
AttachmentManager.getAttachmentInfo(String)
-
storeAttachment
public void storeAttachment(Attachment att, java.io.InputStream in) throws java.io.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.- Specified by:
storeAttachment
in interfaceAttachmentManager
- Parameters:
att
- Attachment to store this under.in
- InputStream from which the attachment contents will be read.- Throws:
java.io.IOException
- If writing the attachment failed.ProviderException
- If something else went wrong.
-
getVersionHistory
public java.util.List<Attachment> getVersionHistory(java.lang.String attachmentName) throws ProviderException
Returns a list of versions of the attachment.- Specified by:
getVersionHistory
in 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
public java.util.Collection<Attachment> getAllAttachments() throws ProviderException
Returns a collection of Attachments, containing each and every attachment that is in this Wiki.- Specified by:
getAllAttachments
in 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
public AttachmentProvider getCurrentProvider()
Returns the current attachment provider.- Specified by:
getCurrentProvider
in interfaceAttachmentManager
- Returns:
- The current provider. May be null, if attachments are disabled.
-
deleteVersion
public void deleteVersion(Attachment att) throws ProviderException
Deletes the given attachment version.- Specified by:
deleteVersion
in interfaceAttachmentManager
- Parameters:
att
- The attachment to delete- Throws:
ProviderException
- If something goes wrong with the backend.
-
deleteAttachment
public void deleteAttachment(Attachment att) throws ProviderException
Deletes all versions of the given attachment.- Specified by:
deleteAttachment
in interfaceAttachmentManager
- Parameters:
att
- The Attachment to delete.- Throws:
ProviderException
- if something goes wrong with the backend.
-
-