Package com.xpn.xwiki.doc
Class XWikiAttachment
- java.lang.Object
-
- com.xpn.xwiki.doc.XWikiAttachment
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
XWikiAttachment.AttachmentContainer
-
Constructor Summary
Constructors Constructor Description XWikiAttachment()
XWikiAttachment(XWikiDocument doc, String filename)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.XWikiAttachment
clone()
XWikiAttachment
clone(String name, XWikiContext context)
Clone the attachment and its history to a new name, and attach it to a new document.boolean
contentExists(XWikiContext xcontext)
boolean
equalsData(XWikiAttachment otherAttachment, XWikiContext xcontext)
void
fromXML(String source)
void
fromXML(org.dom4j.Element docel)
void
fromXML(org.xwiki.filter.input.InputSource source)
org.suigeneris.jrcs.rcs.Archive
getArchive()
Deprecated.since 2.6M1 please do not use this, it is bound to a jrcs based implementation.String
getArchiveStore()
XWikiAttachmentArchive
getAttachment_archive()
XWikiAttachmentContent
getAttachment_content()
XWikiAttachmentArchive
getAttachmentArchive(XWikiContext xcontext)
XWikiAttachmentContent
getAttachmentContent(XWikiContext xcontext)
XWikiAttachment
getAttachmentRevision(String rev, XWikiContext context)
String
getAuthor()
Deprecated.since 6.4M1 usegetAuthorReference()
insteadDocumentReference
getAuthorReference()
String
getCharset()
String
getComment()
byte[]
getContent(XWikiContext xcontext)
Deprecated.usegetContentInputStream(XWikiContext)
insteadInputStream
getContentInputStream(XWikiContext xcontext)
Retrieve the content of this attachment as an input stream.long
getContentLongSize(XWikiContext context)
int
getContentSize(XWikiContext context)
Deprecated.since 9.0RC1, usegetContentLongSize(XWikiContext)
insteadString
getContentStore()
Date
getDate()
XWikiDocument
getDoc()
long
getDocId()
String
getFilename()
int
getFilesize()
Deprecated.since 9.0RC1, usegetLongSize()
insteadlong
getId()
long
getLongSize()
String
getMimeType()
Return the stored media type.String
getMimeType(XWikiContext xcontext)
Return the stored media type.String
getNextVersion()
org.suigeneris.jrcs.rcs.Version
getRCSVersion()
AttachmentReference
getReference()
String
getVersion()
List<org.suigeneris.jrcs.rcs.Version>
getVersionList()
Get the list of all versions up to the current.org.suigeneris.jrcs.rcs.Version[]
getVersions()
void
incrementVersion()
boolean
isArchiveStoreSet()
boolean
isContentDirty()
boolean
isContentStoreSet()
boolean
isImage(XWikiContext context)
boolean
isMetaDataDirty()
XWikiAttachmentArchive
loadArchive(XWikiContext xcontext)
void
loadAttachmentContent(XWikiContext xcontext)
void
loadContent(XWikiContext xcontext)
Deprecated.since 9.11RC1, useloadAttachmentContent(XWikiContext)
insteadvoid
merge(XWikiAttachment previousAttachment, XWikiAttachment nextAttachment, MergeConfiguration configuration, XWikiContext xcontext, MergeResult mergeResult)
void
resetMimeType(XWikiContext xcontext)
Extract the mime type from the file name and content and remember it to be stored.void
setArchive(String data)
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.void
setArchiveStore(String archiveStore)
void
setAttachment_archive(XWikiAttachmentArchive attachment_archive)
void
setAttachment_content(XWikiAttachmentContent attachment_content)
void
setAttachmentContainer(XWikiAttachment.AttachmentContainer container)
void
setAuthor(String author)
Deprecated.since 6.4M1 usesetAuthorReference(org.xwiki.model.reference.DocumentReference)
insteadvoid
setAuthorReference(DocumentReference authorReference)
void
setCharset(String charset)
void
setComment(String comment)
void
setContent(byte[] data)
Deprecated.usesetContent(java.io.InputStream, int)
insteadvoid
setContent(InputStream is)
Set the content of the attachment from an InputStream.void
setContent(InputStream is, int length)
Set the content of an attachment from an InputStream.void
setContentStore(String contentStore)
void
setDate(Date date)
void
setDoc(XWikiDocument doc)
void
setDoc(XWikiDocument doc, boolean updateDirty)
void
setDocId(long id)
void
setFilename(String filename)
void
setFilesize(int filesize)
Deprecated.since 9.0RC1, usesetLongSize(long)
insteadvoid
setId(long id)
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.void
setMetaDataDirty(boolean metaDataDirty)
void
setMimeType(String mimeType)
void
setRCSVersion(org.suigeneris.jrcs.rcs.Version version)
void
setVersion(String version)
String
toString()
String
toStringXML(boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context)
Retrieve an attachment as an XML string.String
toXML()
Retrieve an attachment as an XML string.org.dom4j.Element
toXML(boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context)
Retrieve XML representation of attachment's metadata into anElement
.void
toXML(com.xpn.xwiki.internal.xml.XMLWriter wr, boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context)
Write an XML representation of the attachment into anXMLWriter
org.dom4j.Element
toXML(XWikiContext context)
Retrieve XML representation of attachment's metadata into anElement
.void
toXML(org.xwiki.filter.output.OutputTarget out, boolean bWithAttachmentContent, boolean bWithVersions, boolean format, XWikiContext context)
Write an XML representation of the attachment into anXMLWriter
void
toXML(org.xwiki.filter.output.OutputTarget out, boolean bWithAttachmentContent, boolean bWithVersions, boolean format, String encoding)
Write an XML representation of the attachment into anXMLWriter
void
updateContentArchive(XWikiContext context)
-
-
-
Constructor Detail
-
XWikiAttachment
public XWikiAttachment(XWikiDocument doc, String filename)
-
XWikiAttachment
public XWikiAttachment()
-
-
Method Detail
-
getReference
public AttachmentReference getReference()
-
getId
public long getId()
-
setDocId
public void setDocId(long id)
-
getDocId
public long getDocId()
-
setId
public void setId(long id)
-
clone
public XWikiAttachment clone()
-
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 clonecontext
- the current context- Returns:
- the clone attachment with its updated history
- Throws:
XWikiException
- in case of error when accessing the attachments contentIOException
- in case of error when writing the attachments content- Since:
- 14.2RC1
-
getFilesize
@Deprecated public int getFilesize()
Deprecated.since 9.0RC1, usegetLongSize()
instead- Returns:
- the number of bytes in this attachment content
-
setFilesize
@Deprecated public void setFilesize(int filesize)
Deprecated.since 9.0RC1, usesetLongSize(long)
insteadSet 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
-
getContentSize
@Deprecated public int getContentSize(XWikiContext context) throws XWikiException
Deprecated.since 9.0RC1, usegetContentLongSize(XWikiContext)
instead- 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:
- 2.3M2
-
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)
-
getAuthorReference
public DocumentReference getAuthorReference()
- Since:
- 6.4M1
-
setAuthorReference
public void setAuthorReference(DocumentReference authorReference)
- Since:
- 6.4M1
-
getAuthor
@Deprecated public String getAuthor()
Deprecated.since 6.4M1 usegetAuthorReference()
insteadNote that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument.
-
setAuthor
@Deprecated public void setAuthor(String author)
Deprecated.since 6.4M1 usesetAuthorReference(org.xwiki.model.reference.DocumentReference)
insteadNote that this method cannot be removed for now since it's used by Hibernate for loading 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)
-
getDoc
public XWikiDocument getDoc()
-
setDoc
public void setDoc(XWikiDocument doc)
-
setDoc
public void setDoc(XWikiDocument doc, boolean updateDirty)
- Parameters:
doc
- the document to associate to the attachmentupdateDirty
- 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 prefertoXML(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 includedcontext
- current XWikiContext- Returns:
- a string containing an XML representation of the attachment
- Throws:
XWikiException
- when an error occurs during wiki operations
-
toXML
public String toXML() throws XWikiException
Retrieve an attachment as an XML string. You should prefertoXML(OutputTarget, boolean, boolean, boolean, String)
to avoid memory loads when appropriate.- Returns:
- a string containing an XML representation of the attachment
- Throws:
XWikiException
- when an error occurs during wiki operations- Since:
- 9.10RC1
-
toXML
public org.dom4j.Element toXML(XWikiContext context) throws XWikiException
Retrieve XML representation of attachment's metadata into anElement
.- 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 anXMLWriter
- Parameters:
wr
- the XMLWriter to write tobWithAttachmentContent
- if true, binary content of the attachment is included (base64 encoded)bWithVersions
- if true, all archive version is also includedcontext
- current XWikiContext- Throws:
IOException
- when an error occurs during streaming operationXWikiException
- 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 anXMLWriter
- Parameters:
out
- the output where to write the XMLbWithAttachmentContent
- if true, binary content of the attachment is included (base64 encoded)bWithVersions
- if true, all archive version is also includedformat
- true if the XML should be formatedcontext
- current XWikiContext- Throws:
IOException
- when an error occurs during streaming operationXWikiException
- 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 anXMLWriter
- Parameters:
out
- the output where to write the XMLbWithAttachmentContent
- if true, binary content of the attachment is included (base64 encoded)bWithVersions
- if true, all archive version is also includedformat
- true if the XML should be formatedencoding
- 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 anElement
. You should prefertoXML(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 includedcontext
- 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(String source) throws XWikiException
- Throws:
XWikiException
-
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
-
fromXML
public void fromXML(org.dom4j.Element docel) throws XWikiException
- Throws:
XWikiException
-
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
-
getAttachmentContent
public XWikiAttachmentContent getAttachmentContent(XWikiContext xcontext) throws XWikiException
- Throws:
XWikiException
- when failing to load the attachment content- Since:
- 12.0RC1
-
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
-
getAttachment_content
public XWikiAttachmentContent getAttachment_content()
-
setAttachment_content
public void setAttachment_content(XWikiAttachmentContent attachment_content)
-
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
-
getAttachmentArchive
public XWikiAttachmentArchive getAttachmentArchive(XWikiContext xcontext) throws XWikiException
- Throws:
XWikiException
- when failing to load the attachment archive- Since:
- 12.0RC1
-
getAttachment_archive
public XWikiAttachmentArchive getAttachment_archive()
-
setAttachment_archive
public void setAttachment_archive(XWikiAttachmentArchive attachment_archive)
-
getContent
@Deprecated public byte[] getContent(XWikiContext xcontext) throws XWikiException
Deprecated.usegetContentInputStream(XWikiContext)
insteadRetrieve the content of this attachment as a byte array.- Parameters:
xcontext
- current XWikiContext- Returns:
- a byte array containing the binary data content of the attachment
- Throws:
XWikiException
- when an error occurs during wiki operation
-
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.
-
setArchive
public void setArchive(String data) throws XWikiException
- Throws:
XWikiException
-
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.usesetContent(java.io.InputStream, int)
insteadSet 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 readlength
- 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
-
loadAttachmentContent
public void loadAttachmentContent(XWikiContext xcontext) throws XWikiException
- Throws:
XWikiException
-
loadContent
@Deprecated public void loadContent(XWikiContext xcontext)
Deprecated.since 9.11RC1, useloadAttachmentContent(XWikiContext)
instead
-
loadArchive
public XWikiAttachmentArchive loadArchive(XWikiContext xcontext)
-
updateContentArchive
public void updateContentArchive(XWikiContext context) throws XWikiException
- Throws:
XWikiException
-
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 usingTika
. 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
- theXWikiContext
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)
-
getAttachmentRevision
public XWikiAttachment getAttachmentRevision(String rev, XWikiContext context) throws XWikiException
- Throws:
XWikiException
-
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
-
equalsData
public boolean equalsData(XWikiAttachment otherAttachment, XWikiContext xcontext) throws XWikiException
- Throws:
XWikiException
-
merge
public void merge(XWikiAttachment previousAttachment, XWikiAttachment nextAttachment, MergeConfiguration configuration, XWikiContext xcontext, MergeResult mergeResult)
-
setAttachmentContainer
public void setAttachmentContainer(XWikiAttachment.AttachmentContainer container)
- Since:
- 10.3
-
-