com.atlassian.confluence.pages.persistence.dao
Class WebDavAttachmentDao

java.lang.Object
  extended bycom.atlassian.confluence.pages.persistence.dao.WebDavAttachmentDao
All Implemented Interfaces:
AttachmentDao

public class WebDavAttachmentDao
extends Object
implements AttachmentDao

AttachmentDAO implementation for a WebDAV backend. This class handles authentication and communication with a WebDAV server when it is being used for Attachment storage. This implementation is different to the default (AbstractHibernateAttachmentDao), as it does not store the Attachment data in the Hibernate-managed Confluence database. Instead, we construct the Attachment information from the properties stored by the WebDAV server. While this may result in decreased performance, it allows the WebDAV server to be accessed independently of Confluence and attachments changes to be reflected in Confluence.


Nested Class Summary
 
Nested classes inherited from class com.atlassian.confluence.pages.persistence.dao.AttachmentDao
AttachmentDao.AttachmentCopier, AttachmentDao.AttachmentMigrator
 
Constructor Summary
WebDavAttachmentDao()
           
 
Method Summary
 void afterMigrationFrom()
          The contents of the WebDAV store may be used by other applications or users, so we do not clean it out after migrating away from it.
 List findAll()
          Retrieves the latest versions of all Attachments Use of this method is discouraged when there are a large amount of Attachments.
 List findAllVersions(Attachment attachment)
           
 Iterator findLatestVersionsIterator()
          This implementation is technically dodgy.
 List getAttachmentByQuery(ListQuery query, int firstResult)
           
 InputStream getAttachmentData(Attachment attachment)
          Retrieves the InputStream representing the data for attachment
 AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
          This method is not supported by the implementation.
 List getLatestVersionsOfAttachments(ContentEntityObject ceo)
          Retrieves the latest versions of all attachments to ceo
 AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
          This method is not supported by the implementation.
 void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
          Moves an Attachment to a new file name or content object

