poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1776823 - /poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
Date Sun, 01 Jan 2017 00:56:51 GMT
Author: kiwiwings
Date: Sun Jan  1 00:56:51 2017
New Revision: 1776823

URL: http://svn.apache.org/viewvc?rev=1776823&view=rev
Log:
fix content-type handling in *SSF-EmbeddedExtractor

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java?rev=1776823&r1=1776822&r2=1776823&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java Sun Jan  1
00:56:51 2017
@@ -45,6 +45,7 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.xssf.usermodel.XSSFObjectData;
 
 public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
     private static final POILogger LOG = POILogFactory.getLogger(EmbeddedExtractor.class);
@@ -97,7 +98,11 @@ public class EmbeddedExtractor implement
                     if (od.hasDirectoryEntry()) {
                         data = extractOne((DirectoryNode)od.getDirectory());
                     } else {
-                        data = new EmbeddedData(od.getFileName(), od.getObjectData(), "binary/octet-stream");
+                        String contentType = "binary/octet-stream";
+                        if (od instanceof XSSFObjectData) {
+                            contentType = ((XSSFObjectData)od).getObjectPart().getContentType();
+                        }
+                        data = new EmbeddedData(od.getFileName(), od.getObjectData(), contentType);
                     }
                 } catch (Exception e) {
                     LOG.log(POILogger.WARN, "Entry not found / readable - ignoring OLE embedding",
e);
@@ -169,6 +174,7 @@ public class EmbeddedExtractor implement
         @Override
         public EmbeddedData extract(DirectoryNode dn) throws IOException {
             try {
+                // TODO: inspect the CompObj record for more details, i.e. the content type
                 Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject(dn);
                 return new EmbeddedData(ole10.getFileName(), ole10.getDataBuffer(), "binary/octet-stream");
             } catch (Ole10NativeException e) {
@@ -254,6 +260,7 @@ public class EmbeddedExtractor implement
         public EmbeddedData extract(DirectoryNode dn) throws IOException {
             EmbeddedData ed = super.extract(dn);
             ed.setFilename(dn.getName()+".doc");
+            ed.setContentType("application/msword");
             return ed;
         }
     }
@@ -271,6 +278,7 @@ public class EmbeddedExtractor implement
         public EmbeddedData extract(DirectoryNode dn) throws IOException {
             EmbeddedData ed = super.extract(dn);
             ed.setFilename(dn.getName()+".xls");
+            ed.setContentType("application/vnd.ms-excel");
             return ed;
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message