mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-07 17:48:35 +00:00
ATS-545: Code formatting and small improvements (#113)
This commit is contained in:
@@ -89,8 +89,8 @@ public class MiscController extends AbstractTransformerController
|
||||
{
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(SOURCE_ENCODING, "UTF-8");
|
||||
transformer.transform("html", sourceFile, targetFile, MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN,
|
||||
parameters);
|
||||
transformer.transform("html", sourceFile, targetFile, MIMETYPE_HTML,
|
||||
MIMETYPE_TEXT_PLAIN, parameters);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -107,8 +107,10 @@ public class MiscController extends AbstractTransformerController
|
||||
" '{}', timeout {} ms", sourceFile, targetFile, transformOptions, timeout);
|
||||
}
|
||||
|
||||
String transform = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
transformer.transform(transform, sourceFile, targetFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
final String transform = getTransformerName(sourceFile, sourceMimetype, targetMimetype,
|
||||
transformOptions);
|
||||
transformer.transform(transform, sourceFile, targetFile, sourceMimetype, targetMimetype,
|
||||
transformOptions);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
@@ -127,7 +129,8 @@ public class MiscController extends AbstractTransformerController
|
||||
logger.debug(
|
||||
"Processing request with: sourceMimetype '{}', sourceEncoding '{}', " +
|
||||
"targetMimetype '{}', targetExtension '{}', targetEncoding '{}', pageLimit '{}'",
|
||||
sourceMimetype, sourceEncoding, targetMimetype, targetExtension, targetEncoding, pageLimit);
|
||||
sourceMimetype, sourceEncoding, targetMimetype, targetExtension, targetEncoding,
|
||||
pageLimit);
|
||||
}
|
||||
|
||||
final String targetFilename = createTargetFileName(
|
||||
@@ -136,13 +139,15 @@ public class MiscController extends AbstractTransformerController
|
||||
final File sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
final File targetFile = createTargetFile(request, targetFilename);
|
||||
|
||||
Map<String, String> transformOptions = createTransformOptions(
|
||||
"sourceEncoding", sourceEncoding,
|
||||
"targetEncoding", targetEncoding,
|
||||
"pageLimit", pageLimit);
|
||||
final Map<String, String> transformOptions = createTransformOptions(
|
||||
"sourceEncoding", sourceEncoding,
|
||||
"targetEncoding", targetEncoding,
|
||||
"pageLimit", pageLimit);
|
||||
|
||||
String transform = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
transformer.transform(transform, sourceFile, targetFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
final String transform = getTransformerName(sourceFile, sourceMimetype, targetMimetype,
|
||||
transformOptions);
|
||||
transformer.transform(transform, sourceFile, targetFile, sourceMimetype, targetMimetype,
|
||||
transformOptions);
|
||||
|
||||
final ResponseEntity<Resource> body = createAttachment(targetFilename, targetFile);
|
||||
LogEntry.setTargetSize(targetFile.length());
|
||||
|
@@ -26,10 +26,6 @@
|
||||
*/
|
||||
package org.alfresco.transformer.transformers;
|
||||
|
||||
import org.alfresco.transformer.fs.FileManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_MULTIPART_ALTERNATIVE;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
@@ -37,7 +33,6 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
@@ -54,6 +49,10 @@ import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.alfresco.transformer.fs.FileManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Uses javax.mail.MimeMessage to generate plain text versions of RFC822 email
|
||||
* messages. Searches for all text content parts, and returns them. Any
|
||||
@@ -65,32 +64,33 @@ import javax.mail.internet.MimeMessage;
|
||||
* <p>
|
||||
* This code is based on a class of the same name originally implemented in alfresco-repository.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public class EMLTransformer implements SelectableTransformer
|
||||
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger( EMLTransformer.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(EMLTransformer.class);
|
||||
|
||||
private static final String CHARSET = "charset";
|
||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
@Override
|
||||
public void transform(final File sourceFile, final File targetFile, final String sourceMimetype,
|
||||
final String targetMimetype, final Map<String, String> parameters) throws Exception
|
||||
final String targetMimetype, final Map<String, String> parameters) throws Exception
|
||||
{
|
||||
logger.debug("Performing RFC822 to text transform.");
|
||||
// Use try with resource
|
||||
try (InputStream contentInputStream = new BufferedInputStream( new FileInputStream(sourceFile));
|
||||
try (InputStream contentInputStream = new BufferedInputStream(
|
||||
new FileInputStream(sourceFile));
|
||||
Writer bufferedFileWriter = new BufferedWriter(new FileWriter(targetFile)))
|
||||
{
|
||||
MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), contentInputStream);
|
||||
MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()),
|
||||
contentInputStream);
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
Object content = mimeMessage.getContent();
|
||||
if (content instanceof Multipart)
|
||||
{
|
||||
processMultiPart((Multipart) content,sb);
|
||||
processMultiPart((Multipart) content, sb);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -104,13 +104,15 @@ public class EMLTransformer implements SelectableTransformer
|
||||
* Find "text" parts of message recursively and appends it to sb StringBuilder
|
||||
*
|
||||
* @param multipart Multipart to process
|
||||
* @param sb StringBuilder
|
||||
* @param sb StringBuilder
|
||||
* @throws MessagingException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException, IOException
|
||||
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException,
|
||||
IOException
|
||||
{
|
||||
boolean isAlternativeMultipart = multipart.getContentType().contains(MIMETYPE_MULTIPART_ALTERNATIVE);
|
||||
boolean isAlternativeMultipart = multipart.getContentType().contains(
|
||||
MIMETYPE_MULTIPART_ALTERNATIVE);
|
||||
if (isAlternativeMultipart)
|
||||
{
|
||||
processAlternativeMultipart(multipart, sb);
|
||||
@@ -140,7 +142,8 @@ public class EMLTransformer implements SelectableTransformer
|
||||
* @throws IOException
|
||||
* @throws MessagingException
|
||||
*/
|
||||
private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws IOException, MessagingException
|
||||
private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws
|
||||
IOException, MessagingException
|
||||
{
|
||||
Part partToUse = null;
|
||||
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
||||
@@ -151,7 +154,7 @@ public class EMLTransformer implements SelectableTransformer
|
||||
partToUse = part;
|
||||
break;
|
||||
}
|
||||
else if (part.getContentType().contains(MIMETYPE_HTML))
|
||||
else if (part.getContentType().contains(MIMETYPE_HTML))
|
||||
{
|
||||
partToUse = part;
|
||||
}
|
||||
@@ -194,9 +197,11 @@ public class EMLTransformer implements SelectableTransformer
|
||||
String mailPartContent = part.getContent().toString();
|
||||
|
||||
//create a temporary html file with same mail part content and encoding
|
||||
File tempHtmlFile = FileManager.TempFileProvider.createTempFile("EMLTransformer_", ".html");
|
||||
File tempHtmlFile = FileManager.TempFileProvider.createTempFile("EMLTransformer_",
|
||||
".html");
|
||||
String encoding = getMailPartContentEncoding(part);
|
||||
try (OutputStreamWriter osWriter = new OutputStreamWriter( new FileOutputStream( tempHtmlFile), encoding))
|
||||
try (OutputStreamWriter osWriter = new OutputStreamWriter(
|
||||
new FileOutputStream(tempHtmlFile), encoding))
|
||||
{
|
||||
osWriter.write(mailPartContent);
|
||||
}
|
||||
@@ -220,9 +225,9 @@ public class EMLTransformer implements SelectableTransformer
|
||||
int startIndex = contentType.indexOf(CHARSET);
|
||||
if (startIndex > 0)
|
||||
{
|
||||
encoding = contentType.substring(startIndex + CHARSET.length() + 1).replaceAll("\"", "");
|
||||
encoding = contentType.substring(startIndex + CHARSET.length() + 1)
|
||||
.replaceAll("\"", "");
|
||||
}
|
||||
return encoding;
|
||||
}
|
||||
|
||||
}
|
@@ -30,7 +30,6 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
@@ -40,6 +39,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* The SelectingTransformer selects a registered {@link SelectableTransformer}
|
||||
* and delegates the transformation to its implementation.
|
||||
@@ -51,23 +52,19 @@ public class SelectingTransformer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(SelectingTransformer.class);
|
||||
|
||||
private final Map<String, SelectableTransformer> transformers;
|
||||
|
||||
public SelectingTransformer()
|
||||
{
|
||||
transformers = new HashMap<>();
|
||||
transformers.put("appleIWorks", new AppleIWorksContentTransformer());
|
||||
transformers.put("html", new HtmlParserContentTransformer());
|
||||
transformers.put("string", new StringExtractingContentTransformer());
|
||||
transformers.put("textToPdf", new TextToPdfContentTransformer());
|
||||
transformers.put("rfc822", new EMLTransformer());
|
||||
transformers.put("ooXmlThumbnail", new OOXMLThumbnailContentTransformer());
|
||||
}
|
||||
private final Map<String, SelectableTransformer> transformers = ImmutableMap
|
||||
.<String, SelectableTransformer>builder()
|
||||
.put("appleIWorks", new AppleIWorksContentTransformer())
|
||||
.put("html", new HtmlParserContentTransformer())
|
||||
.put("string", new StringExtractingContentTransformer())
|
||||
.put("textToPdf", new TextToPdfContentTransformer())
|
||||
.put("rfc822", new EMLTransformer())
|
||||
.put("ooXmlThumbnail", new OOXMLThumbnailContentTransformer())
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Performs a transform using a transformer selected based on the provided sourceMimetype and targetMimetype
|
||||
*
|
||||
*
|
||||
* @param transform the name of the transformer
|
||||
* @param sourceFile File to transform from
|
||||
* @param targetFile File to transform to
|
||||
@@ -75,7 +72,7 @@ public class SelectingTransformer
|
||||
* @throws TransformException if there was a problem internally
|
||||
*/
|
||||
public void transform(String transform, File sourceFile, File targetFile, String sourceMimetype,
|
||||
String targetMimetype, Map<String, String> parameters) throws TransformException
|
||||
String targetMimetype, Map<String, String> parameters) throws TransformException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -33,8 +33,8 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IWORK_KEYNOT
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IWORK_NUMBERS;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -42,7 +42,6 @@ import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -90,7 +89,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
@Override
|
||||
protected void mockTransformCommand(String sourceExtension, String targetExtension,
|
||||
String sourceMimetype, boolean readTargetFileBytes) throws IOException
|
||||
String sourceMimetype, boolean readTargetFileBytes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -109,14 +108,14 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||
String... params)
|
||||
{
|
||||
|
||||
MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
||||
.param("sourceEncoding", sourceEncoding)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype);
|
||||
final MockHttpServletRequestBuilder builder = super
|
||||
.mockMvcRequest(url, sourceFile, params)
|
||||
.param("sourceEncoding", sourceEncoding)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype);
|
||||
|
||||
// Only the 'string' transformer should have the targetEncoding.
|
||||
if ("text/plain".equals(targetMimetype) && !"message/rfc822".equals(sourceMimetype) && !"text/html".equals(sourceMimetype))
|
||||
if (!"message/rfc822".equals(sourceMimetype) && !"text/html".equals(sourceMimetype))
|
||||
{
|
||||
builder.param("targetEncoding", targetEncoding);
|
||||
}
|
||||
@@ -139,14 +138,14 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
String expected = "Gym class featuring a brown fox and lazy dog";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("eml"));
|
||||
assertTrue("Content from eml transform didn't contain expected value. ",
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,15 +156,16 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
String expected = "El r\u00E1pido zorro marr\u00F3n salta sobre el perro perezoso";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("spanish.eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("spanish.eml"));
|
||||
|
||||
String contentResult = new String(result.getResponse().getContentAsByteArray(), "UTF-8");
|
||||
assertTrue("Content from eml transform didn't contain expected value. ", contentResult.contains(expected));
|
||||
String contentResult = new String(result.getResponse().getContentAsByteArray(), UTF_8);
|
||||
assertTrue("Content from eml transform didn't contain expected value. ",
|
||||
contentResult.contains(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,17 +174,17 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
@Test
|
||||
public void testRFC822WithAttachmentToText() throws Exception
|
||||
{
|
||||
String expected = "Mail with attachment content";
|
||||
String notExpected = "File attachment content";
|
||||
String expected = "Mail with attachment content";
|
||||
String notExpected = "File attachment content";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("attachment.eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("attachment.eml"));
|
||||
assertTrue("Content from eml transform didn't contain expected value. ",
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
assertFalse(result.getResponse().getContentAsString().contains(notExpected));
|
||||
}
|
||||
|
||||
@@ -194,16 +194,16 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
@Test
|
||||
public void testRFC822AlternativeToText() throws Exception
|
||||
{
|
||||
String expected = "alternative plain text";
|
||||
String expected = "alternative plain text";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("alternative.eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("alternative.eml"));
|
||||
assertTrue("Content from eml transform didn't contain expected value. ",
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,14 +214,14 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
String expected = "nested alternative plain text";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("nested.alternative.eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("nested.alternative.eml"));
|
||||
assertTrue("Content from eml transform didn't contain expected value. ",
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
result.getResponse().getContentAsString().contains(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,12 +232,12 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
String expected = " ";
|
||||
MvcResult result = sendRequest("eml",
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("htmlChars.eml"));
|
||||
null,
|
||||
MIMETYPE_RFC822,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
null,
|
||||
readTestFile("htmlChars.eml"));
|
||||
assertFalse(result.getResponse().getContentAsString().contains(expected));
|
||||
}
|
||||
|
||||
@@ -352,68 +352,74 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
public void testAppleIWorksPages() throws Exception
|
||||
{
|
||||
MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS,
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("pages"));
|
||||
assertTrue("Expected image content but content is empty.",result.getResponse().getContentLengthLong() > 0L);
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("pages"));
|
||||
assertTrue("Expected image content but content is empty.",
|
||||
result.getResponse().getContentLengthLong() > 0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppleIWorksNumbers() throws Exception
|
||||
{
|
||||
MvcResult result = sendRequest("numbers", null, MIMETYPE_IWORK_NUMBERS,
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("numbers"));
|
||||
assertTrue("Expected image content but content is empty.",result.getResponse().getContentLengthLong() > 0L);
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("numbers"));
|
||||
assertTrue("Expected image content but content is empty.",
|
||||
result.getResponse().getContentLengthLong() > 0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppleIWorksKey() throws Exception
|
||||
{
|
||||
MvcResult result = sendRequest("key", null, MIMETYPE_IWORK_KEYNOTE,
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("key"));
|
||||
assertTrue("Expected image content but content is empty.",result.getResponse().getContentLengthLong() > 0L);
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("key"));
|
||||
assertTrue("Expected image content but content is empty.",
|
||||
result.getResponse().getContentLengthLong() > 0L);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// @Test
|
||||
// TODO Doesn't work with java 11, enable when fixed
|
||||
public void testOOXML() throws Exception
|
||||
{
|
||||
MvcResult result = sendRequest("docx",null, MIMETYPE_OPENXML_WORDPROCESSING,
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("docx"));
|
||||
assertTrue("Expected image content but content is empty.",result.getResponse().getContentLengthLong() > 0L);
|
||||
MvcResult result = sendRequest("docx", null, MIMETYPE_OPENXML_WORDPROCESSING,
|
||||
"jpeg", MIMETYPE_IMAGE_JPEG, null, readTestFile("docx"));
|
||||
assertTrue("Expected image content but content is empty.",
|
||||
result.getResponse().getContentLengthLong() > 0L);
|
||||
}
|
||||
|
||||
private MvcResult sendRequest(String sourceExtension,
|
||||
String sourceEncoding,
|
||||
String sourceMimetype,
|
||||
String targetExtension,
|
||||
String targetMimetype,
|
||||
String targetEncoding,
|
||||
byte[] content) throws Exception
|
||||
String sourceEncoding,
|
||||
String sourceMimetype,
|
||||
String targetExtension,
|
||||
String targetMimetype,
|
||||
String targetEncoding,
|
||||
byte[] content) throws Exception
|
||||
{
|
||||
MockMultipartFile sourceFile = new MockMultipartFile("file", "test_file." + sourceExtension, sourceMimetype, content);
|
||||
final MockMultipartFile sourceFile = new MockMultipartFile("file",
|
||||
"test_file." + sourceExtension, sourceMimetype, content);
|
||||
|
||||
MockHttpServletRequestBuilder requestBuilder = super.mockMvcRequest("/transform", sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype);
|
||||
final MockHttpServletRequestBuilder requestBuilder = super
|
||||
.mockMvcRequest("/transform", sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype);
|
||||
|
||||
if (sourceEncoding!=null)
|
||||
if (sourceEncoding != null)
|
||||
{
|
||||
requestBuilder.param("sourceEncoding", sourceEncoding);
|
||||
}
|
||||
if (targetEncoding!=null)
|
||||
if (targetEncoding != null)
|
||||
{
|
||||
requestBuilder.param("targetEncoding", targetEncoding);
|
||||
}
|
||||
|
||||
MvcResult result = mockMvc.perform(requestBuilder)
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= "
|
||||
+(targetEncoding==null ? "UTF-8" : targetEncoding)+"''test_file." + targetExtension)).
|
||||
andReturn();
|
||||
return result;
|
||||
return mockMvc.perform(requestBuilder)
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= " +
|
||||
(targetEncoding == null ? "UTF-8" : targetEncoding) +
|
||||
"''test_file." + targetExtension))
|
||||
.andReturn();
|
||||
}
|
||||
|
||||
|
||||
private String clean(String text)
|
||||
{
|
||||
text = text.replaceAll("\\s+\\r", "");
|
||||
|
Reference in New Issue
Block a user