com.atlassian.confluence.pages
Class DelegatorAttachmentManager

java.lang.Object
  extended by com.atlassian.confluence.pages.DelegatorAttachmentManager
All Implemented Interfaces:
AttachmentManagerInternal, AttachmentManager, DelegatingAttachmentManager

public class DelegatorAttachmentManager
extends Object
implements AttachmentManagerInternal, DelegatingAttachmentManager

This class delegates attachment manager requests to the appropriate attachment manager implementation based on certain Confluence configuration options


Constructor Summary
DelegatorAttachmentManager()
           
 
Method Summary
 void copyAttachment(Attachment attachment, ContentEntityObject destinationContent)
          Copy specified attachment to specified destination content.
 void copyAttachments(ContentEntityObject sourceContent, ContentEntityObject destinationContent)
          Copy the latest version of all the attachments on the sourceContent to the destinationContent.
 int countLatestVersionsOfAttachments(ContentEntityObject content)
          Returns a count of the number of latest versions of attachments
 List<Attachment> getAllVersions(Attachment attachment)
          Get all versions of an attachment, starting with the current version
 List<Attachment> getAllVersionsOfAttachments(ContentEntityObject content)
          Returns a list of all attachments, old and new.
 Attachment getAttachment(ContentEntityObject content, String attachmentFileName)
          Get the most recent version of an attachment with a given name for a particular page
 Attachment getAttachment(ContentEntityObject content, String attachmentFileName, int version)
          Retrieve a named attachment from a page
 Attachment getAttachment(long id)
           
 AttachmentDao getAttachmentDao()
          Retrieves the AttachmentDao for the AttachmentManager
 InputStream getAttachmentData(Attachment attachment)
          Retrieve the data for attachment
 String getAttachmentDownloadPath(ContentEntityObject content, String attachmentFileName)
          Get the download path for the most recent version of an attachment with the given name for some content
 com.atlassian.fugue.Maybe<Attachment> getAttachmentForDownloadPath(String downloadPath)
          Find an Attachment for the given downloadPath.
 AttachmentManagerInternal getAttachmentManager()
          Return the AttachmentManager implementation that the delegator wraps
 List<Attachment> getAttachments(ContentEntityObject content)
          Returns a list of all attachments, old and new.
 PageResponse<Attachment> getAttachments(ContentEntityObject content, LimitedRequest pageRequest, com.google.common.base.Predicate<? super Attachment> filterPredicate)
          Returns the current attachments under the CEO.
 List<Attachment> getAttachments(List<Long> ids)
          Returns a list of attachments matching the given list of IDs.
 AttachmentDataStorageType getBackingStorageType()
          Returns the currently active storage type.
 AttachmentDao.AttachmentCopier getCopier(AttachmentManager destination)
          Retrieves a AttachmentDao.AttachmentCopier that will allow the attachments from one data store to be copied across to another.
 List<Attachment> getLastAddedVersionsOf(Attachment attachment)
          Retrieves all the last added versions for each user who has added a version of the attachment That is, if a user has added multiple versions, only the latest added version will be added to the list returned.
 List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
          Returns a list of only latest versions of attachments.
 AttachmentDao.AttachmentMigrator getMigrator(AttachmentManager destination)
          Retrieves a AttachmentDao.AttachmentMigrator that will allow the attachments from one data store to be moved across to another.
 List<Attachment> getPreviousVersions(Attachment attachment)
          Get all non-current versions of an attachment, not including the current version.
 Map<Long,Long> getRemappedAttachmentIds()
          Gets a list of remapped attachment IDs.
 void moveAttachment(Attachment attachment, ContentEntityObject newContainer)
          Moves an attachment to a different ContentEntityObject container.
 void moveAttachment(Attachment attachment, String newFileName, ContentEntityObject newName)
           
 void removeAttachmentFromServer(Attachment attachment)
          Removes an Attachment and its data from the server and data store.
 void removeAttachments(List<? extends Attachment> attachments)
          Removes the contents of attachments from the server
 void removeAttachmentVersionFromServer(Attachment attachment)
          Removes the given version of the Attachment and its data from the server and data store.
 void saveAttachment(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
          Saves an Attachment and its data
 void saveAttachments(List<SavableAttachment> savableAttachments)
          Saves multiple attachment and their data
 void setAttachmentData(Attachment attachment, InputStream attachmentData)
          Set the data belonging to attachment This method can be used when there is missing data for an Attachment (e.g.
 void setDatabaseAttachmentManager(AttachmentManagerInternal databaseAttachmentManager)
           
 void setDefaultAttachmentManager(AttachmentManagerInternal defaultAttachmentManager)
           
 void setSettingsManager(SettingsManager settingsManager)
           
 void setWebDavAttachmentManager(AttachmentManagerInternal webDavAttachmentManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatorAttachmentManager

public DelegatorAttachmentManager()
Method Detail

getAttachmentManager

public AttachmentManagerInternal getAttachmentManager()
Description copied from interface: DelegatingAttachmentManager
Return the AttachmentManager implementation that the delegator wraps

Specified by:
getAttachmentManager in interface DelegatingAttachmentManager
Returns:
an AttachmentManager instance

getAttachment

public Attachment getAttachment(long id)
Specified by:
getAttachment in interface AttachmentManager
Returns:
attachment with id

getAttachments

public List<Attachment> getAttachments(List<Long> ids)
Description copied from interface: AttachmentManager
Returns a list of attachments matching the given list of IDs. Returns an empty list if no such attachments exist. In the case where some IDs exist and some don't, only the existing Attachments will be returned.

Specified by:
getAttachments in interface AttachmentManager
Parameters:
ids - list of IDs to retrieve.
Returns:
attachments matching ids in the list

getAttachments

public List<Attachment> getAttachments(ContentEntityObject content)
Description copied from interface: AttachmentManager
Returns a list of all attachments, old and new.

Specified by:
getAttachments in interface AttachmentManager

getAllVersionsOfAttachments

public List<Attachment> getAllVersionsOfAttachments(ContentEntityObject content)
Description copied from interface: AttachmentManager
Returns a list of all attachments, old and new.

Specified by:
getAllVersionsOfAttachments in interface AttachmentManager

getLatestVersionsOfAttachments

public List<Attachment> getLatestVersionsOfAttachments(ContentEntityObject content)
Description copied from interface: AttachmentManager
Returns a list of only latest versions of attachments.

Specified by:
getLatestVersionsOfAttachments in interface AttachmentManager

getAttachments

public PageResponse<Attachment> getAttachments(ContentEntityObject content,
                                               LimitedRequest pageRequest,
                                               com.google.common.base.Predicate<? super Attachment> filterPredicate)
Description copied from interface: AttachmentManagerInternal
Returns the current attachments under the CEO.

Note - only returns the latest versions of the Attachments. The legacy AttachmentManager.getAttachments(ContentEntityObject) method that confusingly returns all versions has been deprecated.

Specified by:
getAttachments in interface AttachmentManagerInternal
Parameters:
content - the content to return attachments for
pageRequest - the pagination requested
filterPredicate - the predicate for filtering found attachments
Returns:
the paginated response of Page entities

countLatestVersionsOfAttachments

public int countLatestVersionsOfAttachments(ContentEntityObject content)
Description copied from interface: AttachmentManager
Returns a count of the number of latest versions of attachments

Specified by:
countLatestVersionsOfAttachments in interface AttachmentManager

getAttachment

public Attachment getAttachment(ContentEntityObject content,
                                String attachmentFileName,
                                int version)
Description copied from interface: AttachmentManager
Retrieve a named attachment from a page

Specified by:
getAttachment in interface AttachmentManager
Parameters:
content - the page the attachment is attached to
attachmentFileName - the filename of the attachment to retrieve
version - the version of the attachment to retrieve. If you provide a version of 0 or less, you'll get the most recent version, but you should probably use #getAttachment(AbstractPage, String) instead for that purpose instead
Returns:
the requested attachment, or null if the requested attachment does not exist.

getAttachment

public Attachment getAttachment(ContentEntityObject content,
                                String attachmentFileName)
Description copied from interface: AttachmentManager
Get the most recent version of an attachment with a given name for a particular page

Specified by:
getAttachment in interface AttachmentManager
Parameters:
content - the page the attachment is attached to
attachmentFileName - the filename of the attachment to be retrieved
Returns:
the appropriate attachment, or null if no such attachment exists

getAttachmentDownloadPath

public String getAttachmentDownloadPath(ContentEntityObject content,
                                        String attachmentFileName)
Description copied from interface: AttachmentManager
Get the download path for the most recent version of an attachment with the given name for some content

Specified by:
getAttachmentDownloadPath in interface AttachmentManager
Parameters:
content - the content the attachment is attached to
attachmentFileName - the filename of the attachment to be retrieved
Returns:
the appropriate attachment download path, or null if no such attachment exists

getAttachmentData

public InputStream getAttachmentData(Attachment attachment)
Description copied from interface: AttachmentManager
Retrieve the data for attachment

Specified by:
getAttachmentData in interface AttachmentManager
Parameters:
attachment - the Attachment the data belongs to
Returns:
InputStream representing the data

removeAttachmentFromServer

public void removeAttachmentFromServer(Attachment attachment)
Description copied from interface: AttachmentManager
Removes an Attachment and its data from the server and data store.

Specified by:
removeAttachmentFromServer in interface AttachmentManager
Parameters:
attachment - the Attachment to remove

removeAttachmentVersionFromServer

public void removeAttachmentVersionFromServer(Attachment attachment)
Description copied from interface: AttachmentManager
Removes the given version of the Attachment and its data from the server and data store.

In case of the given attachment being the latest version, the previous version (if any) gets removed and the given object impersonates the previous version as the latest version.

Specified by:
removeAttachmentVersionFromServer in interface AttachmentManager
Parameters:
attachment - the Attachment to remove

saveAttachment

public void saveAttachment(Attachment attachment,
                           Attachment previousVersion,
                           InputStream attachmentData)
                    throws IOException
Description copied from interface: AttachmentManager
Saves an Attachment and its data

Specified by:
saveAttachment in interface AttachmentManager
Parameters:
attachment - the modified version of the Attachment
previousVersion - the original version of the Attachment (null if new)
attachmentData - an InputStream representing the data of the Attachment
Throws:
IOException

saveAttachments

public void saveAttachments(List<SavableAttachment> savableAttachments)
                     throws IOException
Description copied from interface: AttachmentManager
Saves multiple attachment and their data

Specified by:
saveAttachments in interface AttachmentManager
Parameters:
savableAttachments - the modified version of the Attachment
Throws:
IOException

setAttachmentData

public void setAttachmentData(Attachment attachment,
                              InputStream attachmentData)
                       throws AttachmentDataExistsException
Description copied from interface: AttachmentManager
Set the data belonging to attachment This method can be used when there is missing data for an Attachment (e.g. during imports) and the data needs to be set manually.

Specified by:
setAttachmentData in interface AttachmentManager
Parameters:
attachment - Attachment the data belongs to
attachmentData - the data to be saved
Throws:
AttachmentDataExistsException - if data for attachment already exists

moveAttachment

public void moveAttachment(Attachment attachment,
                           String newFileName,
                           ContentEntityObject newName)
Specified by:
moveAttachment in interface AttachmentManager
Parameters:
attachment - The attachment to be moved
newFileName - New name of the file
newName - The new contentEntiityObject which will be parent to the attachment

moveAttachment

public void moveAttachment(Attachment attachment,
                           ContentEntityObject newContainer)
Description copied from interface: AttachmentManagerInternal
Moves an attachment to a different ContentEntityObject container.

Specified by:
moveAttachment in interface AttachmentManagerInternal
Parameters:
attachment - The attachment to be moved
newContainer - The new ContentEntiityObject which will be parent to the attachment

copyAttachments

public void copyAttachments(ContentEntityObject sourceContent,
                            ContentEntityObject destinationContent)
                     throws IOException
Description copied from interface: AttachmentManager
Copy the latest version of all the attachments on the sourceContent to the destinationContent.

Specified by:
copyAttachments in interface AttachmentManager
Parameters:
sourceContent - the content with attachments to be copied.
destinationContent - the content to copy the attachments to.
Throws:
IOException - if there are problems reading or writing attachment data during the copy.

copyAttachment

public void copyAttachment(Attachment attachment,
                           ContentEntityObject destinationContent)
                    throws IOException
Description copied from interface: AttachmentManager
Copy specified attachment to specified destination content.

Specified by:
copyAttachment in interface AttachmentManager
Parameters:
attachment - the attachment
destinationContent - the destination
Throws:
IOException

getAllVersions

public List<Attachment> getAllVersions(Attachment attachment)
Description copied from interface: AttachmentManager
Get all versions of an attachment, starting with the current version

Specified by:
getAllVersions in interface AttachmentManager

getPreviousVersions

public List<Attachment> getPreviousVersions(Attachment attachment)
Description copied from interface: AttachmentManager
Get all non-current versions of an attachment, not including the current version. (ordered from most recent)

Specified by:
getPreviousVersions in interface AttachmentManager
Parameters:
attachment - the attachment to get all non-current versions for.

getLastAddedVersionsOf

public List<Attachment> getLastAddedVersionsOf(Attachment attachment)
Description copied from interface: AttachmentManager
Retrieves all the last added versions for each user who has added a version of the attachment That is, if a user has added multiple versions, only the latest added version will be added to the list returned. Result will be sorted with the earliest version coming first.

Specified by:
getLastAddedVersionsOf in interface AttachmentManager
Parameters:
attachment - attachment (must be the latest version)
Returns:
the last added versions for each user who has added a version of the attachment

removeAttachments

public void removeAttachments(List<? extends Attachment> attachments)
Description copied from interface: AttachmentManager
Removes the contents of attachments from the server

Specified by:
removeAttachments in interface AttachmentManager
Parameters:
attachments - a List of Attachments
See Also:
AttachmentManager.removeAttachmentFromServer(Attachment)

getMigrator

public AttachmentDao.AttachmentMigrator getMigrator(AttachmentManager destination)
Description copied from interface: AttachmentManager
Retrieves a AttachmentDao.AttachmentMigrator that will allow the attachments from one data store to be moved across to another.

Specified by:
getMigrator in interface AttachmentManager
Parameters:
destination - the AttachmentManager the data is being moved to
Returns:
an AttachmentMigrator object

getCopier

public AttachmentDao.AttachmentCopier getCopier(AttachmentManager destination)
Description copied from interface: AttachmentManager
Retrieves a AttachmentDao.AttachmentCopier that will allow the attachments from one data store to be copied across to another.

Specified by:
getCopier in interface AttachmentManager
Parameters:
destination - the AttachmentManager the data is being copied to
Returns:
an AttachmentCopier object

getAttachmentDao

public AttachmentDao getAttachmentDao()
Description copied from interface: AttachmentManager
Retrieves the AttachmentDao for the AttachmentManager

Specified by:
getAttachmentDao in interface AttachmentManager
Returns:
An AttachmentDao instance

setSettingsManager

public void setSettingsManager(SettingsManager settingsManager)

setWebDavAttachmentManager

public void setWebDavAttachmentManager(AttachmentManagerInternal webDavAttachmentManager)

setDefaultAttachmentManager

public void setDefaultAttachmentManager(AttachmentManagerInternal defaultAttachmentManager)

setDatabaseAttachmentManager

public void setDatabaseAttachmentManager(AttachmentManagerInternal databaseAttachmentManager)

getBackingStorageType

public AttachmentDataStorageType getBackingStorageType()
Description copied from interface: AttachmentManager
Returns the currently active storage type.

Specified by:
getBackingStorageType in interface AttachmentManager
See Also:
AttachmentDao.getBackingStorageType()

getAttachmentForDownloadPath

public com.atlassian.fugue.Maybe<Attachment> getAttachmentForDownloadPath(String downloadPath)
Description copied from interface: AttachmentManager
Find an Attachment for the given downloadPath.

The path must at least contain the segment produced by Attachment.getDownloadPath(), that is /download/attachments/<contentId>/<fileName> where <contentId> identifies a valid ContentEntityObject and <fileName> identifies a valid Attachment attached to that ContentEntityObject.

Specified by:
getAttachmentForDownloadPath in interface AttachmentManager
Parameters:
downloadPath - the download path identifying an Attachment.This value is expected to be url encoded, with spaces converted to %20 instead of a '+'
Returns:
maybe the attachment if the given download path matches the criteria as described above and the referenced objects are known to the system
See Also:
Attachment.getDownloadPath()

getRemappedAttachmentIds

public Map<Long,Long> getRemappedAttachmentIds()
Description copied from interface: AttachmentManager
Gets a list of remapped attachment IDs. The key is the old ID and the value is the new ID.

Specified by:
getRemappedAttachmentIds in interface AttachmentManager
Returns:
A map where the key is the original ID and the value is the new ID.


Copyright © 2003–2015 Atlassian. All rights reserved.