com.atlassian.confluence.upgrade
Class AttachmentFileNameUpgradeTask

java.lang.Object
  extended bycom.atlassian.confluence.upgrade.AttachmentFileNameUpgradeTask
All Implemented Interfaces:
UpgradeTask

public class AttachmentFileNameUpgradeTask
extends Object
implements UpgradeTask

Upgrade confluence file system based attachment storage to use new ID naming strategy for attachments [CONF-2948]


Field Summary
protected static org.apache.log4j.Category log
           
 String[] mangledEncodings
           
static int UPDATE_BUILD_NUMBER
           
 
Constructor Summary
AttachmentFileNameUpgradeTask()
           
 
Method Summary
 void doUpgrade()
          Upgrade the attachment files to use the new naming strategy
 String getBuildNumber()
           
 Collection getErrors()
           
 String[] getMangledEncodings()
           
 String getShortDescription()
           
 boolean isSearchForMissingAttachmentFiles()
           
protected  void logMissingAttachments(Collection missingAttachments)
          Report any attachments that were not upgraded successfully
protected  void processAttachments(Iterator attachmentIterator, Collection missingAttachments)
          Update attachment names on disk
protected  void processMissingAttachments(Collection missingAttachments)
          Try and fix any attachment files that were not found
protected  void processStagedUpdates()
          Process all of the staged updates
 void setAttachmentDao(AttachmentDao attachmentDao)
           
 void setBootstrap(BootstrapManager bootstrap)
           
 void setMangledEncodings(String[] mangledEncodings)
          Set the list of character encodings to use when looking for missing attachment files on disk
 void setSearchForMissingAttachmentFiles(boolean searchForMissingAttachmentFiles)
          Sets whether to try and find missing attachment files during upgrade (true by default)
protected  void stageUpdatedAttachment(File originalAttachment, File updatedFile)
          Stage an update for later processing - used for name collision resolution
protected  boolean tryToFixFile(File attachmentDir, Attachment attachment, String nativeEncoding)
          Try and locate and update a file which may have a badly encoded file name This method will run through all the configured mangled encodings
protected  boolean tryToFixFile(File attachmentDir, Attachment attachment, String nativeEncoding, String fileSystemEncoding)
          Try to fix an attachment file by looking for a file name encoded with the specified encoding
protected  boolean updateAttachmentFile(Attachment attachment, File attachmentFile)
          Map an attachment to the new ID based naming scheme
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UPDATE_BUILD_NUMBER

public static final int UPDATE_BUILD_NUMBER
See Also:
Constant Field Values

log

protected static org.apache.log4j.Category log

mangledEncodings

public String[] mangledEncodings
Constructor Detail

AttachmentFileNameUpgradeTask

public AttachmentFileNameUpgradeTask()
Method Detail

isSearchForMissingAttachmentFiles

public boolean isSearchForMissingAttachmentFiles()

setSearchForMissingAttachmentFiles

public void setSearchForMissingAttachmentFiles(boolean searchForMissingAttachmentFiles)
Sets whether to try and find missing attachment files during upgrade (true by default)

Parameters:
searchForMissingAttachmentFiles -

setBootstrap

public void setBootstrap(BootstrapManager bootstrap)

getMangledEncodings

public String[] getMangledEncodings()

setMangledEncodings

public void setMangledEncodings(String[] mangledEncodings)
Set the list of character encodings to use when looking for missing attachment files on disk

Parameters:
mangledEncodings - An array of character encoding strings as used by String.getBytes()

getBuildNumber

public String getBuildNumber()
Specified by:
getBuildNumber in interface UpgradeTask

getShortDescription

public String getShortDescription()
Specified by:
getShortDescription in interface UpgradeTask

doUpgrade

public void doUpgrade()
               throws Exception
Upgrade the attachment files to use the new naming strategy

Specified by:
doUpgrade in interface UpgradeTask
Throws:
Exception

processAttachments

protected void processAttachments(Iterator attachmentIterator,
                                  Collection missingAttachments)
Update attachment names on disk

Parameters:
attachmentIterator - An Iterator over attachments to process
missingAttachments - A collection to hold any attachment objects which could not be matched to a file on disk

processMissingAttachments

protected void processMissingAttachments(Collection missingAttachments)
Try and fix any attachment files that were not found

Parameters:
missingAttachments -

logMissingAttachments

protected void logMissingAttachments(Collection missingAttachments)
Report any attachments that were not upgraded successfully

Parameters:
missingAttachments - Collection of missed attachments

updateAttachmentFile

protected boolean updateAttachmentFile(Attachment attachment,
                                       File attachmentFile)
Map an attachment to the new ID based naming scheme

Parameters:
attachment - The attachment to process
attachmentFile - The expected location of the attachment
Returns:
true if the rename succeeded

stageUpdatedAttachment

protected void stageUpdatedAttachment(File originalAttachment,
                                      File updatedFile)
Stage an update for later processing - used for name collision resolution

Parameters:
originalAttachment - The original attachment file
updatedFile - The file we want to rename it to

processStagedUpdates

protected void processStagedUpdates()
Process all of the staged updates


tryToFixFile

protected boolean tryToFixFile(File attachmentDir,
                               Attachment attachment,
                               String nativeEncoding)
Try and locate and update a file which may have a badly encoded file name This method will run through all the configured mangled encodings

Parameters:
attachmentDir - Root attachment directory
attachment - Attachment to fix
nativeEncoding - Encoding to use to decode the Attachment object's getFileName()
Returns:
true if a file was found and updated

tryToFixFile

protected boolean tryToFixFile(File attachmentDir,
                               Attachment attachment,
                               String nativeEncoding,
                               String fileSystemEncoding)
                        throws UnsupportedEncodingException
Try to fix an attachment file by looking for a file name encoded with the specified encoding

Parameters:
attachmentDir -
attachment -
nativeEncoding -
fileSystemEncoding - Encoding to use when looking on disk
Returns:
true if a file was found and updated
Throws:
UnsupportedEncodingException - When fileSystemEncoding is not recognised

getErrors

public Collection getErrors()
Specified by:
getErrors in interface UpgradeTask

setAttachmentDao

public void setAttachmentDao(AttachmentDao attachmentDao)


Confluence is developed by Atlassian.