Merged 5.1.N (5.1.1) to HEAD (5.1)

121796 rneamtu: Merged 5.0.N (5.0.4) to 5.1.N (5.1.1)
      121764 nsmintanca: Merged V4.2-BUG-FIX (4.2.7) to 5.0.N (5.0.4)
         121709 rneamtu: Merged DEV to V4.2-BUG-FIX (4.2.7)
            121670 rneamtu: MNT-13814 : Using MS word Save As pdf does not work correctly.
               - Added new mimetype "application/applefile" and set it for files that starts with "._"
               - Added new test for case


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123651 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-03-11 21:42:56 +00:00
parent 678273be01
commit 05fd2f8800
3 changed files with 149 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2016 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -613,11 +613,18 @@ public abstract class AbstractContentWriter extends AbstractContentAccessor impl
guessingOnCloseListener.filename = filename; guessingOnCloseListener.filename = filename;
} }
} }
private void doGuessMimetype(String filename) private void doGuessMimetype(String filename)
{ {
String mimetype = mimetypeService.guessMimetype( String mimetype;
filename, getReader() if (filename.startsWith(MimetypeMap.MACOS_RESOURCE_FORK_FILE_NAME_PREFIX))
); {
mimetype = MimetypeMap.MIMETYPE_APPLEFILE;
}
else
{
mimetype = mimetypeService.guessMimetype(filename, getReader());
}
setMimetype(mimetype); setMimetype(mimetype);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2016 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -58,6 +58,7 @@ public class ContentFullContextTestSuite extends TestSuite
//suite.addTestSuite(MimetypeMapTest.class); //suite.addTestSuite(MimetypeMapTest.class);
suite.addTestSuite(RoutingContentServiceTest.class); suite.addTestSuite(RoutingContentServiceTest.class);
suite.addTest(new JUnit4TestAdapter(RoutingContentStoreTest.class)); suite.addTest(new JUnit4TestAdapter(RoutingContentStoreTest.class));
suite.addTestSuite(GuessMimetypeTest.class);
try try
{ {

View File

@@ -0,0 +1,136 @@
/*
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.content;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* Tests for guess mimetype for file
*
* This includes a test for apple specific hidden files
*
* @author rneamtu
*/
public class GuessMimetypeTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private NodeService nodeService;
private ContentService contentService;
private RetryingTransactionHelper retryingTransactionHelper;
private StoreRef storeRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
@Override
public void setUp() throws Exception
{
this.nodeService = (NodeService) ctx.getBean("nodeService");
this.contentService = (ContentService) ctx.getBean("ContentService");
this.retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{
@Override
public Object execute() throws Throwable
{
// As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
rootNodeRef = nodeService.getRootNode(storeRef);
return null;
}
});
}
public void testAppleMimetype() throws Exception
{
String content = "This is some content";
String fileName = "._myfile.pdf";
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{
@Override
public Object execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13);
properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt");
nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
return null;
}
});
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(content);
writer.guessMimetype(fileName);
assertEquals(MimetypeMap.MIMETYPE_APPLEFILE, writer.getMimetype());
fileName = "myfile.pdf";
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{
@Override
public Object execute() throws Throwable
{
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13);
properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt");
nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
return null;
}
});
ContentWriter writer2 = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
content = "This is other content";
writer2.putContent(content);
writer2.guessMimetype(fileName);
assertNotSame(MimetypeMap.MIMETYPE_APPLEFILE, writer2.getMimetype());
}
}