Class XWikiAttachment

    • Constructor Detail

      • XWikiAttachment

        public XWikiAttachment()
    • Method Detail

      • getId

        public long getId()
      • setDocId

        public void setDocId​(long id)
      • getDocId

        public long getDocId()
      • setId

        public void setId​(long id)
      • clone

        @Unstable
        public XWikiAttachment clone​(String name,
                                     XWikiContext context)
                              throws XWikiException,
                                     IOException
        Clone the attachment and its history to a new name, and attach it to a new document.
        Parameters:
        name - the name of the attachment after the clone
        context - the current context
        Returns:
        the clone attachment with its updated history
        Throws:
        XWikiException - in case of error when accessing the attachments content
        IOException - in case of error when writing the attachments content
        Since:
        14.2RC1
      • getFilesize

        @Deprecated
        public int getFilesize()
        Deprecated.
        since 9.0RC1, use getLongSize() instead
        Returns:
        the number of bytes in this attachment content
      • setFilesize

        @Deprecated
        public void setFilesize​(int filesize)
        Deprecated.
        since 9.0RC1, use setLongSize(long) instead
        Set cached filesize of the attachment that will be stored as metadata.
        Parameters:
        filesize - the number of bytes in this attachment content
      • getLongSize

        public long getLongSize()
        Returns:
        the real size of the attachment extracted from the content, or the size metadata if the content is not loaded yet. -1 if the size is unknown.
        Since:
        9.0RC1
      • setLongSize

        public void setLongSize​(long size)
        The size is automatically calculated from the attachment content so this method is mostly internal API that should not be used.
        Parameters:
        size - the metadata holding the number of bytes in this attachment content
        Since:
        9.0RC1
      • getContentLongSize

        public long getContentLongSize​(XWikiContext context)
                                throws XWikiException
        Parameters:
        context - current XWikiContext
        Returns:
        the real filesize in byte of the attachment. We cannot trust the metadata that may be publicly changed.
        Throws:
        XWikiException
        Since:
        9.0RC1
      • getFilename

        public String getFilename()
      • setFilename

        public void setFilename​(String filename)
      • setAuthorReference

        public void setAuthorReference​(DocumentReference authorReference)
        Since:
        6.4M1
      • getAuthor

        @Deprecated
        public String getAuthor()
        Deprecated.
        since 6.4M1 use getAuthorReference() instead
        Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument.
      • getVersion

        public String getVersion()
      • setVersion

        public void setVersion​(String version)
      • getNextVersion

        public String getNextVersion()
      • getRCSVersion

        public org.suigeneris.jrcs.rcs.Version getRCSVersion()
      • setRCSVersion

        public void setRCSVersion​(org.suigeneris.jrcs.rcs.Version version)
      • getComment

        public String getComment()
      • setComment

        public void setComment​(String comment)
      • setDoc

        public void setDoc​(XWikiDocument doc,
                           boolean updateDirty)
        Parameters:
        doc - the document to associate to the attachment
        updateDirty - false if the document metadata dirty flag should not be modified
        Since:
        9.10RC1
      • getDate

        public Date getDate()
      • setDate

        public void setDate​(Date date)
      • isContentDirty

        public boolean isContentDirty()
      • incrementVersion

        public void incrementVersion()
      • isMetaDataDirty

        public boolean isMetaDataDirty()
      • setMetaDataDirty

        public void setMetaDataDirty​(boolean metaDataDirty)
      • toStringXML

        public String toStringXML​(boolean bWithAttachmentContent,
                                  boolean bWithVersions,
                                  XWikiContext context)
                           throws XWikiException
        Retrieve an attachment as an XML string. You should prefer toXML(OutputTarget, boolean, boolean, boolean, XWikiContext) to avoid memory loads when appropriate.
        Parameters:
        bWithAttachmentContent - if true, binary content of the attachment is included (base64 encoded)
        bWithVersions - if true, all archived versions are also included
        context - current XWikiContext
        Returns:
        a string containing an XML representation of the attachment
        Throws:
        XWikiException - when an error occurs during wiki operations
      • toXML

        public org.dom4j.Element toXML​(XWikiContext context)
                                throws XWikiException
        Retrieve XML representation of attachment's metadata into an Element.
        Returns:
        a Element containing an XML representation of the attachment without content
        Throws:
        XWikiException - when an error occurs during wiki operations
      • toXML

        public void toXML​(com.xpn.xwiki.internal.xml.XMLWriter wr,
                          boolean bWithAttachmentContent,
                          boolean bWithVersions,
                          XWikiContext context)
                   throws IOException,
                          XWikiException
        Write an XML representation of the attachment into an XMLWriter
        Parameters:
        wr - the XMLWriter to write to
        bWithAttachmentContent - if true, binary content of the attachment is included (base64 encoded)
        bWithVersions - if true, all archive version is also included
        context - current XWikiContext
        Throws:
        IOException - when an error occurs during streaming operation
        XWikiException - when an error occurs during xwiki operation
        Since:
        2.3M2
      • toXML

        public void toXML​(org.xwiki.filter.output.OutputTarget out,
                          boolean bWithAttachmentContent,
                          boolean bWithVersions,
                          boolean format,
                          XWikiContext context)
                   throws IOException,
                          XWikiException
        Write an XML representation of the attachment into an XMLWriter
        Parameters:
        out - the output where to write the XML
        bWithAttachmentContent - if true, binary content of the attachment is included (base64 encoded)
        bWithVersions - if true, all archive version is also included
        format - true if the XML should be formated
        context - current XWikiContext
        Throws:
        IOException - when an error occurs during streaming operation
        XWikiException - when an error occurs during xwiki operation
        Since:
        9.0RC1
      • toXML

        public void toXML​(org.xwiki.filter.output.OutputTarget out,
                          boolean bWithAttachmentContent,
                          boolean bWithVersions,
                          boolean format,
                          String encoding)
                   throws XWikiException
        Write an XML representation of the attachment into an XMLWriter
        Parameters:
        out - the output where to write the XML
        bWithAttachmentContent - if true, binary content of the attachment is included (base64 encoded)
        bWithVersions - if true, all archive version is also included
        format - true if the XML should be formated
        encoding - the encoding to use when serializing XML
        Throws:
        XWikiException - when an error occurs during xwiki operation
        Since:
        9.10RC1
      • toXML

        public org.dom4j.Element toXML​(boolean bWithAttachmentContent,
                                       boolean bWithVersions,
                                       XWikiContext context)
                                throws XWikiException
        Retrieve XML representation of attachment's metadata into an Element. You should prefer toXML(com.xpn.xwiki.internal.xml.XMLWriter, boolean, boolean, com.xpn.xwiki.XWikiContext) to avoid memory loads when appropriate.
        Parameters:
        bWithAttachmentContent - if true, binary content of the attachment is included (base64 encoded)
        bWithVersions - if true, all archived versions are also included
        context - current XWikiContext
        Returns:
        an Element containing an XML representation of the attachment
        Throws:
        XWikiException - when an error occurs during wiki operations
        Since:
        2.3M2
      • fromXML

        public void fromXML​(org.xwiki.filter.input.InputSource source)
                     throws XWikiException
        Parameters:
        source - the XML source to parse
        Throws:
        XWikiException - when failing to parse the XML
        Since:
        9.0RC1
      • getContentStore

        public String getContentStore()
        Returns:
        the type of the store used for the content
        Since:
        9.10RC1
      • isContentStoreSet

        public boolean isContentStoreSet()
        Returns:
        true if the content store of this attachment has been explicitly set
        Since:
        9.10RC1
      • setContentStore

        public void setContentStore​(String contentStore)
        Parameters:
        contentStore - the type of the store used for the content
        Since:
        9.10RC1
      • contentExists

        public boolean contentExists​(XWikiContext xcontext)
                              throws XWikiException
        Parameters:
        xcontext - the XWiki context
        Returns:
        true of the content of this attachment still exist in the store
        Throws:
        XWikiException
        Since:
        13.8RC1, 13.4.4, 12.10.10
      • getArchiveStore

        public String getArchiveStore()
        Returns:
        the type of the store used for the archive
        Since:
        9.10RC1
      • isArchiveStoreSet

        public boolean isArchiveStoreSet()
        Returns:
        true if the archive store of this attachment has been explicitly set
        Since:
        9.10RC1
      • setArchiveStore

        public void setArchiveStore​(String archiveStore)
        Parameters:
        archiveStore - the type of the store used for the archive
        Since:
        9.10RC1
      • getContentInputStream

        public InputStream getContentInputStream​(XWikiContext xcontext)
                                          throws XWikiException
        Retrieve the content of this attachment as an input stream.
        Parameters:
        xcontext - current XWikiContext
        Returns:
        an InputStream to consume for receiving the content of this attachment
        Throws:
        XWikiException - when an error occurs during wiki operation
        Since:
        2.3M2
      • getArchive

        @Deprecated
        public org.suigeneris.jrcs.rcs.Archive getArchive()
        Deprecated.
        since 2.6M1 please do not use this, it is bound to a jrcs based implementation.
      • setArchive

        @Deprecated
        public void setArchive​(org.suigeneris.jrcs.rcs.Archive archive)
        Deprecated.
        since 2.6M1 please do not use this, it is bound to a jrcs based implementation.
      • getVersions

        public org.suigeneris.jrcs.rcs.Version[] getVersions()
      • getVersionList

        public List<org.suigeneris.jrcs.rcs.Version> getVersionList()
                                                             throws XWikiException
        Get the list of all versions up to the current. We assume versions go from 1.1 to the current one This allows not to read the full archive file.
        Returns:
        a list of Version from 1.1 to the current version.
        Throws:
        XWikiException - never happens.
      • setContent

        @Deprecated
        public void setContent​(byte[] data)
        Deprecated.
        Set the content of an attachment from a byte array.
        Parameters:
        data - a byte array with the binary content of the attachment
      • setContent

        public void setContent​(InputStream is,
                               int length)
                        throws IOException
        Set the content of an attachment from an InputStream.
        Parameters:
        is - the input stream that will be read
        length - the length in byte to read
        Throws:
        IOException - when an error occurs during streaming operation
        Since:
        2.3M2
      • setContent

        public void setContent​(InputStream is)
                        throws IOException
        Set the content of the attachment from an InputStream.
        Parameters:
        is - the input stream that will be read
        Throws:
        IOException - when an error occurs during streaming operation
        Since:
        2.6M1
      • getMimeType

        public String getMimeType​(XWikiContext xcontext)
        Return the stored media type. If none is stored try to detects the media type of this attachment's content using Tika. We first try to determine the media type based on the file name extension and if the extension is unknown we try to determine the media type by reading the first bytes of the attachment content.
        Parameters:
        xcontext - the XWiki context
        Returns:
        the media type of this attachment's content
      • getMimeType

        public String getMimeType()
        Return the stored media type.
        Returns:
        the media type of this attachment's content
        Since:
        7.1M1
      • setMimeType

        public void setMimeType​(String mimeType)
        Parameters:
        mimeType - the explicit mime type of the file
        Since:
        7.1M1
      • resetMimeType

        public void resetMimeType​(XWikiContext xcontext)
        Extract the mime type from the file name and content and remember it to be stored.
        Parameters:
        xcontext - the XWikiContext use to load the content if it's not already loaded
        Since:
        7.1M1
      • getCharset

        public String getCharset()
        Returns:
        charset the character encoding associated with the attachment content
        Since:
        10.11RC1
      • setCharset

        public void setCharset​(String charset)
        Parameters:
        charset - the character encoding associated with the attachment content
        Since:
        10.11RC1
      • isImage

        public boolean isImage​(XWikiContext context)
      • apply

        public boolean apply​(XWikiAttachment attachment)
        Apply the provided attachment so that the current one contains the same informations and indicate if it was necessary to modify it in any way.
        Parameters:
        attachment - the attachment to apply
        Returns:
        true if the attachment has been modified
        Since:
        5.3M2