Merged V2.2 to HEAD

11061: Fix for ETWOTWO-16: Mimetype lost after copy/paste


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11226 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-10-07 01:28:20 +00:00
parent 61ff399d12
commit e6d7627f13
2 changed files with 39 additions and 40 deletions

View File

@@ -9,7 +9,6 @@
<property name="namespaceService"><ref bean="namespaceService" /></property> <property name="namespaceService"><ref bean="namespaceService" /></property>
<property name="dictionaryService"><ref bean="dictionaryService" /></property> <property name="dictionaryService"><ref bean="dictionaryService" /></property>
<property name="nodeService"><ref bean="nodeService" /></property> <property name="nodeService"><ref bean="nodeService" /></property>
<property name="tenantService"><ref bean="tenantService" /></property>
<property name="copyService"><ref bean="copyService" /></property> <property name="copyService"><ref bean="copyService" /></property>
<property name="searchService"><ref bean="admSearchService" /></property> <property name="searchService"><ref bean="admSearchService" /></property>
<property name="contentService"><ref bean="contentService" /></property> <property name="contentService"><ref bean="contentService" /></property>

View File

@@ -40,7 +40,6 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.QueryParameterDefImpl; import org.alfresco.repo.search.QueryParameterDefImpl;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -100,7 +99,6 @@ public class FileFolderServiceImpl implements FileFolderService
private NamespaceService namespaceService; private NamespaceService namespaceService;
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
private NodeService nodeService; private NodeService nodeService;
private TenantService tenantService;
private CopyService copyService; private CopyService copyService;
private SearchService searchService; private SearchService searchService;
private ContentService contentService; private ContentService contentService;
@@ -131,11 +129,6 @@ public class FileFolderServiceImpl implements FileFolderService
this.nodeService = nodeService; this.nodeService = nodeService;
} }
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setCopyService(CopyService copyService) public void setCopyService(CopyService copyService)
{ {
this.copyService = copyService; this.copyService = copyService;
@@ -634,7 +627,6 @@ 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)
{ {
@@ -642,22 +634,31 @@ 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);
// Only care about changing the mimetype id the extension has been changed // May need to update the mimetype, to support apps using .tmp files when saving
if (getFileExtension(sourceName).equals(getFileExtension(newName)) == false) ContentData contentData = (ContentData)nodeService.getProperty(targetNodeRef, ContentModel.PROP_CONTENT);
// Check the newName and oldName extensions.
// Keep previous mimetype if
// 1. new extension is empty
// 2. new extension is '.tmp'
// 3. extension was not changed,
//
// It fixes the ETWOTWO-16 issue.
String oldExt = getExtension(beforeFileInfo.getName());
String newExt = getExtension(newName);
if (contentData != null &&
newExt.length() != 0 &&
!"tmp".equalsIgnoreCase(newExt) &&
!newExt.equalsIgnoreCase(oldExt))
{ {
// May need to update the mimetype, to support apps using .tmp files when saving String targetMimetype = contentData.getMimetype();
ContentData contentData = (ContentData)nodeService.getProperty(targetNodeRef, ContentModel.PROP_CONTENT); String newMimetype = mimetypeService.guessMimetype(newName);
if (contentData != null) if (!targetMimetype.equalsIgnoreCase(newMimetype))
{ {
String targetMimetype = contentData.getMimetype(); contentData = ContentData.setMimetype(contentData, newMimetype);
String newMimetype = mimetypeService.guessMimetype(newName); nodeService.setProperty(targetNodeRef, ContentModel.PROP_CONTENT, contentData);
if (!targetMimetype.equalsIgnoreCase(newMimetype)) }
{
contentData = ContentData.setMimetype(contentData, newMimetype);
nodeService.setProperty(targetNodeRef, ContentModel.PROP_CONTENT, contentData);
}
}
} }
} }
catch (DuplicateChildNodeNameException e) catch (DuplicateChildNodeNameException e)
@@ -679,22 +680,6 @@ 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
* *
@@ -979,4 +964,19 @@ public class FileFolderServiceImpl implements FileFolderService
} }
} }
private String getExtension(String name)
{
String result = "";
if (name != null)
{
name = name.trim();
int index = name.lastIndexOf('.');
if (index > -1 && (index < name.length() - 1))
{
result = name.substring(index + 1);
}
}
return result;
}
} }