This method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.

 void prepareForMigrationTo()
          In this implementation, there may be existing files on the WebDAV store, so no deletion will occur.
 void removeAttachmentFromServer(Attachment attachment)
          todo: Should i remove the files from the webdav server?! should i remove the parent folder when folder's empty?
 void renameAttachment(Attachment attachment, String newName)
           
 void replaceAttachmentData(Attachment attachment, InputStream attachmentData)
          Technically, this method is supposed to overwrite existing data without incrementing the version, due to the nature of WebDAV, we can't avoid that.
 void saveNewAttachment(Attachment attachment, InputStream attachmentData)
          This implementation saves a new Attachment to the appropriate path.
 void saveNewAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream attachmentData)
          Saves a new version of attachment
 void setConfig(WebDavConfiguration config)
           
 void setContentEntityManager(ContentEntityManager contentEntityManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebDavAttachmentDao

public WebDavAttachmentDao()
Method Detail

setConfig

public void setConfig(WebDavConfiguration config)

getLatestVersionsOfAttachments

public List getLatestVersionsOfAttachments(ContentEntityObject ceo)
Description copied from interface: AttachmentDao
Retrieves the latest versions of all attachments to ceo

Specified by:
getLatestVersionsOfAttachments in interface AttachmentDao
Parameters:
ceo - the content to look up attachments
Returns:
a List of Attachment objects

findAll

public List findAll()
Description copied from interface: AttachmentDao
Retrieves the latest versions of all Attachments Use of this method is discouraged when there are a large amount of Attachments.

Specified by:
findAll in interface AttachmentDao
Returns:
A List of Attachment objects
See Also:
AttachmentDao.findLatestVersionsIterator()

findLatestVersionsIterator

public Iterator findLatestVersionsIterator()
This implementation is technically dodgy. In other (Hibernate) implementations, we get an iterator of the results from the database, so we don't have to load all of the attachments into memory at the same time.

However, due to the nature of WebDAV (and the fact that we don't have a store for Attachment meta-data internal to Confluence), we can't do that, so just return an Iterator over the results of #findAll.

Specified by:
findLatestVersionsIterator in interface AttachmentDao
Returns:
an Iterator for the results of #findAll

getAttachmentData

public InputStream getAttachmentData(Attachment attachment)
                              throws AttachmentDataNotFoundException
Description copied from interface: AttachmentDao
Retrieves the InputStream representing the data for attachment

Specified by:
getAttachmentData in interface AttachmentDao
Parameters:
attachment -
Returns:
InputStream of the data
Throws:
AttachmentDataNotFoundException - if the data could not be found

getAttachmentByQuery

public List getAttachmentByQuery(ListQuery query,
                                 int firstResult)
Specified by:
getAttachmentByQuery in interface AttachmentDao

saveNewAttachment

public void saveNewAttachment(Attachment attachment,
                              InputStream attachmentData)
This implementation saves a new Attachment to the appropriate path.

It also removes the ContentEntityObject from the Attachment, in order to prevent cascade problems with Hibernate trying to store the Attachment and the CEO.

Specified by:
saveNewAttachment in interface AttachmentDao
Parameters:
attachment - the Attachment to save
attachmentData - the data to save for the Attachment

saveNewAttachmentVersion

public void saveNewAttachmentVersion(Attachment attachment,
                                     Attachment previousVersion,
                                     InputStream attachmentData)
Description copied from interface: AttachmentDao
Saves a new version of attachment

Specified by:
saveNewAttachmentVersion in interface AttachmentDao
Parameters:
attachment - the Attachment to be saved
previousVersion - the previous version of the Attachment
attachmentData - the attachment data to be saved

moveAttachment

public void moveAttachment(Attachment attachment,
                           Attachment oldAttachment,
                           ContentEntityObject newContent)
Description copied from interface: AttachmentDao
Moves an Attachment to a new file name or content object

This method assumes that the filename and/or content of the attachment (and its previous versions) have already been updated.

Specified by:
moveAttachment in interface AttachmentDao
Parameters:
attachment - the Attachment to be moved
oldAttachment - the Attachment before it has been updated
newContent - the new content attachment belongs to

removeAttachmentFromServer

public void removeAttachmentFromServer(Attachment attachment)
todo: Should i remove the files from the webdav server?! should i remove the parent folder when folder's empty?

Specified by:
removeAttachmentFromServer in interface AttachmentDao
Parameters:
attachment - the Attachment to be removed

replaceAttachmentData

public void replaceAttachmentData(Attachment attachment,
                                  InputStream attachmentData)
Technically, this method is supposed to overwrite existing data without incrementing the version, due to the nature of WebDAV, we can't avoid that.

Specified by:
replaceAttachmentData in interface AttachmentDao
Parameters:
attachment - the Attachment to replace the data
attachmentData - the data to write

getMigrator

public AttachmentDao.AttachmentMigrator getMigrator(AttachmentDao destinationDao)
This method is not supported by the implementation.

Specified by:
getMigrator in interface AttachmentDao
Parameters:
destinationDao - the destination AttachmentDAO
Returns:
throws UnsupportedOperationException
See Also:
GeneralAttachmentMigrator

getCopier

public AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
This method is not supported by the implementation.

Specified by:
getCopier in interface AttachmentDao
Parameters:
destinationDao - the destination AttachmentDAO
Returns:
throws UnsupportedOperationException
See Also:
GeneralAttachmentCopier

prepareForMigrationTo

public void prepareForMigrationTo()
In this implementation, there may be existing files on the WebDAV store, so no deletion will occur. However, existing files will be overwritten.

Specified by:
prepareForMigrationTo in interface AttachmentDao

afterMigrationFrom

public void afterMigrationFrom()
The contents of the WebDAV store may be used by other applications or users, so we do not clean it out after migrating away from it.

Specified by:
afterMigrationFrom in interface AttachmentDao

renameAttachment

public void renameAttachment(Attachment attachment,
                             String newName)
                      throws IOException
Throws:
IOException

setContentEntityManager

public void setContentEntityManager(ContentEntityManager contentEntityManager)

findAllVersions

public List findAllVersions(Attachment attachment)
Specified by:
findAllVersions in interface AttachmentDao


Confluence is developed by Atlassian.