Class BasicAttachmentProvider

  • All Implemented Interfaces:
    AttachmentProvider, WikiProvider

    public class BasicAttachmentProvider
    extends java.lang.Object
    implements AttachmentProvider
    Provides basic, versioning attachments.
       Structure is as follows:
          attachment_dir/
             ThisPage/
                attachment.doc/
                   attachment.properties
                   1.doc
                   2.doc
                   3.doc
                picture.png/
                   attachment.properties
                   1.png
                   2.png
             ThatPage/
                picture.png/
                   attachment.properties
                   1.png
                 
      
    The names of the directories will be URLencoded.

    "attachment.properties" consists of the following items:

    • 1.author = author name for version 1 (etc)
    • Method Detail

      • initialize

        public void initialize​(Engine engine,
                               java.util.Properties properties)
                        throws NoRequiredPropertyException,
                               java.io.IOException
        Initializes the page provider.
        Specified by:
        initialize in interface WikiProvider
        Parameters:
        engine - Engine to own this provider
        properties - A set of properties used to initialize this provider
        Throws:
        NoRequiredPropertyException - If the provider needs a property which is not found in the property set
        java.io.IOException - If there is an IO problem
      • getFileExtension

        protected static java.lang.String getFileExtension​(java.lang.String filename)
        Returns the file extension. For example "test.png" returns "png".

        If file has no extension, will return "bin"

        Parameters:
        filename - The file name to check
        Returns:
        The extension. If no extension is found, returns "bin".
      • getProviderInfo

        public java.lang.String getProviderInfo()
        Return a valid HTML string for information. May be anything.
        Specified by:
        getProviderInfo in interface WikiProvider
        Returns:
        A string describing the provider.
      • getAttachmentData

        public java.io.InputStream getAttachmentData​(Attachment att)
                                              throws java.io.IOException,
                                                     ProviderException
        Get attachment data.
        Specified by:
        getAttachmentData in interface AttachmentProvider
        Parameters:
        att - The attachment
        Returns:
        An InputStream which you contains the raw data of the object. It's your responsibility to close it.
        Throws:
        java.io.IOException - If the attachment cannot be opened
        ProviderException - If the attachment cannot be found
      • findAttachments

        public java.util.Collection<AttachmentfindAttachments​(QueryItem[] query)
        Finds attachments based on the query.
        Specified by:
        findAttachments in interface AttachmentProvider
        Parameters:
        query - An array of QueryItem objects to search for
        Returns:
        A Collection of Attachment objects. May be empty, but never null.
      • listAllChanged

        public java.util.List<AttachmentlistAllChanged​(java.util.Date timestamp)
                                                  throws ProviderException
        Lists changed attachments since given date. Can also be used to fetch a list of all pages.

        This is different from WikiPageProvider, where you basically get a list of all pages, then sort them locally. However, since some providers can be more efficient in locating recently changed files (like any database) than our non-optimized Java code, it makes more sense to fetch the whole list this way.

        To get all files, call this with Date(0L);

        Specified by:
        listAllChanged in interface AttachmentProvider
        Parameters:
        timestamp - List all files from this date onward.
        Returns:
        A List of Attachment objects, in most-recently-changed first order.
        Throws:
        ProviderException - If something goes wrong.
      • getAttachmentInfo

        public Attachment getAttachmentInfo​(Page page,
                                            java.lang.String name,
                                            int version)
                                     throws ProviderException
        Returns info about an attachment.
        Specified by:
        getAttachmentInfo in interface AttachmentProvider
        Parameters:
        page - The parent page
        name - The name of the attachment
        version - The version of the attachment (it's okay to use WikiPage.LATEST_VERSION to find the latest one)
        Returns:
        An attachment object
        Throws:
        ProviderException - If the attachment cannot be found or some other error occurs.
      • deleteVersion

        public void deleteVersion​(Attachment att)
                           throws ProviderException
        Removes a specific version from the repository. The implementations should really do no more security checks, since that is the domain of the AttachmentManager. Just delete it as efficiently as you can.
        Specified by:
        deleteVersion in interface AttachmentProvider
        Parameters:
        att - Attachment to be removed. The version field is checked, and thus only that version is removed.
        Throws:
        ProviderException - If the attachment cannot be removed for some reason.
      • deleteAttachment

        public void deleteAttachment​(Attachment att)
                              throws ProviderException
        Removes an entire page from the repository. The implementations should really do no more security checks, since that is the domain of the AttachmentManager. Just delete it as efficiently as you can. You should also delete any auxiliary files and directories that belong to this attachment, IF they were created by this provider.
        Specified by:
        deleteAttachment in interface AttachmentProvider
        Parameters:
        att - Attachment to delete.
        Throws:
        ProviderException - If the page could not be removed for some reason.
      • moveAttachmentsForPage

        public void moveAttachmentsForPage​(java.lang.String oldParent,
                                           java.lang.String newParent)
                                    throws ProviderException
        Move all the attachments for a given page so that they are attached to a new page.
        Specified by:
        moveAttachmentsForPage in interface AttachmentProvider
        Parameters:
        oldParent - Name of the page we are to move the attachments from.
        newParent - Name of the page we are to move the attachments to.
        Throws:
        ProviderException - If the attachments could not be moved for some reason.