mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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>
|
||||||
|
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -643,21 +635,30 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user