mirror of
https://github.com/sismics/docs.git
synced 2025-12-17 19:51:39 +00:00
Closes #215: handle pptx files
This commit is contained in:
@@ -44,6 +44,16 @@ public class TestFileUtil {
|
||||
Assert.assertTrue(content.contains("Lorem ipsum dolor sit amen."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractContentPowerpointTest() throws Exception {
|
||||
Path path = Paths.get(ClassLoader.getSystemResource("file/apache.pptx").toURI());
|
||||
FormatHandler formatHandler = FormatHandlerUtil.find(MimeTypeUtil.guessMimeType(path, "apache.pptx"));
|
||||
Assert.assertNotNull(formatHandler);
|
||||
Assert.assertTrue(formatHandler instanceof PptxFormatHandler);
|
||||
String content = formatHandler.extractContent("eng", path);
|
||||
Assert.assertTrue(content.contains("Scaling"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractContentPdf() throws Exception {
|
||||
Path path = Paths.get(ClassLoader.getSystemResource("file/udhr.pdf").toURI());
|
||||
@@ -70,7 +80,8 @@ public class TestFileUtil {
|
||||
InputStream inputStream1 = Resources.getResource("file/apollo_portrait.jpg").openStream();
|
||||
InputStream inputStream2 = Resources.getResource("file/udhr_encrypted.pdf").openStream();
|
||||
InputStream inputStream3 = Resources.getResource("file/document.docx").openStream();
|
||||
InputStream inputStream4 = Resources.getResource("file/document.odt").openStream()) {
|
||||
InputStream inputStream4 = Resources.getResource("file/document.odt").openStream();
|
||||
InputStream inputStream5 = Resources.getResource("file/apache.pptx").openStream()) {
|
||||
// Document
|
||||
DocumentDto documentDto = new DocumentDto();
|
||||
documentDto.setTitle("My super document 1");
|
||||
@@ -117,9 +128,16 @@ public class TestFileUtil {
|
||||
file4.setId("document_odt");
|
||||
file4.setMimeType(MimeType.OPEN_DOCUMENT_TEXT);
|
||||
|
||||
// Sixth file
|
||||
Files.copy(inputStream5, DirectoryUtil.getStorageDirectory().resolve("document_pptx"), StandardCopyOption.REPLACE_EXISTING);
|
||||
File file5 = new File();
|
||||
file5.setId("document_pptx");
|
||||
file5.setMimeType(MimeType.OFFICE_PRESENTATION);
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PdfUtil.convertToPdf(documentDto, Lists.newArrayList(file0, file1, file2, file3, file4), true, true, 10, outputStream);
|
||||
PdfUtil.convertToPdf(documentDto, Lists.newArrayList(file0, file1, file2, file3, file4, file5), true, true, 10, outputStream);
|
||||
Assert.assertTrue(outputStream.toByteArray().length > 0);
|
||||
com.google.common.io.Files.write(outputStream.toByteArray(), new java.io.File("C:\\Users\\Jendib\\Downloads\\test.pdf"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,9 @@ public class TestMimeTypeUtil {
|
||||
// Detect DOCX files
|
||||
path = Paths.get(ClassLoader.getSystemResource("file/document.docx").toURI());
|
||||
Assert.assertEquals(MimeType.OFFICE_DOCUMENT, MimeTypeUtil.guessMimeType(path, "document.odt"));
|
||||
|
||||
// Detect PPTX files
|
||||
path = Paths.get(ClassLoader.getSystemResource("file/apache.pptx").toURI());
|
||||
Assert.assertEquals(MimeType.OFFICE_PRESENTATION, MimeTypeUtil.guessMimeType(path, "apache.pptx"));
|
||||
}
|
||||
}
|
||||
|
||||
BIN
docs-core/src/test/resources/file/apache.pptx
Normal file
BIN
docs-core/src/test/resources/file/apache.pptx
Normal file
Binary file not shown.
Reference in New Issue
Block a user