Interface AttachmentManager

All Known Implementing Classes:
DefaultAttachmentManager

public interface AttachmentManager
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 Engine as a singleton object, and can be requested through the Engine.

Since:
1.9.28
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A space-separated list of attachment types which can be uploaded
    static final String
    A space-separated list of attachment types which cannot be uploaded
    static final String
    A space-separated list of attachment types which will never open in the browser.
    static final String
    The maximum size of attachments that can be uploaded.
    static final String
    The property name for defining the attachment provider class name.
    static final String
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    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
    Check if attachement link should force a download iso opening the attachment in the browser.
    Collection<org.apache.wiki.api.core.Attachment>
    Returns a collection of Attachments, containing each and every attachment that is in this Wiki.
    default org.apache.wiki.api.core.Attachment
    Gets info on a particular attachment, latest version.
    default org.apache.wiki.api.core.Attachment
    getAttachmentInfo(String name, int version)
    Gets info on a particular attachment with the given version.
    default org.apache.wiki.api.core.Attachment
    getAttachmentInfo(org.apache.wiki.api.core.Context context, String attachmentname)
    Figures out the full attachment name from the context and attachment name.
    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.
    getAttachmentInfoName(org.apache.wiki.api.core.Context context, String attachmentname)
    Figures out the full attachment name from the context and attachment name.
    default InputStream
    getAttachmentStream(org.apache.wiki.api.core.Attachment att)
    Finds a (real) attachment from the repository as an 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
    Returns the current attachment provider.
    Finds a DynamicAttachment.
    List<org.apache.wiki.api.core.Attachment>
    getVersionHistory(String attachmentName)
    Returns a list of versions of the attachment.
    default boolean
    hasAttachments(org.apache.wiki.api.core.Page wikipage)
    Returns true, if the page has any attachments at all.
    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.
    default void
    storeAttachment(org.apache.wiki.api.core.Attachment att, File source)
    Stores an attachment that lives in the given file.
    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.
    static String
    Validates the filename and makes sure it is legal.
  • Field Details

  • Method Details

    • attachmentsEnabled

      Returns true, if attachments are enabled and running.
      Returns:
      A boolean value indicating whether attachment functionality is enabled.
    • getAttachmentInfo

      default org.apache.wiki.api.core.Attachment getAttachmentInfo(String name) throws org.apache.wiki.api.exceptions.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:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong.
    • getAttachmentInfo

      default org.apache.wiki.api.core.Attachment getAttachmentInfo(String name, int version) throws org.apache.wiki.api.exceptions.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:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong.
    • getAttachmentInfo

      default org.apache.wiki.api.core.Attachment getAttachmentInfo(org.apache.wiki.api.core.Context context, String attachmentname) throws org.apache.wiki.api.exceptions.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:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong.
    • getAttachmentInfo

      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.
      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.
    • getAttachmentInfoName

      String getAttachmentInfoName(org.apache.wiki.api.core.Context context, String attachmentname)
      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.
    • listAttachments

      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.
      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.
    • hasAttachments

      default boolean hasAttachments(org.apache.wiki.api.core.Page wikipage)
      Returns true, if the page has any attachments at all. This is a convenience method.
      Parameters:
      wikipage - The wiki page from which you are seeking attachments for.
      Returns:
      True, if the page has attachments, else false.
    • forceDownload

      boolean forceDownload(String name)
      Check if attachement link should force a download iso opening the attachment in the browser.
      Parameters:
      name - Name of attachment to be checked
      Returns:
      true, if the attachment should be downloaded when clicking the link
      Since:
      2.11.0 M4
    • getAttachmentStream

      default InputStream getAttachmentStream(org.apache.wiki.api.core.Attachment att) throws IOException, org.apache.wiki.api.exceptions.ProviderException
      Finds a (real) attachment from the repository as an InputStream.
      Parameters:
      att - Attachment
      Returns:
      An InputStream to read from. May return null, if attachments are disabled.
      Throws:
      IOException - If the stream cannot be opened
      org.apache.wiki.api.exceptions.ProviderException - If the backend fails due to some other reason.
    • getAttachmentStream

      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 getAttachmentStream(Attachment), since it also allows the DynamicAttachments to function.
      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

      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.
      Parameters:
      ctx - A WikiContext
      att - An attachment to store
    • getDynamicAttachment

      Finds a DynamicAttachment. Normally, you should just use getAttachmentInfo(String) , since that will find also DynamicAttachments.
      Parameters:
      name - The name of the attachment to look for
      Returns:
      An Attachment, or null.
      See Also:
    • storeAttachment

      default void storeAttachment(org.apache.wiki.api.core.Attachment att, File source) throws IOException, org.apache.wiki.api.exceptions.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.
      org.apache.wiki.api.exceptions.ProviderException - If something else went wrong.
    • storeAttachment

      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.
      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

      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.
      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

      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.
      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

      org.apache.wiki.api.providers.AttachmentProvider getCurrentProvider()
      Returns the current attachment provider.
      Returns:
      The current provider. May be null, if attachments are disabled.
    • deleteVersion

      void deleteVersion(org.apache.wiki.api.core.Attachment att) throws org.apache.wiki.api.exceptions.ProviderException
      Deletes the given attachment version.
      Parameters:
      att - The attachment to delete
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong with the backend.
    • deleteAttachment

      void deleteAttachment(org.apache.wiki.api.core.Attachment att) throws org.apache.wiki.api.exceptions.ProviderException
      Deletes all versions of the given attachment.
      Parameters:
      att - The Attachment to delete.
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - if something goes wrong with the backend.
    • validateFileName

      static String validateFileName(String filename) throws org.apache.wiki.api.exceptions.WikiException
      Validates the filename and makes sure it is legal. It trims and splits and replaces bad characters.
      Parameters:
      filename - file name to validate.
      Returns:
      A validated name with annoying characters replaced.
      Throws:
      org.apache.wiki.api.exceptions.WikiException - If the filename is not legal (e.g. empty)