Merged V2.1-A to HEAD

8574: Fix for ADB-55
   8577: ADB-35: when a file with no extension is copied its MIME type is lost


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9164 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-05-19 14:27:23 +00:00
parent d73a5faa88
commit 60e308f7e9

View File

@@ -679,6 +679,7 @@ public class FileFolderServiceImpl implements FileFolderService
} }
// Only update the name if it has changed // Only update the name if it has changed
String sourceName = (String)nodeService.getProperty(sourceNodeRef, ContentModel.PROP_NAME);
String currentName = (String)nodeService.getProperty(targetNodeRef, ContentModel.PROP_NAME); String currentName = (String)nodeService.getProperty(targetNodeRef, ContentModel.PROP_NAME);
if (currentName.equals(newName) == false) if (currentName.equals(newName) == false)
{ {
@@ -686,18 +687,22 @@ public class FileFolderServiceImpl implements FileFolderService
{ {
// changed the name property // changed the name property
nodeService.setProperty(targetNodeRef, ContentModel.PROP_NAME, newName); nodeService.setProperty(targetNodeRef, ContentModel.PROP_NAME, newName);
// May need to update the mimetype, to support apps using .tmp files when saving // Only care about changing the mimetype id the extension has been changed
ContentData contentData = (ContentData)nodeService.getProperty(targetNodeRef, ContentModel.PROP_CONTENT); if (getFileExtension(sourceName).equals(getFileExtension(newName)) == false)
if (contentData != null)
{ {
String targetMimetype = contentData.getMimetype(); // May need to update the mimetype, to support apps using .tmp files when saving
String newMimetype = mimetypeService.guessMimetype(newName); ContentData contentData = (ContentData)nodeService.getProperty(targetNodeRef, ContentModel.PROP_CONTENT);
if (!targetMimetype.equalsIgnoreCase(newMimetype)) if (contentData != null)
{ {
contentData = ContentData.setMimetype(contentData, newMimetype); String targetMimetype = contentData.getMimetype();
nodeService.setProperty(targetNodeRef, ContentModel.PROP_CONTENT, contentData); String newMimetype = mimetypeService.guessMimetype(newName);
} if (!targetMimetype.equalsIgnoreCase(newMimetype))
{
contentData = ContentData.setMimetype(contentData, newMimetype);
nodeService.setProperty(targetNodeRef, ContentModel.PROP_CONTENT, contentData);
}
}
} }
} }
catch (DuplicateChildNodeNameException e) catch (DuplicateChildNodeNameException e)
@@ -719,6 +724,22 @@ public class FileFolderServiceImpl implements FileFolderService
return afterFileInfo; return afterFileInfo;
} }
/**
* Get the file extension for a given file name
*
* @param filename the file name
* @return String the file extension
*/
private String getFileExtension(String filename)
{
String result = "";
if (filename.lastIndexOf(".")!=-1)
{
result = filename.substring(filename.lastIndexOf(".")+1, filename.length());
}
return result;
}
/** /**
* Determine if the specified node is a special "system" folder path based node * Determine if the specified node is a special "system" folder path based node
* *