mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fix/mnt 19682 fix upload versions different mime types (#955)
* MNT-19682 : Fix upload of document versions with different mime types * MNT-19682 : Remove blank line * MNT-19682 : Add doc comment and rename variable. * MNT-19682 Tests for fix upload new version with different mimetype Co-authored-by: Chris Shields <christopher.shields@alfresco.com>
This commit is contained in:
@@ -3950,6 +3950,20 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
// update cached variables after putContent()
|
||||
updateContentData(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another content object.
|
||||
*
|
||||
* @param content ScriptContent to set
|
||||
* @param applyMimetype If true, apply the mimetype from the Content object, else leave the original mimetype
|
||||
* @param guessEncoding If true, guess the encoding from the underlying input stream, else use encoding set in
|
||||
* the Content object as supplied.
|
||||
*/
|
||||
@Deprecated
|
||||
public void write(Content content, boolean applyMimetype, boolean guessEncoding)
|
||||
{
|
||||
write(content, applyMimetype, guessEncoding, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another content object.
|
||||
@@ -3958,15 +3972,23 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
* @param applyMimetype If true, apply the mimetype from the Content object, else leave the original mimetype
|
||||
* @param guessEncoding If true, guess the encoding from the underlying input stream, else use encoding set in
|
||||
* the Content object as supplied.
|
||||
* @param fileName The filename for the attachment.
|
||||
*/
|
||||
public void write(Content content, boolean applyMimetype, boolean guessEncoding)
|
||||
public void write(Content content, boolean applyMimetype, boolean guessEncoding, String fileName)
|
||||
{
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
|
||||
InputStream is = null;
|
||||
if (applyMimetype)
|
||||
{
|
||||
writer.setMimetype(content.getMimetype().toLowerCase());
|
||||
if (fileName != null && !fileName.isEmpty())
|
||||
{
|
||||
writer.setMimetype(services.getMimetypeService().guessMimetype(fileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.setMimetype(content.getMimetype().toLowerCase());
|
||||
}
|
||||
}
|
||||
if (guessEncoding)
|
||||
{
|
||||
|
@@ -95,6 +95,7 @@ import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestName;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.springframework.extensions.surf.util.InputStreamContent;
|
||||
|
||||
|
||||
/**
|
||||
@@ -848,4 +849,44 @@ public class ScriptNodeTest
|
||||
fail("Converting multiple property for Activiti script fails with " + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://issues.alfresco.com/jira/browse/MNT-19682
|
||||
* Test that mimetype is correctly set according to the content
|
||||
*/
|
||||
@Test
|
||||
public void testWriteContentWithMimetypeAndWithoutFilename()
|
||||
{
|
||||
createTestContent(true);
|
||||
ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
|
||||
scriptNode.setScope(getScope());
|
||||
|
||||
ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);
|
||||
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
|
||||
InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");
|
||||
|
||||
scd.write(inputStreamContent, true, false);
|
||||
assertEquals(MimetypeMap.MIMETYPE_APPLICATION_PS, scriptNode.getMimetype());
|
||||
}
|
||||
|
||||
/**
|
||||
* https://issues.alfresco.com/jira/browse/MNT-19682
|
||||
* Test that mimetype is correctly set according to the filename
|
||||
*/
|
||||
@Test
|
||||
public void testWriteContentWithMimetypeAndFilename()
|
||||
{
|
||||
createTestContent(true);
|
||||
ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
|
||||
scriptNode.setScope(getScope());
|
||||
|
||||
ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);
|
||||
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
|
||||
InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");
|
||||
|
||||
scd.write(inputStreamContent, true, false, "test.ai");
|
||||
assertEquals(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR, scriptNode.getMimetype());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user