com.atlassian.confluence.pages
Class DefaultAttachmentManager

java.lang.Object
  extended by com.atlassian.confluence.pages.DefaultAttachmentManager
All Implemented Interfaces:
AttachmentManager
Direct Known Subclasses:
WebDavAttachmentManager

public class DefaultAttachmentManager
extends Object
implements AttachmentManager

Default implementation of AttachmentManager. The storage location of attachments is not defined, and is handled by the AttachmentDao.


Constructor Summary
DefaultAttachmentManager()
           
 
Method Summary
 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
 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
 List<Attachment> getAttachments(ContentEntityObject content)
          Returns a list of all attachments, old and new.
 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.
 void moveAttachment(Attachment latestVersion, String newFileName, ContentEntityObject newContent)
           
 void removeAttachmentFromServer(Attachment latestVersion)
          Removes the attachment and all previous versions
 void removeAttachments(List<? extends Attachment> attachments)
          Removes the contents of attachments from the server
 void saveAttachment(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
          Saves an Attachment and its data
protected  void saveNewAttachment(Attachment attachment, InputStream attachmentData)
           
protected  void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
           
 void setAttachmentDao(AttachmentDao attachmentDao)
           
 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 setEventManager(com.atlassian.event.EventManager eventManager)
           
 void setLinkManager(LinkManager linkManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAttachmentManager

public DefaultAttachmentManager()
Method Detail

getAttachment

public Attachment getAttachment(ContentEntityObject content,
                                String attachmentFileName)
Get the most recent version of an attachment with a given name for a particular page. If the supplied content parameter is not a type which contains attachments (e.g. Comment) then attempt to find the nearest owner that does have attachments.

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

getAttachment

public Attachment getAttachment(ContentEntityObject content,
                                String attachmentFileName,
                                int version)
Retrieve a named attachment from a page. If the supplied content parameter is not a type which contains attachments (e.g. Comment) then attempt to find the nearest owner that does have attachments.

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.

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

saveNewAttachment

protected void saveNewAttachment(Attachment attachment,
                                 InputStream attachmentData)
                          throws IOException
Throws:
IOException

saveNewAttachmentVersion

protected void saveNewAttachmentVersion(Attachment attachment,
                                        Attachment previousVersion,
                                        InputStream attachmentData)
                                 throws IOException
Throws:
IOException

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)

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

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

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

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(long id)
Specified by:
getAttachment in interface AttachmentManager
Returns:
attachment with id

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

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

removeAttachmentFromServer

public void removeAttachmentFromServer(Attachment latestVersion)
Removes the attachment and all previous versions

Specified by:
removeAttachmentFromServer in interface AttachmentManager
Parameters:
latestVersion - latest version of the attachment to remove

moveAttachment

public void moveAttachment(Attachment latestVersion,
                           String newFileName,
                           ContentEntityObject newContent)
Specified by:
moveAttachment in interface AttachmentManager
Parameters:
latestVersion - The attachment to be moved
newFileName - New name of the file
newContent - 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.

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

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

setAttachmentDao

public void setAttachmentDao(AttachmentDao attachmentDao)

setEventManager

public void setEventManager(com.atlassian.event.EventManager eventManager)

setLinkManager

public void setLinkManager(LinkManager linkManager)


Copyright © 2003-2012 Atlassian. All Rights Reserved.