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>
- Direct Known Subclasses:
ReadOnlyAttachment
public class Attachment
extends SpaceContentEntityObject
implements SearchableAttachment, Addressable, HasLinkWikiMarkup, ContentConvertible, Contained<ContentEntityObject>
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
An enum of basic Attachment types with a text description of each type. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
The download path for an attachment is composed with this base, seegetDownloadPathWithoutEncoding()
for an example.static final String
static final String
static final String
static final String
static final String
static final String
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, DELETED_BY, DELETED_BY_ANON_VALUE, 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
ConstructorDescriptionAttachment
(@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
Modifier and TypeMethodDescriptionclone()
copy()
Will copy all detail information of an attachment including : - Content Properties - File Name - File Size - Content Type - And set version is 1boolean
Deprecated.Since 5.7.@Nullable ContentEntityObject
Returns theContentId
for this entity object, if it implementsContentConvertible
.Deprecated.since 5.5.@NonNull String
Deprecated.Since 5.7.static String
getDescriptionForMimeType
(String mimeType, String fileExtension) Returns the display title.getDownloadPath
(String attachmentPath, boolean addVersionInfo) Returns the download path of the attachment for a given attachmentPath prefix.Returns the download path without any version info.Returns the download path without any version info or API revision.Returns the file extension of the attachment.@NonNull String
Gets the filename of this attachment.long
protected Collection
accessor methods provided for hibernate proxy use only.@NonNull String
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.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.getSpace()
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
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
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
Indicates whether this attachment is supposed to be hidden under normal circumstances.boolean
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
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, 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 Details
-
PROP_MEDIA_TYPE
- See Also:
-
PROP_FILESIZE
- See Also:
-
PROP_MINOR_EDIT
- See Also:
-
PROP_HIDDEN
- See Also:
-
PROP_FILE_STORE_ID
- See Also:
-
CONTENT_TYPE
- See Also:
-
PROFILE_PICTURE_COMMENT
- See Also:
-
API_REVISION
- See Also:
-
API_REVISION_V2
- See Also:
-
DOWNLOAD_PATH_BASE
The download path for an attachment is composed with this base, seegetDownloadPathWithoutEncoding()
for an example.
-
-
Constructor Details
-
Method Details
-
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
-
getMediaType
-
setMediaType
-
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.Since 5.7. UsesetMediaType(java.lang.String)
instead -
getContainer
- Specified by:
getContainer
in interfaceContained<ContentEntityObject>
- Returns:
- the owner of this content object. Can be null.
-
setContainer
-
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
- Returns:
- FileStore ID of the binary data of this attachment
- Since:
- 5.9
-
setFileStoreId
- 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
- Specified by:
getNiceFileSize
in interfaceSearchableAttachment
-
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
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
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
- Specified by:
getUrlPath
in interfaceAddressable
- Specified by:
getUrlPath
in classContentEntityObject
-
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
- Specified by:
getDownloadPath
in interfaceSearchableAttachment
-
getDownloadPathWithoutVersion
Returns the download path without any version info. -
getDownloadPathWithoutVersionOrApiRevision
Returns the download path without any version info or API revision.- Since:
- 5.10
-
getDownloadPath
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
-
getExportPath
-
getExportPathForThumbnail
-
getContentsAsStream
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
- Overrides:
toString
in classContentEntityObject
-
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
- Overrides:
equals
in classContentEntityObject
-
hashCode
public int hashCode()- Overrides:
hashCode
in classSpaceContentEntityObject
-
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
- 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
- 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
- Specified by:
getLinkWikiMarkup
in interfaceHasLinkWikiMarkup
- Returns:
- the wiki markup used to link to this content
-
getImageDetailsDTO
accessor methods provided for hibernate proxy use only. useImageDetailsManager
.getImageDetails(Attachment attachment) -
setImageDetailsDTO
-
clone
- Overrides:
clone
in classContentEntityObject
-
copy
-
getVersionChildPolicy
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
- Specified by:
getContentTypeObject
in interfaceContentConvertible
- Returns:
- the api ContentType that this ContentConvertible converts to
-
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
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
-