Package com.atlassian.confluence.pages
Class Attachment
- java.lang.Object
-
- com.atlassian.core.bean.EntityObject
-
- All Implemented Interfaces:
Searchable
,Content
,Addressable
,ContentTypeAware
,HasLinkWikiMarkup
,Versioned
,RelatableEntity
,EditableLabelable
,Labelable
,Contained<ContentEntityObject>
,ContentConvertible
,SearchableAttachment
,Spaced
,Serializable
,Cloneable
,Comparable<ContentEntityObject>
public class Attachment extends SpaceContentEntityObject implements SearchableAttachment, Addressable, HasLinkWikiMarkup, ContentConvertible, Contained<ContentEntityObject>
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Attachment.Type
An enum of basic Attachment types with a text description of each type.
-
Field Summary
Fields Modifier and Type Field Description static String
API_REVISION
static String
API_REVISION_V2
static String
CONTENT_TYPE
static String
DOWNLOAD_PATH_BASE
The download path for an attachment is composed with this base, seegetDownloadPathWithoutEncoding()
for an example.static String
PROFILE_PICTURE_COMMENT
static String
PROP_FILE_STORE_ID
static String
PROP_FILESIZE
static String
PROP_HIDDEN
static String
PROP_MEDIA_TYPE
static String
PROP_MINOR_EDIT
-
Fields inherited from class com.atlassian.confluence.core.ContentEntityObject
COLLABORATIVE_EDITING_UUID, CONFLUENCE_RECOVERY, CONFLUENCE_RECOVERY_WITH_EXTERNAL_CHANGE, CONTENT_RESTORED_SYNC_REV_SOURCE, CREATED, CURRENT, DELETED, DRAFT, DUMMY_SYNC_REV, LIMITED_MODE_SYNC_REV_SOURCE, MODIFIED, SHARE_ID, SYNC_REV, SYNC_REV_SOURCE, SYNCHRONY_ACK_SYNC_REV_SOURCE, SYNCHRONY_RECOVERY, SYNCHRONY_RECOVERY_WITH_EXTERNAL_CHANGE, SYNCHRONY_SYNC_REV_SOURCE
-
Fields inherited from class com.atlassian.confluence.core.AbstractVersionedEntityObject
INITIAL_VERSION
-
-
Constructor Summary
Constructors Constructor Description Attachment()
Attachment(@NonNull String fileName, @NonNull String mediaType, long fileSize, String versionComment)
Constructs a new Attachment.Attachment(@NonNull String fileName, @NonNull String mediaType, long fileSize, String versionComment, boolean minorEdit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Object
clone()
Attachment
copy()
Attachment
copyLatestVersion()
Will copy all detail information of an attachment including : - Content Properties - File Name - File Size - Content Type - And set version is 1boolean
equals(Object o)
String
getComment()
Deprecated.Since 5.7.@Nullable ContentEntityObject
getContainer()
ContentId
getContentId()
Returns theContentId
for this entity object, if it implementsContentConvertible
.InputStream
getContentsAsStream()
Deprecated.since 5.5.@NonNull String
getContentType()
Deprecated.Since 5.7.ContentType
getContentTypeObject()
static String
getDescriptionForMimeType(String mimeType, String fileExtension)
String
getDisplayTitle()
Returns the display title.String
getDownloadPath()
String
getDownloadPath(String attachmentPath, boolean addVersionInfo)
Returns the download path of the attachment for a given attachmentPath prefix.String
getDownloadPathWithoutEncoding()
String
getDownloadPathWithoutVersion()
Returns the download path without any version info.String
getDownloadPathWithoutVersionOrApiRevision()
Returns the download path without any version info or API revision.String
getExportPath()
String
getExportPathForThumbnail()
String
getFileExtension()
Returns the file extension of the attachment.@NonNull String
getFileName()
Gets the filename of this attachment.long
getFileSize()
String
getFileStoreId()
protected Collection
getImageDetailsDTO()
accessor methods provided for hibernate proxy use only.String
getLinkWikiMarkup()
@NonNull String
getMediaType()
String
getNameForComparison()
Subclasses should implement this method, giving a String back so that the content can be alphabetically sorted in a mixed-type list of content-entities.String
getNiceFileSize()
String
getNiceType()
Collection<Searchable>
getSearchableDependants()
When we un-index something (say, a page), we also need to un-index everything contained within that page (comments, attachments), because presumably they're all about to go away.Space
getSpace()
String
getType()
An easy name for the type of this content: makes it easy for things like the #contentLink macro to work out what to draw.@Nullable String
getUrlPath()
VersionChildOwnerPolicy
getVersionChildPolicy(ContentType contentType)
Returns the rightVersionChildOwnerPolicy
depending on the passed contentType.int
hashCode()
boolean
isHidden()
Indicates whether this attachment is supposed to be strictly hidden from displaying and searching Hidden attachment is not indexable Hidden attachment manipulation will not trigger external notification eventsboolean
isIndexable()
Only the current version of a non-hidden attachment is indexable (until we can deal with old objects in search results) We also don't want to index attachments associated with drafts or global descriptions or hidden attachmentsboolean
isMinorEdit()
Indicates whether this attachment is supposed to be hidden under normal circumstances.boolean
isUserProfilePicture()
Determines whether the Attachment is a user's profile picturevoid
setContainer(ContentEntityObject content)
void
setContentType(@NonNull String contentType)
Deprecated.Since 5.7.void
setFileName(@NonNull String fileName)
void
setFileSize(long fileSize)
void
setFileStoreId(String fileStoreId)
void
setHidden(boolean hidden)
protected void
setImageDetailsDTO(Set imageDetailDTOs)
void
setMediaType(@NonNull String mediaType)
void
setMinorEdit(boolean minorEdit)
boolean
shouldConvertToContent()
String
toString()
-
Methods inherited from class com.atlassian.confluence.core.SpaceContentEntityObject
convertToHistoricalVersion, getSpaceKey, isInSpace, setSpace
-
Methods inherited from class com.atlassian.confluence.core.ContentEntityObject
addAttachment, addComment, addCustomContent, addOutgoingLink, addPermission, applyChildVersioningPolicy, applyChildVersioningPolicy, compareTo, ensureAttachmentBelongsToContent, getAttachmentManager, getAttachmentNamed, getAttachments, getAttachmentsUrlPath, getAttachmentUrlPath, getBodyAsString, getBodyAsStringWithoutMarkup, getBodyContent, getBodyContent, getBodyContents, getCollaborativeEditingUuid, getComments, getContainerContent, getContentPermission, getContentPermissionSet, getContentStatus, getContentStatusObject, getCustomContent, getDefaultBodyType, getEntity, getExcerpt, getIdAsString, getLatestVersionId, getLatestVersionsOfAttachments, getLowerTitle, getOriginalVersionId, getOutgoingLinks, getPermissions, getProperties, getRenderedVersionComment, getSelector, getShareId, getSynchronyRevision, getSynchronyRevisionSource, getTitle, getTrashDate, getTypeEnum, getVersionComment, hasContentPermissions, hasPermissions, isCurrent, isDeleted, isDraft, isUnpublished, isVersionCommentAvailable, removeAttachment, removeComment, removeContentPermissionSet, removeCustomContent, removeOutgoingLink, replaceContentProperties, restore, restoreDependents, setAttachments, setBodyAsString, setBodyContent, setBodyContents, setCollaborativeEditingUuid, setComments, setContainerContent, setContentPropertiesFrom, setContentStatus, setOriginalVersion, setOriginalVersionId, setOutgoingLinks, setShareId, setSynchronyRevision, setSynchronyRevisionSource, setTitle, setVersionComment, sharedAccessAllowed, sharedAccessAllowed, toPageContext, trash, trash, trashDependents, wasCreatedBy
-
Methods inherited from class com.atlassian.confluence.core.AbstractLabelableEntityObject
addLabelling, getGlobalLabels, getLabelCount, getLabellings, getLabels, getLabelsForDisplay, getPersonalLabels, getTeamLabels, getVisibleLabels, isFavourite, removeLabelling, setLabellings
-
Methods inherited from class com.atlassian.confluence.core.AbstractVersionedEntityObject
getConfluenceRevision, getLatestVersion, getVersion, isLatestVersion, isNew, setVersion
-
Methods inherited from class com.atlassian.confluence.core.ConfluenceEntityObject
getCreator, getCreatorName, getLastModifier, getLastModifierName, getRealClass, isPersistent, setCreator, setCreatorName, setLastModifier, setLastModifierName
-
Methods inherited from class com.atlassian.core.bean.EntityObject
getCreationDate, getCurrentDate, getId, getLastModificationDate, setClock, setCreationDate, setId, setLastModificationDate
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.core.Addressable
getId
-
Methods inherited from interface com.atlassian.confluence.pages.ContentConvertible
getSelector
-
Methods inherited from interface com.atlassian.confluence.labels.EditableLabelable
getId, isPersistent
-
Methods inherited from interface com.atlassian.bonnie.Searchable
getId
-
-
-
-
Field Detail
-
PROP_MEDIA_TYPE
public static final String PROP_MEDIA_TYPE
- See Also:
- Constant Field Values
-
PROP_FILESIZE
public static final String PROP_FILESIZE
- See Also:
- Constant Field Values
-
PROP_MINOR_EDIT
public static final String PROP_MINOR_EDIT
- See Also:
- Constant Field Values
-
PROP_HIDDEN
public static final String PROP_HIDDEN
- See Also:
- Constant Field Values
-
PROP_FILE_STORE_ID
public static final String PROP_FILE_STORE_ID
- See Also:
- Constant Field Values
-
CONTENT_TYPE
public static final String CONTENT_TYPE
- See Also:
- Constant Field Values
-
PROFILE_PICTURE_COMMENT
public static final String PROFILE_PICTURE_COMMENT
- See Also:
- Constant Field Values
-
API_REVISION
public static final String API_REVISION
- See Also:
- Constant Field Values
-
API_REVISION_V2
public static final String API_REVISION_V2
- See Also:
- Constant Field Values
-
DOWNLOAD_PATH_BASE
public static final String DOWNLOAD_PATH_BASE
The download path for an attachment is composed with this base, seegetDownloadPathWithoutEncoding()
for an example.
-
-
Method Detail
-
getFileName
public @NonNull String getFileName()
Description copied from interface:SearchableAttachment
Gets the filename of this attachment. If there is no filename, return the empty string. This method should never return null.- Specified by:
getFileName
in interfaceSearchableAttachment
- Returns:
- the filename of this attachment, or the empty string if there is no filename
-
setFileName
public void setFileName(@NonNull String fileName)
-
getMediaType
public @NonNull String getMediaType()
-
setMediaType
public void setMediaType(@NonNull String mediaType)
-
getContentType
@Deprecated public @NonNull String getContentType()
Deprecated.Since 5.7. UsegetMediaType()
insteadDescription copied from interface:SearchableAttachment
Gets the MIME content-type of this attachment. If there is no content-type, return "application/x-unknown". Should never return null.- Specified by:
getContentType
in interfaceSearchableAttachment
- Returns:
- the MIME content-type of the attachment, or "application/x-unknown" if the MIME type is unknown
-
setContentType
@Deprecated public void setContentType(@NonNull String contentType)
Deprecated.Since 5.7. UsesetMediaType(java.lang.String)
instead
-
getContainer
public @Nullable ContentEntityObject getContainer()
- Specified by:
getContainer
in interfaceContained<ContentEntityObject>
- Returns:
- the owner of this content object. Can be null.
-
setContainer
public void setContainer(ContentEntityObject content)
-
getComment
@Deprecated public String getComment()
Deprecated.Since 5.7. UseContentEntityObject.getVersionComment()
insteadDescription copied from interface:SearchableAttachment
Return any comment associated with this attachment- Specified by:
getComment
in interfaceSearchableAttachment
-
isMinorEdit
public boolean isMinorEdit()
Indicates whether this attachment is supposed to be hidden under normal circumstances. At the moment this is only used to avoid sending notifications and to hide them in the activity stream. Future usages should be hiding them by default in the attachment macro output- Returns:
- true, if the attachment is hidden
-
setMinorEdit
public void setMinorEdit(boolean minorEdit)
-
getFileStoreId
public String getFileStoreId()
- Returns:
- FileStore ID of the binary data of this attachment
- Since:
- 5.9
-
setFileStoreId
public void setFileStoreId(String fileStoreId)
- Since:
- 5.9
-
isHidden
public boolean isHidden()
Indicates whether this attachment is supposed to be strictly hidden from displaying and searching Hidden attachment is not indexable Hidden attachment manipulation will not trigger external notification events- Returns:
- true, if the attachment is hidden
-
setHidden
public void setHidden(boolean hidden)
-
getFileSize
public long getFileSize()
- Returns:
- The size (in bytes) of the attachment's raw binary data
-
setFileSize
public void setFileSize(long fileSize)
-
getNiceFileSize
public String getNiceFileSize()
- Specified by:
getNiceFileSize
in interfaceSearchableAttachment
-
getNiceType
public String getNiceType()
- Specified by:
getNiceType
in interfaceSearchableAttachment
- Returns:
- A nice type for this file if possible (eg "PDF" or "Word") - or null if no nice type can be recognised
-
getType
public String getType()
Description copied from class:ContentEntityObject
An easy name for the type of this content: makes it easy for things like the #contentLink macro to work out what to draw.This is a bit of a hack, but it saves heaps of code elsewhere, especially since we tend to get back these objects wrapped in all sorts of Hibernate CGLIB stuff.
- Specified by:
getType
in interfaceContentTypeAware
- Specified by:
getType
in classContentEntityObject
- Returns:
- the content type
-
getDisplayTitle
public String getDisplayTitle()
Description copied from class:ContentEntityObject
Returns the display title. Some entities don't have titles for identification. For example, personal information objects use the user's fullname. Override this method to provide a custom title.- Specified by:
getDisplayTitle
in interfaceAddressable
- Overrides:
getDisplayTitle
in classContentEntityObject
- Returns:
- the display title
-
getUrlPath
public @Nullable String getUrlPath()
- Specified by:
getUrlPath
in interfaceAddressable
- Specified by:
getUrlPath
in classContentEntityObject
-
getSearchableDependants
public Collection<Searchable> getSearchableDependants()
Description copied from interface:Searchable
When we un-index something (say, a page), we also need to un-index everything contained within that page (comments, attachments), because presumably they're all about to go away.- Specified by:
getSearchableDependants
in interfaceSearchable
- Overrides:
getSearchableDependants
in classContentEntityObject
-
isUserProfilePicture
public boolean isUserProfilePicture()
Determines whether the Attachment is a user's profile picture- Returns:
- true if it is attached to a PersonalInformation object and has the correct comment
-
isIndexable
public boolean isIndexable()
Only the current version of a non-hidden attachment is indexable (until we can deal with old objects in search results) We also don't want to index attachments associated with drafts or global descriptions or hidden attachments- Specified by:
isIndexable
in interfaceSearchable
- Overrides:
isIndexable
in classSpaceContentEntityObject
-
getDownloadPath
public String getDownloadPath()
- Specified by:
getDownloadPath
in interfaceSearchableAttachment
-
getDownloadPathWithoutVersion
public String getDownloadPathWithoutVersion()
Returns the download path without any version info.
-
getDownloadPathWithoutVersionOrApiRevision
public String getDownloadPathWithoutVersionOrApiRevision()
Returns the download path without any version info or API revision.- Since:
- 5.10
-
getDownloadPath
public String getDownloadPath(String attachmentPath, boolean addVersionInfo)
Returns the download path of the attachment for a given attachmentPath prefix. It basically appends the filename and some meta info to form the path.
-
getDownloadPathWithoutEncoding
public String getDownloadPathWithoutEncoding()
-
getExportPath
public String getExportPath()
-
getExportPathForThumbnail
public String getExportPathForThumbnail()
-
getContentsAsStream
@Deprecated public InputStream getContentsAsStream() throws IOException
Deprecated.since 5.5. UseAttachmentManager.getAttachmentData(Attachment)
Description copied from interface:SearchableAttachment
Return the contents of the attachment as an InputStream- Specified by:
getContentsAsStream
in interfaceSearchableAttachment
- Returns:
- an InputStream set at the start of the attachment's contents.
- Throws:
IOException
-
toString
public String toString()
- Overrides:
toString
in classContentEntityObject
-
getNameForComparison
public String getNameForComparison()
Description copied from class:ContentEntityObject
Subclasses should implement this method, giving a String back so that the content can be alphabetically sorted in a mixed-type list of content-entities.- Overrides:
getNameForComparison
in classSpaceContentEntityObject
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classContentEntityObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classSpaceContentEntityObject
-
getFileExtension
public String getFileExtension()
Returns the file extension of the attachment. If there is no extension, an empty string is returned.- Returns:
- the file extension of the attachment in lower case
-
getDescriptionForMimeType
public static String getDescriptionForMimeType(String mimeType, String fileExtension)
- Parameters:
mimeType
- the mime type to be described. Should not be nullfileExtension
- the file extension to help with the deriving of the description.- Returns:
- A more displayable description for the supplied mime type. If a blank String is supplied then null will be returned.
-
getSpace
public Space getSpace()
- Specified by:
getSpace
in interfaceSpaced
- Overrides:
getSpace
in classSpaceContentEntityObject
- Returns:
- the space of the owning content if it can be associated with a space (i.e. of type
Spaced
), or null otherwise.
-
getLinkWikiMarkup
public String getLinkWikiMarkup()
- Specified by:
getLinkWikiMarkup
in interfaceHasLinkWikiMarkup
- Returns:
- the wiki markup used to link to this content
-
getImageDetailsDTO
protected Collection getImageDetailsDTO()
accessor methods provided for hibernate proxy use only. useImageDetailsManager
.getImageDetails(Attachment attachment)
-
setImageDetailsDTO
protected void setImageDetailsDTO(Set imageDetailDTOs)
-
clone
public Object clone()
- Overrides:
clone
in classContentEntityObject
-
copy
public Attachment copy()
-
getVersionChildPolicy
public VersionChildOwnerPolicy getVersionChildPolicy(ContentType contentType)
Description copied from interface:Versioned
Returns the rightVersionChildOwnerPolicy
depending on the passed contentType. By default,VersionChildOwnerPolicy.currentVersion
is returnedRight now, this is only enforced for children with content type Attachment or Comment
- Specified by:
getVersionChildPolicy
in interfaceVersioned
- Overrides:
getVersionChildPolicy
in classAbstractVersionedEntityObject
-
getContentTypeObject
public ContentType getContentTypeObject()
- Specified by:
getContentTypeObject
in interfaceContentConvertible
- Returns:
- the api ContentType that this ContentConvertible converts to
-
getContentId
public ContentId getContentId()
Description copied from class:ContentEntityObject
Returns theContentId
for this entity object, if it implementsContentConvertible
.Subclasses implementing ContentConvertible must override this method.
- Specified by:
getContentId
in interfaceContentConvertible
- Overrides:
getContentId
in classContentEntityObject
- Returns:
- the ContentId representation of this object's id
-
shouldConvertToContent
public boolean shouldConvertToContent()
- Specified by:
shouldConvertToContent
in interfaceContentConvertible
- Returns:
- true if the implementer wants to be part of the core API (default value), false otherwise
-
copyLatestVersion
public Attachment copyLatestVersion()
Will copy all detail information of an attachment including : - Content Properties - File Name - File Size - Content Type - And set version is 1NOTE: it won't copy content history
- Returns:
- a copy instance
- Since:
- 5.10
-
-