aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2021-09-19 19:52:20 +0000
committerAndreas Beeker <kiwiwings@apache.org>2021-09-19 19:52:20 +0000
commitd6806c33652ecfcb4f106a0c988bfa057c76104f (patch)
tree4f90b6901ff9f8d77379a90820287587dc718dd2 /poi-ooxml
parent22f16b9fe8560a7679255554f04e4056c2901273 (diff)
downloadpoi-d6806c33652ecfcb4f106a0c988bfa057c76104f.tar.gz
poi-d6806c33652ecfcb4f106a0c988bfa057c76104f.zip
rework BitmapImageRenderer
refactor TestPPTX2PNG code to support archives git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893451 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/build.gradle1
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java93
2 files changed, 73 insertions, 21 deletions
diff --git a/poi-ooxml/build.gradle b/poi-ooxml/build.gradle
index f8ac5a93ae..d6ac1c2149 100644
--- a/poi-ooxml/build.gradle
+++ b/poi-ooxml/build.gradle
@@ -136,6 +136,7 @@ dependencies {
testImplementation 'org.openjdk.jmh:jmh-core:1.32'
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.32'
testImplementation 'com.google.guava:guava:30.1.1-jre'
+ testImplementation 'org.tukaani:xz:1.9'
// prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.32 dependency
// see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
index 4226b28095..c94cf59580 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
@@ -25,13 +25,20 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.function.Function;
+import java.util.Locale;
import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
+import org.apache.commons.compress.archivers.sevenz.SevenZFile;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.xslf.util.PPTX2PNG;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -44,6 +51,7 @@ import org.junit.jupiter.params.provider.MethodSource;
class TestPPTX2PNG {
private static boolean xslfOnly;
private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
+
private static final File basedir = null;
private static final String files =
@@ -58,38 +66,55 @@ class TestPPTX2PNG {
private static final String pdfFiles =
"alterman_security.ppt";
+ private static InputStream defStdin;
+
@BeforeAll
- public static void checkHslf() {
+ public static void init() {
try {
Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
} catch (Exception e) {
xslfOnly = true;
}
+ defStdin = System.in;
}
- public static Stream<Arguments> data() {
- Function<String, Stream<Arguments>> fun = (basedir == null)
- ? (f) -> Stream.of(Arguments.of(f))
- : (f) -> Stream.of(basedir.listFiles(p -> p.getName().matches(f))).map(File::getName).map(Arguments::of);
+ @AfterAll
+ public static void resetStdin() {
+ System.setIn(defStdin);
+ }
- return Stream.of(files.split(", ?")).flatMap(fun);
+ public static Stream<Arguments> data() throws IOException {
+ if (basedir != null && basedir.getName().endsWith(".zip")) {
+ ZipFile zipFile = new ZipFile(basedir);
+ return zipFile.stream().map(f -> Arguments.of(f.getName(), f, zipFile));
+ } else if (basedir != null && basedir.getName().endsWith(".7z")) {
+ SevenZFile sevenZFile = new SevenZFile(basedir);
+ return ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().filter(f -> !f.isDirectory()).map(f -> Arguments.of(f.getName(), f, sevenZFile));
+ } else {
+ return Stream.of(files.split(", ?")).
+ map(basedir == null ? samples::getFile : f -> new File(basedir, f)).
+ map(f -> Arguments.of(f.getName(), f, f.getParentFile()));
+ }
}
// use filename instead of File object to omit full pathname in test name
- @ParameterizedTest
+ @ParameterizedTest(name = "{0} ({index})")
@MethodSource("data")
- void render(String pptFile) throws Exception {
- assumeFalse(xslfOnly && pptFile.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
- PPTX2PNG.main(getArgs(pptFile, "null"));
- if (svgFiles.contains(pptFile)) {
- PPTX2PNG.main(getArgs(pptFile, "svg"));
+ void render(String fileName, Object fileObj, Object fileContainer) throws Exception {
+ assumeFalse(xslfOnly && fileName.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "null"));
+ if (svgFiles.contains(fileName)) {
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "svg"));
+ }
+ if (pdfFiles.contains(fileName)) {
+ PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "pdf"));
}
- if (pdfFiles.contains(pptFile)) {
- PPTX2PNG.main(getArgs(pptFile, "pdf"));
+ if (System.in != defStdin) {
+ System.in.close();
}
}
- private String[] getArgs(String pptFile, String format) throws IOException {
+ private String[] getArgs(String fileName, Object fileObj, Object fileContainer, String format) throws IOException {
File tmpDir = new File("build/tmp/");
// fix maven build errors
@@ -105,20 +130,46 @@ class TestPPTX2PNG {
// "-dump", new File("build/tmp/", pptFile+".json").getCanonicalPath(),
"-dump", "null",
"-quiet",
+ "-ignoreParse",
// "-charset", "GBK",
// "-emfHeaderBounds",
// "-textAsShapes",
+ // "-extractEmbedded",
"-fixside", "long",
"-scale", "800"
));
- if ("bug64693.pptx".equals(pptFile)) {
- args.addAll(asList(
- "-charset", "GBK"
- ));
+ String lName = fileName.toLowerCase(Locale.ROOT);
+ FileMagic inputType = null;
+ if (lName.endsWith(".emf")) {
+ inputType = FileMagic.EMF;
+ } else if (lName.endsWith(".wmf")) {
+ inputType = FileMagic.WMF;
}
- args.add((basedir == null ? samples.getFile(pptFile) : new File(basedir, pptFile)).getAbsolutePath());
+ if (inputType != null) {
+ args.add("-inputtype");
+ args.add(inputType.toString());
+ }
+
+ if (fileName.endsWith("bug64693.pptx")) {
+ args.add("-charset");
+ args.add("GBK");
+ }
+
+ if (fileObj instanceof ZipEntry) {
+ ZipEntry ze = (ZipEntry)fileObj;
+ ZipFile zf = (ZipFile)fileContainer;
+ System.setIn(zf.getInputStream(ze));
+ args.add("stdin");
+ } else if (fileObj instanceof SevenZArchiveEntry) {
+ SevenZArchiveEntry ze = (SevenZArchiveEntry)fileObj;
+ SevenZFile zf = (SevenZFile)fileContainer;
+ System.setIn(zf.getInputStream(ze));
+ args.add("stdin");
+ } else if (fileObj instanceof File) {
+ args.add(((File)fileObj).getAbsolutePath());
+ }
return args.toArray(new String[0]);
}