You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/09/09 11:28:05 UTC
svn commit: r995360 - in /poi/trunk/src: documentation/content/xdocs/
java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/
ooxml/java/org/apache/poi/xssf/usermodel/
ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/po...
Author: nick
Date: Thu Sep 9 09:28:04 2010
New Revision: 995360
URL: http://svn.apache.org/viewvc?rev=995360&view=rev
Log:
Add getMimeType() method to HSSF/XSSF PictureData, alongside existing file extension
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/PictureData.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Sep 9 09:28:04 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta3" date="2010-??-??">
+ <action dev="poi-developers" type="add">Add getMimeType() method to HSSF/XSSF PictureData, alongside existing file extension</action>
<action dev="poi-developers" type="fix">49887 - allow sheet names longer than 31 chars in XSSF, enforce name uniqueness on the first 31 chars</action>
<action dev="poi-developers" type="fix">49878 - improved API for hiding sheets</action>
<action dev="poi-developers" type="fix">49875 - fixed XSSFWorkbook.createSheet to throw exception if sheet name begins or ends with a single quote (')</action>
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java Thu Sep 9 09:28:04 2010
@@ -81,10 +81,8 @@ public class HSSFPictureData implements
* @see #getFormat
* @return 'wmf', 'jpeg' etc depending on the format. never <code>null</code>
*/
- public String suggestFileExtension()
- {
- switch (blip.getRecordId())
- {
+ public String suggestFileExtension() {
+ switch (blip.getRecordId()) {
case EscherMetafileBlip.RECORD_ID_WMF:
return "wmf";
case EscherMetafileBlip.RECORD_ID_EMF:
@@ -101,5 +99,26 @@ public class HSSFPictureData implements
return "";
}
}
+
+ /**
+ * Returns the mime type for the image
+ */
+ public String getMimeType() {
+ switch (blip.getRecordId()) {
+ case EscherMetafileBlip.RECORD_ID_WMF:
+ return "application/x-wmf";
+ case EscherMetafileBlip.RECORD_ID_EMF:
+ return "application/x-emf";
+ case EscherMetafileBlip.RECORD_ID_PICT:
+ return "image/x-pict";
+ case EscherBitmapBlip.RECORD_ID_PNG:
+ return "image/png";
+ case EscherBitmapBlip.RECORD_ID_JPEG:
+ return "image/jpeg";
+ case EscherBitmapBlip.RECORD_ID_DIB:
+ return "image/bmp";
+ default:
+ return "image/unknown";
+ }
+ }
}
-
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/PictureData.java?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/PictureData.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/PictureData.java Thu Sep 9 09:28:04 2010
@@ -33,4 +33,8 @@ public interface PictureData {
*/
String suggestFileExtension();
+ /**
+ * Returns the mime type for the image
+ */
+ String getMimeType();
}
\ No newline at end of file
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java Thu Sep 9 09:28:04 2010
@@ -120,4 +120,8 @@ public class XSSFPictureData extends POI
}
return 0;
}
+
+ public String getMimeType() {
+ return getPackagePart().getContentType();
+ }
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPictureData.java Thu Sep 9 09:28:04 2010
@@ -36,8 +36,10 @@ public final class TestXSSFPictureData e
assertEquals(5, pictures.size());
String[] ext = {"jpeg", "emf", "png", "emf", "wmf"};
+ String[] mimetype = {"image/jpeg", "image/x-emf", "image/png", "image/x-emf", "image/x-wmf"};
for (int i = 0; i < pictures.size(); i++) {
assertEquals(ext[i], pictures.get(i).suggestFileExtension());
+ assertEquals(mimetype[i], pictures.get(i).getMimeType());
}
int num = pictures.size();
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java?rev=995360&r1=995359&r2=995360&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java Thu Sep 9 09:28:04 2010
@@ -57,6 +57,7 @@ public final class TestHSSFPictureData e
assertEquals(192, jpg.getWidth());
assertEquals(176, jpg.getHeight());
assertEquals(HSSFWorkbook.PICTURE_TYPE_JPEG, pict.getFormat());
+ assertEquals("image/jpeg", pict.getMimeType());
} else if (ext.equals("png")){
//try to read image data using javax.imageio.* (JDK 1.4+)
BufferedImage png = ImageIO.read(new ByteArrayInputStream(data));
@@ -64,6 +65,7 @@ public final class TestHSSFPictureData e
assertEquals(300, png.getWidth());
assertEquals(300, png.getHeight());
assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
+ assertEquals("image/png", pict.getMimeType());
} else {
//TODO: test code for PICT, WMF and EMF
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org