]> source.dussan.org Git - poi.git/commitdiff
#64716 - wmf display error - use FileMagic also for File-based input
authorAndreas Beeker <kiwiwings@apache.org>
Sat, 19 Sep 2020 08:16:34 +0000 (08:16 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sat, 19 Sep 2020 08:16:34 +0000 (08:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881838 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java

index ff0d4e7d8ae7cbd0359bf55a26c5f95d44102781..46d3da99fb1f241f6e3006cd26055a65ecea430f 100644 (file)
@@ -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;