From: Andreas Beeker Date: Sat, 19 Sep 2020 08:16:34 +0000 (+0000) Subject: #64716 - wmf display error - use FileMagic also for File-based input X-Git-Tag: before_ooxml_3rd_edition~112 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8eefca1bfe3c843ca3ffb7c9c6b82ecb8af73399;p=poi.git #64716 - wmf display error - use FileMagic also for File-based input git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881838 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java index ff0d4e7d8a..46d3da99fb 100644 --- a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java +++ b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java @@ -362,46 +362,42 @@ public final class PPTX2PNG { } } + private interface ProxyConsumer { + void parse(MFProxy proxy) throws IOException; + } + @SuppressWarnings({"resource", "squid:S2095"}) private MFProxy initProxy(File file) throws IOException { MFProxy proxy; final String fileName = file.getName().toLowerCase(Locale.ROOT); + FileMagic fm; + ProxyConsumer con; if ("stdin".equals(fileName)) { InputStream bis = FileMagic.prepareToCheckMagic(System.in); - FileMagic fm = FileMagic.valueOf(bis); - if (fm == FileMagic.UNKNOWN) { - fm = defaultFileType; - } - switch (fm) { - case EMF: - proxy = new EMFHandler(); - break; - case WMF: - proxy = new WMFHandler(); - break; - default: - proxy = new PPTHandler(); - break; - } - proxy.setIgnoreParse(ignoreParse); - proxy.setQuite(quiet); - proxy.parse(bis); + fm = FileMagic.valueOf(bis); + con = (p) -> p.parse(bis); } else { - switch (fileName.contains(".") ? fileName.substring(fileName.lastIndexOf('.')) : "") { - case ".emf": - proxy = new EMFHandler(); - break; - case ".wmf": - proxy = new WMFHandler(); - break; - default: - proxy = new PPTHandler(); - break; - } - proxy.setIgnoreParse(ignoreParse); - proxy.setQuite(quiet); - proxy.parse(file); + fm = FileMagic.valueOf(file); + con = (p) -> p.parse(file); + } + + if (fm == FileMagic.UNKNOWN) { + fm = defaultFileType; + } + switch (fm) { + case EMF: + proxy = new EMFHandler(); + break; + case WMF: + proxy = new WMFHandler(); + break; + default: + proxy = new PPTHandler(); + break; } + proxy.setIgnoreParse(ignoreParse); + proxy.setQuite(quiet); + con.parse(proxy); proxy.setDefaultCharset(charset); return proxy;