poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r995464 - in /poi/trunk/src: documentation/content/xdocs/status.xml scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
Date Thu, 09 Sep 2010 15:30:55 GMT
Author: nick
Date: Thu Sep  9 15:30:55 2010
New Revision: 995464

URL: http://svn.apache.org/viewvc?rev=995464&view=rev
Log:
Add getMimeType() method to HWPF Picture, and fix some generics warnings

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.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=995464&r1=995463&r2=995464&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Sep  9 15:30:55 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="poi-developers" type="add">Add getMimeType() method to HWPF
Picture, alongside existing file extension</action>
            <action dev="poi-developers" type="add">Add code for reading Ole10Native
data</action>
            <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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java?rev=995464&r1=995463&r2=995464&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java Thu Sep  9 15:30:55
2010
@@ -17,16 +17,16 @@
 
 package org.apache.poi.hwpf.usermodel;
 
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.POILogFactory;
-
-import java.io.OutputStream;
-import java.io.IOException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.zip.InflaterInputStream;
 
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
 /**
  * Represents embedded picture extracted from Word Document
  * @author Dmitry Romanov
@@ -216,6 +216,35 @@ public final class Picture
     }
     return extension;
   }
+  
+  /**
+   * Returns the mime type for the image
+   */
+  public String getMimeType() {
+     String extension = suggestFileExtension();
+     if("jpg".equals(extension)) {
+        return "image/jpeg";
+     }
+     if("png".equals(extension)) {
+        return "image/png";
+     }
+     if("gif".equals(extension)) {
+        return "image/gif";
+     }
+     if("bmp".equals(extension)) {
+        return "image/bmp";
+     }
+     if("tiff".equals(extension)) {
+        return "image/tiff";
+     }
+     if("wmf".equals(extension)) {
+        return "application/x-wmf";
+     }
+     if("emf".equals(extension)) {
+        return "application/x-emf";
+     }
+     return "image/unknown";
+  }
 
 
   private String suggestFileExtension(byte[] _dataStream, int pictureBytesStartOffset)

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java?rev=995464&r1=995463&r2=995464&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java Thu
Sep  9 15:30:55 2010
@@ -29,7 +29,7 @@ import org.apache.poi.POIDataSamples;
 /**
  * Test the picture handling
  *
- * @author Nick Burch (nick at torchbox dot com)
+ * @author Nick Burch
  */
 public final class TestPictures extends TestCase {
 
@@ -38,21 +38,18 @@ public final class TestPictures extends 
 	 */
 	public void testTwoImages() {
 		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
-		List pics = doc.getPicturesTable().getAllPictures();
+		List<Picture> pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
 		assertEquals(pics.size(), 2);
 		for(int i=0; i<pics.size(); i++) {
-			Object p = pics.get(i);
-			assertTrue(p instanceof Picture);
-
-			Picture pic = (Picture)p;
+			Picture pic = (Picture)pics.get(i);
 			assertNotNull(pic.suggestFileExtension());
 			assertNotNull(pic.suggestFullFileName());
 		}
 
-		Picture picA = (Picture)pics.get(0);
-		Picture picB = (Picture)pics.get(1);
+		Picture picA = pics.get(0);
+		Picture picB = pics.get(1);
 		assertEquals("jpg", picA.suggestFileExtension());
 		assertEquals("jpg", picA.suggestFileExtension());
 	}
@@ -62,25 +59,28 @@ public final class TestPictures extends 
 	 */
 	public void testDifferentImages() {
 		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc");
-		List pics = doc.getPicturesTable().getAllPictures();
+		List<Picture> pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
 		assertEquals(7, pics.size());
 		for(int i=0; i<pics.size(); i++) {
-			Object p = pics.get(i);
-			assertTrue(p instanceof Picture);
-
-			Picture pic = (Picture)p;
+			Picture pic = (Picture)pics.get(i);
 			assertNotNull(pic.suggestFileExtension());
 			assertNotNull(pic.suggestFullFileName());
 		}
 
-		assertEquals("jpg", ((Picture)pics.get(0)).suggestFileExtension());
-		assertEquals("jpg", ((Picture)pics.get(1)).suggestFileExtension());
-		assertEquals("png", ((Picture)pics.get(3)).suggestFileExtension());
-		assertEquals("png", ((Picture)pics.get(4)).suggestFileExtension());
-		assertEquals("wmf", ((Picture)pics.get(5)).suggestFileExtension());
-		assertEquals("jpg", ((Picture)pics.get(6)).suggestFileExtension());
+		assertEquals("jpg", pics.get(0).suggestFileExtension());
+		assertEquals("image/jpeg", pics.get(0).getMimeType());
+		assertEquals("jpg", pics.get(1).suggestFileExtension());
+      assertEquals("image/jpeg", pics.get(1).getMimeType());
+		assertEquals("png", pics.get(3).suggestFileExtension());
+      assertEquals("image/png", pics.get(3).getMimeType());
+		assertEquals("png", pics.get(4).suggestFileExtension());
+      assertEquals("image/png", pics.get(4).getMimeType());
+		assertEquals("wmf", pics.get(5).suggestFileExtension());
+      assertEquals("application/x-wmf", pics.get(5).getMimeType());
+		assertEquals("jpg", pics.get(6).suggestFileExtension());
+      assertEquals("image/jpeg", pics.get(6).getMimeType());
 	}
 
 	/**
@@ -88,12 +88,12 @@ public final class TestPictures extends 
 	 */
 	public void testEmfImage() {
 		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc");
-		List pics = doc.getPicturesTable().getAllPictures();
+		List<Picture> pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
 		assertEquals(1, pics.size());
 
-		Picture pic = (Picture)pics.get(0);
+		Picture pic = pics.get(0);
 		assertNotNull(pic.suggestFileExtension());
 		assertNotNull(pic.suggestFullFileName());
 		assertTrue(pic.getSize() > 128);
@@ -117,12 +117,12 @@ public final class TestPictures extends 
 		// revisiting the implementation of office drawing objects.
 
 		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("emf_2003_image.doc");
-		List pics = doc.getPicturesTable().getAllPictures();
+		List<Picture> pics = doc.getPicturesTable().getAllPictures();
 
 		assertNotNull(pics);
 		assertEquals(1, pics.size());
 
-		Picture pic = (Picture)pics.get(0);
+		Picture pic = pics.get(0);
 		assertNotNull(pic.suggestFileExtension());
 		assertNotNull(pic.suggestFullFileName());
 
@@ -140,33 +140,33 @@ public final class TestPictures extends 
 	public void testPicturesWithTable() {
 		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
 
-		List pics = doc.getPicturesTable().getAllPictures();
+		List<Picture> pics = doc.getPicturesTable().getAllPictures();
 		assertEquals(2, pics.size());
 	}
 
-        public void testPicturesInHeader() {
-                HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc");
+	public void testPicturesInHeader() {
+	   HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc");
 
-                List pics = doc.getPicturesTable().getAllPictures();
-                assertEquals(2, pics.size());
-        }
+	   List<Picture> pics = doc.getPicturesTable().getAllPictures();
+	   assertEquals(2, pics.size());
+	}
 
     public void testFastSaved() {
-            HWPFDocument doc = HWPFTestDataSamples.openSampleFile("rasp.doc");
+       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("rasp.doc");
 
-            doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
+       doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
     }
 
     public void testFastSaved2() {
-            HWPFDocument doc = HWPFTestDataSamples.openSampleFile("o_kurs.doc");
+       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("o_kurs.doc");
 
-            doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
+       doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
     }
 
     public void testFastSaved3() {
-            HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
+       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
 
-            doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
+       doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
     }
 
 }



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


Mime
View raw message