@Deprecated public class

WebDavAttachmentDao

extends Object
implements AttachmentDao
java.lang.Object
   ↳ com.atlassian.confluence.pages.persistence.dao.WebDavAttachmentDao

This class is deprecated.
since 2.7 WebDav attachment storage is no longer supported

Class Overview

Legacy AttachmentDAO implementation for a WebDAV backend only maintained in the codebase for the purpose of upgrading *from* WebDAV.

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.

Summary

Public Constructors
WebDavAttachmentDao()
Public Methods
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.
int countLatestVersionsOfAttachments(ContentEntityObject ceo)
List<Attachment> 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<Attachment> findLatestVersionsIterator()
This implementation is technically dodgy.
Attachment getAttachment(ContentEntityObject content, String fileName, int version)
Return the attachment on the specified content with the given filename and version.
InputStream getAttachmentData(Attachment attachment)
Retrieves the InputStream representing the data for attachment
Attachment getById(long id)
Returns the attachment with the given persistent ID.
AttachmentDao.AttachmentCopier getCopier(AttachmentDao destinationDao)
This method is not supported by the implementation.
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.
Attachment getLatestAttachment(ContentEntityObject content, String fileName)
Return the latest version of the attachment on the specified content with the given filename.
List<Attachment> 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 setContentEntityObjectDao(ContentEntityObjectDao contentEntityObjectDao)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.confluence.pages.persistence.dao.AttachmentDao

Public Constructors

public WebDavAttachmentDao ()

Public Methods

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.

public int countLatestVersionsOfAttachments (ContentEntityObject ceo)

public List<Attachment> findAll ()

Retrieves the latest versions of all Attachments Use of this method is discouraged when there are a large amount of Attachments.

Returns
  • A List of Attachment objects

public List findAllVersions (Attachment attachment)

public Iterator<Attachment> 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.
Returns
  • an Iterator for the results of #findAll

public Attachment getAttachment (ContentEntityObject content, String fileName, int version)

Return the attachment on the specified content with the given filename and version. Returns null if no such attachment exists.

Note: unlike getAttachment(ContentEntityObject, String, int), this method does not accept zero as a special flag to indicate the latest version of an attachment. To retrieve the latest version of an attachment, use getLatestAttachment(ContentEntityObject, String).
Parameters
content the content to find the attachment on
fileName the file name of the attachment, treated case-insensitively
version the version of the attachment
Returns
  • the attachment with the given name and version attached to that content, or null if the attachment does not exist.

public InputStream getAttachmentData (Attachment attachment)

Retrieves the InputStream representing the data for attachment

Parameters
attachment the attachment whose data will be returned
Returns
  • InputStream of the data

public Attachment getById (long id)

Returns the attachment with the given persistent ID. Returns null if no such attachment exists.

Parameters
id the persistent ID of the attachment to retrieve
Returns
  • the attachment with the given ID, or null if no attachment exists with the provided ID.

public AttachmentDao.AttachmentCopier getCopier (AttachmentDao destinationDao)

This method is not supported by the implementation.

Parameters
destinationDao the destination AttachmentDAO
Returns
  • throws UnsupportedOperationException

public 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. Result will be sorted with the earliest version coming first.

Parameters
attachment attachment (must be the latest version)
Returns
  • the last added versions for each user who has added a version of the attachment

public Attachment getLatestAttachment (ContentEntityObject content, String fileName)

Return the latest version of the attachment on the specified content with the given filename. Returns null if no attachment with that name on the content exists.

Parameters
content the content to find the attachment on
fileName the file name of the attachment
Returns
  • the latest version of attachment with the given name attached to that content, or null if the attachment does not exist.

public List<Attachment> getLatestVersionsOfAttachments (ContentEntityObject ceo)

Retrieves the latest versions of all attachments to ceo

Parameters
ceo the content to look up attachments
Returns
  • a List of Attachment objects

public AttachmentDao.AttachmentMigrator getMigrator (AttachmentDao destinationDao)

This method is not supported by the implementation.

Parameters
destinationDao the destination AttachmentDAO
Returns
  • throws UnsupportedOperationException

public 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.
Parameters
attachment the Attachment to be moved
oldAttachment the Attachment before it has been updated
newContent the new content attachment belongs to

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.

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?

Parameters
attachment the Attachment to be removed

public void renameAttachment (Attachment attachment, String newName)

Throws
IOException

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.

Parameters
attachment the Attachment to replace the data
attachmentData the data to write

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.
Parameters
attachment the Attachment to save
attachmentData the data to save for the Attachment

public void saveNewAttachmentVersion (Attachment attachment, Attachment previousVersion, InputStream attachmentData)

Saves a new version of attachment

Parameters
attachment the Attachment to be saved
previousVersion the previous version of the Attachment
attachmentData the attachment data to be saved

public void setConfig (WebDavConfiguration config)

public void setContentEntityObjectDao (ContentEntityObjectDao contentEntityObjectDao)