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

java.lang.Object
  extended by com.atlassian.confluence.pages.persistence.dao.FileSystemAttachmentDataDao
All Implemented Interfaces:
AttachmentDataDao, NonTransactionalAttachmentDataDao
Direct Known Subclasses:
HierarchicalFileSystemAttachmentDataDao

public class FileSystemAttachmentDataDao
extends Object
implements NonTransactionalAttachmentDataDao


Nested Class Summary
static interface FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy
           
 
Field Summary
protected  FileLocationResolver attachmentsDirResolver
           
static FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy NAMING_STRATEGY_FILE_NAME
           
static FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy NAMING_STRATEGY_ID
           
 
Constructor Summary
FileSystemAttachmentDataDao()
           
 
Method Summary
 void afterMigrationFrom()
          In this implementation, we leave the filesystem as is, and don't remove the attachments that have just been moved to another data store.
 FileLocationResolver getAttachmentsDirResolver()
           
protected  File getConfluenceAttachmentDirectory()
           
 InputStream getDataForAttachment(Attachment attachment)
          Grabs the AttachmentData object for an Attachment
protected  File getDirectoryForAttachment(ContentEntityObject content, Attachment attachment)
          Retrieves the location of the containing folder for an Attachment
protected  File getDirectoryForContent(ContentEntityObject content)
           
protected  File getLatestAttachmentFile(Attachment attachment)
           
 FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy getNamingStrategy()
           
 void moveAttachment(Attachment attachment, Attachment oldAttachment, ContentEntityObject newContent)
          Moves an attachment to a new file name or content object
 void prepareForMigrationTo()
          In this implementation, we want to make sure the attachments directory is empty, otherwise we will have attachments or files that don't belong.
 void removeDataForAttachment(Attachment attachment, ContentEntityObject originalContent)
          Removes all attachment data for an attachment
 void replaceDataForAttachment(Attachment attachment, InputStream data)
          Sets the data for attachment This method will overwrite any existing data for the attachment.
 void saveDataForAttachment(Attachment attachment, InputStream data)
          Saves data to the attachment data store
protected  void saveDataForAttachment(Attachment attachment, InputStream data, boolean overwrite)
          Saves data to the file system
 void saveDataForAttachmentVersion(Attachment attachment, Attachment previousVersion, InputStream data)
          Saves data to the attachment data store, for an attachment that has been updated.
 void setAttachmentsDirResolver(FileLocationResolver attachmentsDirResolver)
           
 void setNamingStrategy(FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy namingStrategy)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attachmentsDirResolver

protected FileLocationResolver attachmentsDirResolver

NAMING_STRATEGY_ID

public static final FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy NAMING_STRATEGY_ID

NAMING_STRATEGY_FILE_NAME

public static final FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy NAMING_STRATEGY_FILE_NAME
Constructor Detail

FileSystemAttachmentDataDao

public FileSystemAttachmentDataDao()
Method Detail

getNamingStrategy

public FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy getNamingStrategy()

setNamingStrategy

public void setNamingStrategy(FileSystemAttachmentDataDao.FileSystemAttachmentNamingStrategy namingStrategy)

getConfluenceAttachmentDirectory

protected File getConfluenceAttachmentDirectory()

getLatestAttachmentFile

protected File getLatestAttachmentFile(Attachment attachment)

getDataForAttachment

public InputStream getDataForAttachment(Attachment attachment)
                                 throws AttachmentDataNotFoundException
Description copied from interface: AttachmentDataDao
Grabs the AttachmentData object for an Attachment

Specified by:
getDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment representing the data
Returns:
an AttachmentData object
Throws:
AttachmentDataNotFoundException - if no data was found

removeDataForAttachment

public void removeDataForAttachment(Attachment attachment,
                                    ContentEntityObject originalContent)
Description copied from interface: AttachmentDataDao
Removes all attachment data for an attachment

Specified by:
removeDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - The attachment for which data should be removed
originalContent - The content the attachment belongs to

saveDataForAttachment

public void saveDataForAttachment(Attachment attachment,
                                  InputStream data)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store

Specified by:
saveDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment the data belongs to
data - the InputStream to be written

getAttachmentsDirResolver

public FileLocationResolver getAttachmentsDirResolver()

saveDataForAttachment

protected void saveDataForAttachment(Attachment attachment,
                                     InputStream data,
                                     boolean overwrite)
Saves data to the file system

Parameters:
attachment - the Attachment the data belongs to
data - the InputStream to be written
overwrite -
Throws:
IllegalArgumentException - if attachment is null
IllegalArgumentException - if data is null

saveDataForAttachmentVersion

public void saveDataForAttachmentVersion(Attachment attachment,
                                         Attachment previousVersion,
                                         InputStream data)
Description copied from interface: AttachmentDataDao
Saves data to the attachment data store, for an attachment that has been updated.

This method assumes that the attachment has already been saved.

Specified by:
saveDataForAttachmentVersion in interface AttachmentDataDao
Parameters:
attachment - the new version of the attachment
previousVersion - the previous version of the attachment
data - the InputStream representing the data

replaceDataForAttachment

public void replaceDataForAttachment(Attachment attachment,
                                     InputStream data)
Description copied from interface: AttachmentDataDao
Sets the data for attachment This method will overwrite any existing data for the attachment.

Specified by:
replaceDataForAttachment in interface AttachmentDataDao
Parameters:
attachment - Attachment the data belongs to
data - the data to be saved

moveAttachment

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

Specified by:
moveAttachment in interface AttachmentDataDao
Parameters:
attachment - the Attachment to be moved
oldAttachment - the original version of the attachment
newContent - the new content the Attachment belongs to

getDirectoryForAttachment

protected File getDirectoryForAttachment(ContentEntityObject content,
                                         Attachment attachment)
Retrieves the location of the containing folder for an Attachment

Parameters:
content - the ContentEntityObject the Attachment belongs to
attachment -
Returns:
a File pointing to the location

getDirectoryForContent

protected File getDirectoryForContent(ContentEntityObject content)

prepareForMigrationTo

public void prepareForMigrationTo()
In this implementation, we want to make sure the attachments directory is empty, otherwise we will have attachments or files that don't belong.

We also want to make sure the attachments directory actually exists, prior to moving data across.

It is the responsibility of the action performing the migration to warn the user about this.

Specified by:
prepareForMigrationTo in interface AttachmentDataDao

afterMigrationFrom

public void afterMigrationFrom()
In this implementation, we leave the filesystem as is, and don't remove the attachments that have just been moved to another data store.

Specified by:
afterMigrationFrom in interface AttachmentDataDao

setAttachmentsDirResolver

public void setAttachmentsDirResolver(FileLocationResolver attachmentsDirResolver)


Copyright © 2003-2011 Atlassian. All Rights Reserved.