Class Attachment

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

See Also:
  • Field Details

  • Constructor Details

    • Attachment

      public Attachment()
    • Attachment

      public Attachment(@NonNull String fileName, @NonNull String mediaType, long fileSize, String versionComment, boolean minorEdit)
    • Attachment

      public Attachment(@NonNull String fileName, @NonNull String mediaType, long fileSize, String versionComment)
      Constructs a new Attachment.
  • Method Details

    • 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 interface SearchableAttachment
      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. Use getMediaType() instead
      Description 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 interface SearchableAttachment
      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. Use setMediaType(java.lang.String) instead
    • getContainer

      public @Nullable ContentEntityObject getContainer()
      Specified by:
      getContainer in interface Contained<ContentEntityObject>
      Returns:
      the owner of this content object. Can be null.
    • setContainer

      public void setContainer(ContentEntityObject content)
    • getComment

      @Deprecated public String getComment()
      Deprecated.
      Description copied from interface: SearchableAttachment
      Return any comment associated with this attachment
      Specified by:
      getComment in interface SearchableAttachment
    • 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 interface SearchableAttachment
    • getNiceType

      public String getNiceType()
      Specified by:
      getNiceType in interface SearchableAttachment
      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 interface ContentTypeAware
      Specified by:
      getType in class ContentEntityObject
      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 interface Addressable
      Overrides:
      getDisplayTitle in class ContentEntityObject
      Returns:
      the display title
    • getUrlPath

      public @Nullable String getUrlPath()
      Specified by:
      getUrlPath in interface Addressable
      Specified by:
      getUrlPath in class ContentEntityObject
    • 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 interface Searchable
      Overrides:
      getSearchableDependants in class ContentEntityObject
    • 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 interface Searchable
      Overrides:
      isIndexable in class SpaceContentEntityObject
    • getDownloadPath

      public String getDownloadPath()
      Specified by:
      getDownloadPath in interface SearchableAttachment
    • 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
      Description copied from interface: SearchableAttachment
      Return the contents of the attachment as an InputStream
      Specified by:
      getContentsAsStream in interface SearchableAttachment
      Returns:
      an InputStream set at the start of the attachment's contents.
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class ContentEntityObject
    • 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 class SpaceContentEntityObject
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ContentEntityObject
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class SpaceContentEntityObject
    • 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 null
      fileExtension - 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 interface Spaced
      Overrides:
      getSpace in class SpaceContentEntityObject
      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 interface HasLinkWikiMarkup
      Returns:
      the wiki markup used to link to this content
    • getImageDetailsDTO

      protected Collection getImageDetailsDTO()
      accessor methods provided for hibernate proxy use only. use ImageDetailsManager.getImageDetails(Attachment attachment)
    • setImageDetailsDTO

      protected void setImageDetailsDTO(Set imageDetailDTOs)
    • clone

      public Object clone()
      Overrides:
      clone in class ContentEntityObject
    • copy

      public Attachment copy()
    • getVersionChildPolicy

      public VersionChildOwnerPolicy getVersionChildPolicy(ContentType contentType)
      Description copied from interface: Versioned
      Returns the right VersionChildOwnerPolicy depending on the passed contentType. By default, VersionChildOwnerPolicy.currentVersion is returned

      Right now, this is only enforced for children with content type Attachment or Comment

      Specified by:
      getVersionChildPolicy in interface Versioned
      Overrides:
      getVersionChildPolicy in class AbstractVersionedEntityObject
    • getContentTypeObject

      public ContentType getContentTypeObject()
      Specified by:
      getContentTypeObject in interface ContentConvertible
      Returns:
      the api ContentType that this ContentConvertible converts to
    • getContentId

      public ContentId getContentId()
      Description copied from class: ContentEntityObject
      Returns the ContentId for this entity object, if it implements ContentConvertible.

      Subclasses implementing ContentConvertible must override this method.

      Specified by:
      getContentId in interface ContentConvertible
      Overrides:
      getContentId in class ContentEntityObject
      Returns:
      the ContentId representation of this object's id
    • shouldConvertToContent

      public boolean shouldConvertToContent()
      Specified by:
      shouldConvertToContent in interface ContentConvertible
      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 1

      NOTE: it won't copy content history

      Returns:
      a copy instance
      Since:
      5.10