poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1693825 [1/2] - in /poi: site/src/documentation/content/xdocs/ site/src/documentation/content/xdocs/slideshow/ trunk/src/examples/src/org/apache/poi/hslf/examples/ trunk/src/examples/src/org/apache/poi/xslf/usermodel/ trunk/src/java/org/ap...
Date Sun, 02 Aug 2015 20:21:36 GMT
Author: kiwiwings
Date: Sun Aug  2 20:21:35 2015
New Revision: 1693825

URL: http://svn.apache.org/r1693825
Log:
#58190 - The current picture handling uses raw integers for types and index, replace with enum and reference

Modified:
    poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml
    poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
    poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java
    poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

Modified: poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml (original)
+++ poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml Sun Aug  2 20:21:35 2015
@@ -203,16 +203,8 @@
         // picture data
         byte[] data = pict.getData();
 
-        int type = pict.getType();
-        String ext;
-        switch (type) {
-            case HSLFPictureShape.JPEG: ext = ".jpg"; break;
-            case HSLFPictureShape.PNG: ext = ".png"; break;
-            case HSLFPictureShape.WMF: ext = ".wmf"; break;
-            case HSLFPictureShape.EMF: ext = ".emf"; break;
-            case HSLFPictureShape.PICT: ext = ".pict"; break;
-            default: continue;
-        }
+        PictureData.PictureType type = pict.getType();
+        String ext = type.extension;
         FileOutputStream out = new FileOutputStream("pict_" + idx + ext);
         out.write(data);
         out.close();
@@ -220,9 +212,9 @@
     }
 
     // add a new picture to this slideshow and insert it in a new slide
-    idx = ppt.addPicture(new File("clock.jpg"), HSLFPictureShape.JPEG);
+    HSLFPictureData pd = ppt.addPicture(new File("clock.jpg"), PictureData.PictureType.JPEG);
 
-    HSLFPictureShape pictNew = new HSLFPictureShape(idx);
+    HSLFPictureShape pictNew = new HSLFPictureShape(pd);
 
     // set image position in the slide
     pictNew.setAnchor(new java.awt.Rectangle(100, 100, 300, 200));
@@ -238,16 +230,10 @@
             HSLFPictureShape pict = (HSLFPictureShape) sh;
             HSLFPictureData pictData = pict.getPictureData();
             byte[] data = pictData.getData();
-            int type = pictData.getType();
-            if (type == HSLFPictureShape.JPEG) {
-                FileOutputStream out = new FileOutputStream("slide0_" + idx + ".jpg");
-                out.write(data);
-                out.close();
-            } else if (type == HSLFPictureShape.PNG) {
-                FileOutputStream out = new FileOutputStream("slide0_" + idx + ".png");
-                out.write(data);
-                out.close();
-            }
+            PictureData.PictureType type = pictData.getType();
+            FileOutputStream out = new FileOutputStream("slide0_" + idx + type.extension);
+            out.write(data);
+            out.close();
             idx++;
         }
     }
@@ -285,9 +271,9 @@
     HSLFSlideMaster master = ppt.getSlideMasters().get(0);
 
     HSLFFill fill = master.getBackground().getFill();
-    int idx = ppt.addPicture(new File("background.png"), HSLFPictureShape.PNG);
+    HSLFPictureData pd = ppt.addPicture(new File("background.png"), PictureData.PictureType.PNG);
     fill.setFillType(HSLFFill.FILL_PICTURE);
-    fill.setPictureData(idx);
+    fill.setPictureData(pd);
                   </source>
                 </section>
                 <section><title>How to modify background of a slide</title>
@@ -299,9 +285,9 @@
     // Without this line it will use master's background.
     slide.setFollowMasterBackground(false);
     HSLFFill fill = slide.getBackground().getFill();
-    int idx = ppt.addPicture(new File("background.png"), HSLFPictureShape.PNG);
+    HSLFPictureData pd = ppt.addPicture(new File("background.png"), PictureData.PictureType.PNG);
     fill.setFillType(HSLFFill.FILL_PATTERN);
-    fill.setPictureData(idx);
+    fill.setPictureData(pd);    
                   </source>
                 </section>
                 <section><title>How to modify background of a shape</title>

Modified: poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml (original)
+++ poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml Sun Aug  2 20:21:35 2015
@@ -187,13 +187,13 @@
                 <anchor id="AddImage"/>
                 <section><title>Add Image to Slide</title>
                     <source>
-        XMLSlideShow ppt = new XMLSlideShow();
-        XSLFSlide slide = ppt.createSlide();
-        
-        byte[] pictureData = IOUtils.toByteArray(new FileInputStream("image.png"));
+    XMLSlideShow ppt = new XMLSlideShow();
+    XSLFSlide slide = ppt.createSlide();
+    
+    byte[] pictureData = IOUtils.toByteArray(new FileInputStream("image.png"));
 
-        int idx = ppt.addPicture(pictureData, XSLFPictureData.PICTURE_TYPE_PNG);
-        XSLFPictureShape pic = slide.createPicture(idx);
+    XSLFPictureData pd = ppt.addPicture(pictureData, PictureData.PictureType.PNG);
+    XSLFPictureShape pic = slide.createPicture(pd);
                     </source>
                 </section>
 

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sun Aug  2 20:21:35 2015
@@ -39,6 +39,7 @@
     </devs>
 
     <release version="3.13-beta2" date="2015-10-??">
+        <action dev="PD" type="add" fixes-bug="58190">The current picture handling uses raw integers for types and index, replace with enum and reference</action>
         <action dev="PD" type="fix" fixes-bug="58203">Apparently Maven uses plurals for all artifacts except javadocs, so tweak our naming to make it happy</action>
         <action dev="PD" type="add" fixes-bug="58193">Use input stream rather than byte array for checksum etc.</action>
         <action dev="PD" type="add" fixes-bug="58200">SXSSF support for evaluating formula cells, provided the cell and all its references are within the current window</action>

Modified: poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java Sun Aug  2 20:21:35 2015
@@ -77,6 +77,7 @@ public final class DataExtraction {
                     if ("Worksheet".equals(name)) {
 
                         //read xls
+                        @SuppressWarnings({ "unused", "resource" })
                         HSSFWorkbook wb = new HSSFWorkbook(data.getData());
 
                     } else if ("Document".equals(name)) {
@@ -110,31 +111,7 @@ public final class DataExtraction {
                     picIdx++;
                     HSLFPictureShape p = (HSLFPictureShape) shape;
                     HSLFPictureData data = p.getPictureData();
-                    String name = p.getPictureName();
-                    int type = data.getType();
-                    String ext;
-                    switch (type) {
-                        case HSLFPictureShape.JPEG:
-                            ext = ".jpg";
-                            break;
-                        case HSLFPictureShape.PNG:
-                            ext = ".png";
-                            break;
-                        case HSLFPictureShape.WMF:
-                            ext = ".wmf";
-                            break;
-                        case HSLFPictureShape.EMF:
-                            ext = ".emf";
-                            break;
-                        case HSLFPictureShape.PICT:
-                            ext = ".pict";
-                            break;
-                        case HSLFPictureShape.DIB:
-                            ext = ".dib";
-                            break;
-                        default:
-                            continue;
-                    }
+                    String ext = data.getType().extension;
                     FileOutputStream out = new FileOutputStream("pict-" + picIdx + ext);
                     out.write(data.getData());
                     out.close();

Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java Sun Aug  2 20:21:35 2015
@@ -25,6 +25,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 
 /**
  * Images
@@ -39,7 +40,7 @@ public class Tutorial5 {
         XSLFSlide slide = ppt.createSlide();
         File img = new File(System.getProperty("POI.testdata.path"), "slideshow/clock.jpg");
         byte[] data = IOUtils.toByteArray(new FileInputStream(img));
-        int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG);
+        XSLFPictureData pictureIndex = ppt.addPicture(data, PictureType.PNG);
 
         /*XSLFPictureShape shape =*/ slide.createPicture(pictureIndex);
 

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/PictureData.java Sun Aug  2 20:21:35 2015
@@ -20,8 +20,80 @@ package org.apache.poi.sl.usermodel;
 import java.io.IOException;
 
 public interface PictureData {
-	public String getContentType();
+    
+    enum PictureType {
+        /** Extended windows meta file */
+        EMF(2,2,"image/x-emf",".emf"),
+        /** Windows Meta File */
+        WMF(3,3,"image/x-wmf",".wmf"),
+        /** Mac PICT format */
+        PICT(4,4,"image/pict",".pict"), // or image/x-pict (for HSLF) ???
+        /** JPEG format */
+        JPEG(5,5,"image/jpeg",".jpg"),
+        /** PNG format */
+        PNG(6,6,"image/png",".png"),
+        /** Device independent bitmap */
+        DIB(7,7,"image/dib",".dib"),
+        /** GIF image format */
+        GIF(-1,8,"image/gif",".gif"),
+        /** Tag Image File (.tiff) */
+        TIFF(-1,9,"image/tiff",".tif"),
+        /** Encapsulated Postscript (.eps) */
+        EPS(-1,10,"image/x-eps",".eps"),
+        /** Windows Bitmap (.bmp) */
+        BMP(-1,11,"image/x-ms-bmp",".bmp"),
+        /** WordPerfect graphics (.wpg) */
+        WPG(-1,12,"image/x-wpg",".wpg"),
+        /** Microsoft Windows Media Photo image (.wdp) */
+        WDP(-1,13,"image/vnd.ms-photo",".wdp");
+        
+        public final int nativeId, ooxmlId;
+        public final String contentType,extension;
 
-	public byte[] getData();
-	public void setData(byte[] data) throws IOException;
+        PictureType(int nativeId, int ooxmlId,String contentType,String extension) {
+            this.nativeId = nativeId;
+            this.ooxmlId = ooxmlId;
+            this.contentType = contentType;
+            this.extension = extension;
+        }
+        
+        public static PictureType forNativeID(int nativeId) {
+            for (PictureType ans : values()) {
+                if (ans.nativeId == nativeId) return ans;
+            }
+            return null;
+        }
+
+        public static PictureType forOoxmlID(int ooxmlId) {
+            for (PictureType ans : values()) {
+                if (ans.ooxmlId == ooxmlId) return ans;
+            }
+            return null;
+        }
+    }
+    
+    
+    /**
+     * Returns content type (mime type) of this picture.
+     *
+     * @return content type of this picture.
+     */
+	String getContentType();
+	
+	/**
+	 * @return the picture type
+	 */
+	PictureType getType();
+
+    /**
+     * Returns the binary data of this Picture
+     * @return picture data
+     */
+	byte[] getData();
+
+    /**
+     * Sets the binary picture data
+     * @param data picture data
+     */
+	void setData(byte[] data) throws IOException;
 }

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShow.java Sun Aug  2 20:21:35 2015
@@ -21,6 +21,9 @@ import java.awt.Dimension;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
+
 public interface SlideShow {
 	Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>> createSlide() throws IOException;
 
@@ -41,5 +44,16 @@ public interface SlideShow {
      *
      * @return the page size
      */
-    Dimension getPageSize();    
+    Dimension getPageSize();
+    
+
+    /**
+     * Adds a picture to the workbook.
+     *
+     * @param pictureData       The bytes of the picture
+     * @param format            The format of the picture.
+     *
+     * @return the new picture reference
+     */
+    PictureData addPicture(byte[] pictureData, PictureType format) throws IOException;
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Sun Aug  2 20:21:35 2015
@@ -36,6 +36,7 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.sl.usermodel.Resources;
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.util.Beta;
@@ -192,7 +193,9 @@ public class XMLSlideShow extends POIXML
             List<PackagePart> mediaParts = getPackage().getPartsByName(Pattern.compile("/ppt/media/.*?"));
             _pictures = new ArrayList<XSLFPictureData>(mediaParts.size());
             for(PackagePart part : mediaParts){
-                _pictures.add(new XSLFPictureData(part, null));    
+                XSLFPictureData pd = new XSLFPictureData(part, null);
+                pd.setIndex(_pictures.size());
+                _pictures.add(pd);
             }
         }
         return Collections.unmodifiableList(_pictures);
@@ -442,26 +445,28 @@ public class XMLSlideShow extends POIXML
      * @see XSLFPictureData#PICTURE_TYPE_PNG
      * @see XSLFPictureData#PICTURE_TYPE_DIB
      */
-    public int addPicture(byte[] pictureData, int format) {
+    public XSLFPictureData addPicture(byte[] pictureData, PictureType format) {
         XSLFPictureData img = findPictureData(pictureData);
-        // POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format];
 
-        if(img == null) {
-            int imageNumber = _pictures.size();
-            img = (XSLFPictureData) createRelationship(
-                    XSLFPictureData.RELATIONS[format], XSLFFactory.getInstance(), imageNumber + 1, true);
-            _pictures.add(img);
-            try {
-                OutputStream out = img.getPackagePart().getOutputStream();
-                out.write(pictureData);
-                out.close();
-            } catch (IOException e) {
-                throw new POIXMLException(e);
-            }
-            return _pictures.size() - 1;
-        } else {
-            return _pictures.indexOf(img);
+        if (img != null) return img;
+        
+        int imageNumber = _pictures.size();
+        XSLFRelation relType = XSLFPictureData.getRelationForType(format);
+        if (relType == null) {
+            throw new IllegalArgumentException("Picture type "+format+" is not supported.");
+        }
+        img = (XSLFPictureData) createRelationship(relType, XSLFFactory.getInstance(), imageNumber + 1, true);
+        img.setIndex(imageNumber);
+        _pictures.add(img);
+        try {
+            OutputStream out = img.getPackagePart().getOutputStream();
+            out.write(pictureData);
+            out.close();
+        } catch (IOException e) {
+            throw new POIXMLException(e);
         }
+        
+        return img;
     }
 
     /**
@@ -492,7 +497,7 @@ public class XMLSlideShow extends POIXML
         return null;
     }
 
-    public MasterSheet createMasterSheet() throws IOException {
+    public MasterSheet<XSLFShape, XMLSlideShow> createMasterSheet() throws IOException {
         // TODO: implement!
         throw new UnsupportedOperationException();
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java Sun Aug  2 20:21:35 2015
@@ -23,7 +23,6 @@ import java.awt.geom.Rectangle2D;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.regex.Pattern;
 
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackageRelationship;
@@ -239,16 +238,8 @@ public class XSLFGroupShape extends XSLF
         return sh;
     }
 
-    public XSLFPictureShape createPicture(int pictureIndex){
-
-        List<PackagePart>  pics = getSheet().getPackagePart().getPackage()
-                .getPartsByName(Pattern.compile("/ppt/media/image" + (pictureIndex + 1) + ".*?"));
-
-        if(pics.size() == 0) {
-            throw new IllegalArgumentException("Picture with index=" + pictureIndex + " was not found");
-        }
-
-        PackagePart pic = pics.get(0);
+    public XSLFPictureShape createPicture(XSLFPictureData pictureData){
+        PackagePart pic = pictureData.getPackagePart();
 
         PackageRelationship rel = getSheet().getPackagePart().addRelationship(
                 pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
@@ -321,8 +312,8 @@ public class XSLFGroupShape extends XSLF
             } else if (shape instanceof XSLFPictureShape) {
                 XSLFPictureShape p = (XSLFPictureShape)shape;
                 XSLFPictureData pd = p.getPictureData();
-                int picId = getSheet().getSlideShow().addPicture(pd.getData(), pd.getPictureType());
-                newShape = createPicture(picId);
+                XSLFPictureData pdNew = getSheet().getSlideShow().addPicture(pd.getData(), pd.getType());
+                newShape = createPicture(pdNew);
             } else if (shape instanceof XSLFGroupShape) {
                 newShape = createGroup();
             } else if (shape instanceof XSLFTable) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java Sun Aug  2 20:21:35 2015
@@ -25,7 +25,6 @@ import java.io.OutputStream;
 
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLException;
-import org.apache.poi.POIXMLRelation;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.sl.usermodel.PictureData;
@@ -34,94 +33,11 @@ import org.apache.poi.util.IOUtils;
 
 /**
  * Instantiates sub-classes of POIXMLDocumentPart depending on their relationship type
- *
- * @author Yegor Kozlov
  */
 @Beta
 public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData {
-    /**
-     * Extended windows meta file
-     */
-    public static final int PICTURE_TYPE_EMF = 2;
-
-    /**
-     * Windows Meta File
-     */
-    public static final int PICTURE_TYPE_WMF = 3;
-
-    /**
-     * Mac PICT format
-     */
-    public static final int PICTURE_TYPE_PICT = 4;
-
-    /**
-     * JPEG format
-     */
-    public static final int PICTURE_TYPE_JPEG = 5;
-
-    /**
-     * PNG format
-     */
-    public static final int PICTURE_TYPE_PNG = 6;
-
-    /**
-     * Device independent bitmap
-     */
-    public static final int PICTURE_TYPE_DIB = 7;
-
-    /**
-     * GIF image format
-     */
-    public static final int PICTURE_TYPE_GIF = 8;
-
-    /**
-     * Tag Image File (.tiff)
-     */
-    public static final int PICTURE_TYPE_TIFF = 9;
-
-    /**
-     * Encapsulated Postscript (.eps)
-     */
-    public static final int PICTURE_TYPE_EPS = 10;
-
-
-    /**
-     * Windows Bitmap (.bmp)
-     */
-    public static final int PICTURE_TYPE_BMP = 11;
-
-    /**
-     * WordPerfect graphics (.wpg)
-     */
-    public static final int PICTURE_TYPE_WPG = 12;
-
-    /**
-     * Microsoft Windows Media Photo image (.wdp)
-     */
-    public static final int PICTURE_TYPE_WDP = 13;
-
-    /**
-     * Relationships for each known picture type
-     */
-    protected static final POIXMLRelation[] RELATIONS;
-
-    static {
-        RELATIONS = new POIXMLRelation[14];
-        RELATIONS[PICTURE_TYPE_EMF] = XSLFRelation.IMAGE_EMF;
-        RELATIONS[PICTURE_TYPE_WMF] = XSLFRelation.IMAGE_WMF;
-        RELATIONS[PICTURE_TYPE_PICT] = XSLFRelation.IMAGE_PICT;
-        RELATIONS[PICTURE_TYPE_JPEG] = XSLFRelation.IMAGE_JPEG;
-        RELATIONS[PICTURE_TYPE_PNG] = XSLFRelation.IMAGE_PNG;
-        RELATIONS[PICTURE_TYPE_DIB] = XSLFRelation.IMAGE_DIB;
-        RELATIONS[PICTURE_TYPE_GIF] = XSLFRelation.IMAGE_GIF;
-        RELATIONS[PICTURE_TYPE_TIFF] = XSLFRelation.IMAGE_TIFF;
-        RELATIONS[PICTURE_TYPE_EPS] = XSLFRelation.IMAGE_EPS;
-        RELATIONS[PICTURE_TYPE_BMP] = XSLFRelation.IMAGE_BMP;
-        RELATIONS[PICTURE_TYPE_WPG] = XSLFRelation.IMAGE_WPG;
-        RELATIONS[PICTURE_TYPE_WDP] = XSLFRelation.IMAGE_WDP;
-    }
-
     private Long checksum = null;
+    private int index = -1;
 
     /**
      * Create a new XSLFGraphicData node
@@ -150,12 +66,12 @@ public final class XSLFPictureData exten
     public InputStream getInputStream() throws IOException {
         return getPackagePart().getInputStream();
     }
-    
+
     /**
      * Gets the picture data as a byte array.
      *
      * You can grab the picture data directly from the underlying package part with the {@link #getInputStream()} method
-     * 
+     *
      * @return the Picture data.
      */
     public byte[] getData() {
@@ -187,25 +103,6 @@ public final class XSLFPictureData exten
         return getPackagePart().getPartName().getExtension();
     }
 
-    /**
-     * Return an integer constant that specifies type of this picture
-     *
-     * @return an integer constant that specifies type of this picture
-     */
-    public int getPictureType() {
-        String contentType = getPackagePart().getContentType();
-        for (int i = 0; i < RELATIONS.length; i++) {
-            if (RELATIONS[i] == null) {
-                continue;
-            }
-
-            if (RELATIONS[i].getContentType().equals(contentType)) {
-                return i;
-            }
-        }
-        return 0;
-    }
-
     long getChecksum(){
         if(checksum == null){
             try {
@@ -218,17 +115,17 @@ public final class XSLFPictureData exten
     }
 
     /**
-     * *PictureData objects store the actual content in the part directly without keeping a 
+     * *PictureData objects store the actual content in the part directly without keeping a
      * copy like all others therefore we need to handle them differently.
      */
     @Override
     protected void prepareForCommit() {
         // do not clear the part here
     }
-    
+
+    @Override
     public String getContentType() {
-        POIXMLRelation rel = RELATIONS[getPictureType()];
-        return (rel == null) ? null : rel.getContentType();
+        return getPackagePart().getContentType();
     }
 
     public void setData(byte[] data) throws IOException {
@@ -238,6 +135,65 @@ public final class XSLFPictureData exten
         // recalculate now since we already have the data bytes available anyhow
         checksum = IOUtils.calculateChecksum(data);
     }
+
+    @Override
+    public PictureType getType() {
+        String ct = getContentType();
+        if (XSLFRelation.IMAGE_EMF.getContentType().equals(ct)) {
+            return PictureType.EMF;
+        } else if (XSLFRelation.IMAGE_WMF.getContentType().equals(ct)) {
+            return PictureType.WMF;
+        } else if (XSLFRelation.IMAGE_PICT.getContentType().equals(ct)) {
+            return PictureType.PICT;
+        } else if (XSLFRelation.IMAGE_JPEG.getContentType().equals(ct)) {
+            return PictureType.JPEG;
+        } else if (XSLFRelation.IMAGE_PNG.getContentType().equals(ct)) {
+            return PictureType.PNG;
+        } else if (XSLFRelation.IMAGE_DIB.getContentType().equals(ct)) {
+            return PictureType.DIB;
+        } else if (XSLFRelation.IMAGE_GIF.getContentType().equals(ct)) {
+            return PictureType.GIF;
+        } else if (XSLFRelation.IMAGE_EPS.getContentType().equals(ct)) {
+            return PictureType.EPS;
+        } else if (XSLFRelation.IMAGE_BMP.getContentType().equals(ct)) {
+            return PictureType.BMP;
+        } else if (XSLFRelation.IMAGE_WPG.getContentType().equals(ct)) {
+            return PictureType.WPG;
+        } else if (XSLFRelation.IMAGE_WDP.getContentType().equals(ct)) {
+            return PictureType.WDP;
+        } else {
+            return null;
+        }
+    }
     
-    
+    /* package */ static XSLFRelation getRelationForType(PictureType pt) {
+        switch (pt) {
+            case EMF: return XSLFRelation.IMAGE_EMF;
+            case WMF: return XSLFRelation.IMAGE_WMF;
+            case PICT: return XSLFRelation.IMAGE_PICT;
+            case JPEG: return XSLFRelation.IMAGE_JPEG;
+            case PNG: return XSLFRelation.IMAGE_PNG;
+            case DIB: return XSLFRelation.IMAGE_DIB;
+            case GIF: return XSLFRelation.IMAGE_GIF;
+            case EPS: return XSLFRelation.IMAGE_EPS;
+            case BMP: return XSLFRelation.IMAGE_BMP;
+            case WPG: return XSLFRelation.IMAGE_WPG;
+            case WDP: return XSLFRelation.IMAGE_WDP;
+            default: return null;
+        }
+    }
+
+    /**
+     * @return the 0-based index of this pictures within the picture parts
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * @param index sets the 0-based index of this pictures within the picture parts
+     */
+    public void setIndex(int index) {
+        this.index = index;
+    }
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java Sun Aug  2 20:21:35 2015
@@ -21,15 +21,12 @@ import java.util.Map;
 
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLRelation;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.util.Beta;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 
 @Beta
 public class XSLFRelation extends POIXMLRelation {
 
-   private static final POILogger log = POILogFactory.getLogger(XSLFRelation.class);
-
    /**
     * A map to lookup POIXMLRelation by its relation type
     */
@@ -148,76 +145,76 @@ public class XSLFRelation extends POIXML
     );
 
     public static final XSLFRelation IMAGE_EMF = new XSLFRelation(
-          "image/x-emf",
+          PictureType.EMF.contentType,
           "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
           "/ppt/media/image#.emf",
           XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_WMF = new XSLFRelation(
-	      "image/x-wmf",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.wmf",
-	      XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_PICT = new XSLFRelation(
-	      "image/pict",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.pict",
-	      XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_JPEG = new XSLFRelation(
-	      "image/jpeg",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.jpeg",
-	      XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_PNG = new XSLFRelation(
-	      "image/png",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.png",
-	      XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_DIB = new XSLFRelation(
-	      "image/dib",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.dib",
-	      XSLFPictureData.class
-	);
-	public static final XSLFRelation IMAGE_GIF = new XSLFRelation(
-	      "image/gif",
-	      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-	      "/ppt/media/image#.gif",
-	      XSLFPictureData.class
-	);
+    );
+    public static final XSLFRelation IMAGE_WMF = new XSLFRelation(
+          PictureType.WMF.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.wmf",
+          XSLFPictureData.class
+    );
+    public static final XSLFRelation IMAGE_PICT = new XSLFRelation(
+          PictureType.PICT.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.pict",
+          XSLFPictureData.class
+    );
+    public static final XSLFRelation IMAGE_JPEG = new XSLFRelation(
+          PictureType.JPEG.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.jpeg",
+          XSLFPictureData.class
+    );
+    public static final XSLFRelation IMAGE_PNG = new XSLFRelation(
+          PictureType.PNG.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.png",
+          XSLFPictureData.class
+    );
+    public static final XSLFRelation IMAGE_DIB = new XSLFRelation(
+          PictureType.DIB.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.dib",
+          XSLFPictureData.class
+    );
+    public static final XSLFRelation IMAGE_GIF = new XSLFRelation(
+          PictureType.GIF.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.gif",
+          XSLFPictureData.class
+    );
     public static final XSLFRelation IMAGE_TIFF = new XSLFRelation(
-            "image/tiff",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/ppt/media/image#.tiff",
-            XSLFPictureData.class
+          PictureType.TIFF.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.tiff",
+          XSLFPictureData.class
     );
     public static final XSLFRelation IMAGE_EPS = new XSLFRelation(
-            "image/x-eps",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/ppt/media/image#.eps",
-            XSLFPictureData.class
+          PictureType.EPS.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.eps",
+          XSLFPictureData.class
     );
     public static final XSLFRelation IMAGE_BMP = new XSLFRelation(
-            "image/x-ms-bmp",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/ppt/media/image#.bmp",
-            XSLFPictureData.class
+          PictureType.BMP.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.bmp",
+          XSLFPictureData.class
     );
     public static final XSLFRelation IMAGE_WPG = new XSLFRelation(
-            "image/x-wpg",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/ppt/media/image#.wpg",
-            XSLFPictureData.class
+          PictureType.WPG.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.wpg",
+          XSLFPictureData.class
     );
     public static final XSLFRelation IMAGE_WDP = new XSLFRelation(
-            "image/vnd.ms-photo",
-            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
-            "/ppt/media/image#.wdp",
-            XSLFPictureData.class
+          PictureType.WDP.contentType,
+          "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
+          "/ppt/media/image#.wdp",
+          XSLFPictureData.class
     );
 
     public static final XSLFRelation IMAGES = new XSLFRelation(

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java Sun Aug  2 20:21:35 2015
@@ -55,7 +55,7 @@ public interface XSLFShapeContainer exte
     /**
      * create a picture belonging to this container
      */
-    XSLFPictureShape createPicture(int pictureIndex);
+    XSLFPictureShape createPicture(XSLFPictureData pictureData);
 
     /**
      * Removes all of the elements from this container (optional operation).

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java Sun Aug  2 20:21:35 2015
@@ -25,7 +25,6 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Pattern;
 
 import javax.xml.namespace.QName;
 
@@ -182,15 +181,8 @@ public abstract class XSLFSheet extends
         return sh;
     }
 
-    public XSLFPictureShape createPicture(int pictureIndex){
-        List<PackagePart>  pics = getPackagePart().getPackage()
-                .getPartsByName(Pattern.compile("/ppt/media/image" + (pictureIndex + 1) + ".*?"));
-
-        if(pics.size() == 0) {
-            throw new IllegalArgumentException("Picture with index=" + pictureIndex + " was not found");
-        }
-
-        PackagePart pic = pics.get(0);
+    public XSLFPictureShape createPicture(XSLFPictureData pictureData){
+        PackagePart pic = pictureData.getPackagePart();
 
         PackageRelationship rel = getPackagePart().addRelationship(
                 pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
@@ -525,8 +517,8 @@ public abstract class XSLFSheet extends
         XSLFPictureData data = new XSLFPictureData(blipPart, null);
 
         XMLSlideShow ppt = getSlideShow();
-        int pictureIdx = ppt.addPicture(data.getData(), data.getPictureType());
-        PackagePart pic = ppt.getAllPictures().get(pictureIdx).getPackagePart();
+        XSLFPictureData pictureData = ppt.addPicture(data.getData(), data.getType());
+        PackagePart pic = pictureData.getPackagePart();
 
         PackageRelationship rel = getPackagePart().addRelationship(
                 pic.getPartName(), TargetMode.INTERNAL, blipRel.getRelationshipType());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Sun Aug  2 20:21:35 2015
@@ -37,6 +37,7 @@ import javax.imageio.ImageIO;
 
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.xslf.usermodel.DrawingParagraph;
 import org.apache.poi.xslf.usermodel.DrawingTextBody;
 import org.apache.poi.xslf.usermodel.XMLSlideShow;
@@ -48,6 +49,8 @@ import org.apache.poi.xslf.usermodel.XSL
 import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
 import org.junit.Ignore;
 import org.junit.Test;
+
+
 public class TestXSLFBugs {
 
     @Test
@@ -56,7 +59,6 @@ public class TestXSLFBugs {
        XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("51187.pptx");
        
        assertEquals(1, ss.getSlides().size());
-       XSLFSlide slide = ss.getSlides().get(0);
        
        // Check the relations on it
        // Note - rId3 is a self reference
@@ -289,11 +291,11 @@ public class TestXSLFBugs {
         
         // Add a few pictures
         for (int i=0; i<10; i++) {
-            int idx = ss.addPicture(pics[i], XSLFPictureData.PICTURE_TYPE_JPEG);
-            assertEquals(i, idx);
+            XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
+            assertEquals(i, data.getIndex());
             assertEquals(i+1, ss.getAllPictures().size());
             
-            XSLFPictureShape shape = slide.createPicture(idx);
+            XSLFPictureShape shape = slide.createPicture(data);
             assertNotNull(shape.getPictureData());
             assertArrayEquals(pics[i], shape.getPictureData().getData());
             assertEquals(i+2, slide.getShapes().size());
@@ -307,11 +309,11 @@ public class TestXSLFBugs {
         
         // Add past 10
         for (int i=10; i<15; i++) {
-            int idx = ss.addPicture(pics[i], XSLFPictureData.PICTURE_TYPE_JPEG);
-            assertEquals(i, idx);
+            XSLFPictureData data = ss.addPicture(pics[i], PictureType.JPEG);
+            assertEquals(i, data.getIndex());
             assertEquals(i+1, ss.getAllPictures().size());
             
-            XSLFPictureShape shape = slide.createPicture(idx);
+            XSLFPictureShape shape = slide.createPicture(data);
             assertNotNull(shape.getPictureData());
             assertArrayEquals(pics[i], shape.getPictureData().getData());
             assertEquals(i+2, slide.getShapes().size());
@@ -324,11 +326,11 @@ public class TestXSLFBugs {
         }
         
         // Add a duplicate, check the right one is picked
-        int idx = ss.addPicture(pics[3], XSLFPictureData.PICTURE_TYPE_JPEG);
-        assertEquals(3, idx);
+        XSLFPictureData data = ss.addPicture(pics[3], PictureType.JPEG);
+        assertEquals(3, data.getIndex());
         assertEquals(15, ss.getAllPictures().size());
         
-        XSLFPictureShape shape = slide.createPicture(idx);
+        XSLFPictureShape shape = slide.createPicture(data);
         assertNotNull(shape.getPictureData());
         assertArrayEquals(pics[3], shape.getPictureData().getData());
         assertEquals(17, slide.getShapes().size());
@@ -351,11 +353,11 @@ public class TestXSLFBugs {
         assertArrayEquals(pics[3], shape.getPictureData().getData());
         
         // Add another duplicate
-        idx = ss.addPicture(pics[5], XSLFPictureData.PICTURE_TYPE_JPEG);
-        assertEquals(5, idx);
+        data = ss.addPicture(pics[5], PictureType.JPEG);
+        assertEquals(5, data.getIndex());
         assertEquals(15, ss.getAllPictures().size());
         
-        shape = slide.createPicture(idx);
+        shape = slide.createPicture(data);
         assertNotNull(shape.getPictureData());
         assertArrayEquals(pics[5], shape.getPictureData().getData());
         assertEquals(18, slide.getShapes().size());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java Sun Aug  2 20:21:35 2015
@@ -16,11 +16,17 @@
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
-import static org.junit.Assert.*;
-
-import java.util.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.junit.Test;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
 
@@ -35,21 +41,21 @@ public class TestXSLFPictureShape {
         assertEquals(0, ppt.getAllPictures().size());
         byte[] data1 = new byte[100];
         for(int i = 0;i < 100;i++) { data1[i] = (byte)i; }
-        int idx1 = ppt.addPicture(data1, XSLFPictureData.PICTURE_TYPE_JPEG);
-        assertEquals(0, idx1);
+        XSLFPictureData pdata1 = ppt.addPicture(data1, PictureType.JPEG);
+        assertEquals(0, pdata1.getIndex());
         assertEquals(1, ppt.getAllPictures().size());
 
         XSLFSlide slide = ppt.createSlide();
-        XSLFPictureShape shape1 = slide.createPicture(idx1);
+        XSLFPictureShape shape1 = slide.createPicture(pdata1);
         assertNotNull(shape1.getPictureData());
         assertArrayEquals(data1, shape1.getPictureData().getData());
 
         byte[] data2 = new byte[200];
         for(int i = 0;i < 200;i++) { data2[i] = (byte)i; }
-        int idx2 = ppt.addPicture(data2, XSLFPictureData.PICTURE_TYPE_PNG);
-        XSLFPictureShape shape2 = slide.createPicture(idx2);
+        XSLFPictureData pdata2 = ppt.addPicture(data2, PictureType.PNG);
+        XSLFPictureShape shape2 = slide.createPicture(pdata2);
         assertNotNull(shape2.getPictureData());
-        assertEquals(1, idx2);
+        assertEquals(1, pdata2.getIndex());
         assertEquals(2, ppt.getAllPictures().size());
         assertArrayEquals(data2, shape2.getPictureData().getData());
 
@@ -75,12 +81,11 @@ public class TestXSLFPictureShape {
         // first add 20 images to the slide
         for (int i = 0; i < 20; i++, pictureIndex++) {
             byte[] data = new byte[]{(byte)pictureIndex};
-            int elementIndex = ppt.addPicture(data,
-                    XSLFPictureData.PICTURE_TYPE_PNG);
-            assertEquals(pictureIndex, elementIndex);   // added images have indexes 0,1,2....19
-            XSLFPictureShape picture = slide1.createPicture(elementIndex);
+            XSLFPictureData elementData = ppt.addPicture(data, PictureType.PNG);
+            assertEquals(pictureIndex, elementData.getIndex());   // added images have indexes 0,1,2....19
+            XSLFPictureShape picture = slide1.createPicture(elementData);
             // POI saves images as image1.png, image2.png, etc.
-            String fileName = "image" + (elementIndex + 1) + ".png";
+            String fileName = "image" + (elementData.getIndex()+1) + ".png";
             assertEquals(fileName, picture.getPictureData().getFileName());
             assertArrayEquals(data, picture.getPictureData().getData());
         }
@@ -88,11 +93,10 @@ public class TestXSLFPictureShape {
         // and then add next 20 images to a group
         for (int i = 0; i < 20; i++, pictureIndex++) {
             byte[] data = new byte[]{(byte)pictureIndex};
-            int elementIndex = ppt.addPicture(data,
-                    XSLFPictureData.PICTURE_TYPE_PNG);
-            XSLFPictureShape picture = group1.createPicture(elementIndex);
+            XSLFPictureData elementData = ppt.addPicture(data, PictureType.PNG);
+            XSLFPictureShape picture = group1.createPicture(elementData);
             // POI saves images as image1.png, image2.png, etc.
-            assertEquals(pictureIndex, elementIndex);   // added images have indexes 0,1,2....19
+            assertEquals(pictureIndex, elementData.getIndex());   // added images have indexes 0,1,2....19
             String fileName = "image" + (pictureIndex + 1) + ".png";
             assertEquals(fileName, picture.getPictureData().getFileName());
             assertArrayEquals(data, picture.getPictureData().getData());
@@ -122,13 +126,13 @@ public class TestXSLFPictureShape {
         XMLSlideShow ppt = new XMLSlideShow();
         byte[] img1 = new byte[]{1,2,3};
         byte[] img2 = new byte[]{3,4,5};
-        int idx1 = ppt.addPicture(img1, XSLFPictureData.PICTURE_TYPE_PNG);
-        assertEquals(0, idx1);
-        assertEquals(0, ppt.addPicture(img1, XSLFPictureData.PICTURE_TYPE_PNG));
-
-        int idx2 = ppt.addPicture(img2, XSLFPictureData.PICTURE_TYPE_PNG);
-        assertEquals(1, idx2);
-        assertEquals(1, ppt.addPicture(img2, XSLFPictureData.PICTURE_TYPE_PNG));
+        XSLFPictureData pdata1 = ppt.addPicture(img1, PictureType.PNG);
+        assertEquals(0, pdata1.getIndex());
+        assertEquals(0, ppt.addPicture(img1, PictureType.PNG).getIndex());
+
+        XSLFPictureData idx2 = ppt.addPicture(img2, PictureType.PNG);
+        assertEquals(1, idx2.getIndex());
+        assertEquals(1, ppt.addPicture(img2, PictureType.PNG).getIndex());
 
         XSLFSlide slide1 = ppt.createSlide();
         assertNotNull(slide1);
@@ -141,10 +145,10 @@ public class TestXSLFPictureShape {
     public void testMerge() {
         XMLSlideShow ppt1 = new XMLSlideShow();
         byte[] data1 = new byte[100];
-        int idx1 = ppt1.addPicture(data1, XSLFPictureData.PICTURE_TYPE_JPEG);
+        XSLFPictureData pdata1 = ppt1.addPicture(data1, PictureType.JPEG);
 
         XSLFSlide slide1 = ppt1.createSlide();
-        XSLFPictureShape shape1 = slide1.createPicture(idx1);
+        XSLFPictureShape shape1 = slide1.createPicture(pdata1);
         CTPicture ctPic1 = (CTPicture)shape1.getXmlObject();
         ctPic1.getNvPicPr().getNvPr().addNewCustDataLst().addNewTags().setId("rId99");
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java Sun Aug  2 20:21:35 2015
@@ -25,11 +25,10 @@ import java.io.ByteArrayOutputStream;
 /**
  * Represents a bitmap picture data:  JPEG or PNG.
  * The data is not compressed and the exact file content is written in the stream.
- *
- * @author Yegor Kozlov
  */
-public abstract  class Bitmap extends HSLFPictureData {
+public abstract class Bitmap extends HSLFPictureData {
 
+    @Override
     public byte[] getData(){
         byte[] rawdata = getRawData();
         int prefixLen = 16*uidInstanceCount+1;
@@ -38,6 +37,7 @@ public abstract  class Bitmap extends HS
         return imgdata;
     }
 
+    @Override
     public void setData(byte[] data) throws IOException {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         for (int i=0; i<uidInstanceCount; i++) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java Sun Aug  2 20:21:35 2015
@@ -17,15 +17,12 @@
 
 package org.apache.poi.hslf.blip;
 
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
-import org.apache.poi.util.LittleEndian;
-
 import java.io.IOException;
 
+import org.apache.poi.util.LittleEndian;
+
 /**
  * Represents a DIB picture data in a PPT file
- *
- * @author Yegor Kozlov
  */
 public final class DIB extends Bitmap {
     /**
@@ -33,12 +30,9 @@ public final class DIB extends Bitmap {
      */
     private static final int HEADER_SIZE = 14;
 
-    /**
-     * @return type of  this picture
-     * @see  org.apache.poi.hslf.usermodel.HSLFPictureShape#DIB
-     */
-    public int getType(){
-        return HSLFPictureShape.DIB;
+    @Override
+    public PictureType getType(){
+        return PictureType.DIB;
     }
 
     /**
@@ -66,6 +60,7 @@ public final class DIB extends Bitmap {
         }        
     }    
     
+    @Override
     public byte[] getData(){
         return addBMPHeader ( super.getData() );
     }
@@ -99,14 +94,11 @@ public final class DIB extends Bitmap {
         return dib;
     }
 
+    @Override
     public void setData(byte[] data) throws IOException {
         //cut off the bitmap file-header
         byte[] dib = new byte[data.length-HEADER_SIZE];
         System.arraycopy(data, HEADER_SIZE, dib, 0, dib.length);
         super.setData(dib);
     }
-
-    public String getContentType() {
-        return "image/bmp";
-    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java Sun Aug  2 20:21:35 2015
@@ -24,19 +24,14 @@ import java.io.InputStream;
 import java.util.zip.InflaterInputStream;
 
 import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
 import org.apache.poi.util.Units;
 
 /**
  * Represents EMF (Windows Enhanced Metafile) picture data.
- *
- * @author Yegor Kozlov
  */
 public final class EMF extends Metafile {
 
-    /**
-     * Extract compressed EMF data from a ppt
-     */
+    @Override
     public byte[] getData(){
         try {
             byte[] rawdata = getRawData();
@@ -60,6 +55,7 @@ public final class EMF extends Metafile
         }
     }
 
+    @Override
     public void setData(byte[] data) throws IOException {
         byte[] compressed = compress(data, 0, data.length);
 
@@ -79,8 +75,9 @@ public final class EMF extends Metafile
         setRawData(out.toByteArray());
     }
 
-    public int getType(){
-        return HSLFPictureShape.EMF;
+    @Override
+    public PictureType getType(){
+        return PictureType.EMF;
     }
 
     /**
@@ -107,8 +104,4 @@ public final class EMF extends Metafile
                 throw new IllegalArgumentException(signature+" is not a valid instance/signature value for EMF");
         }        
     }
-
-    public String getContentType() {
-        return "image/x-emf";
-    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java Sun Aug  2 20:21:35 2015
@@ -17,12 +17,9 @@
 
 package org.apache.poi.hslf.blip;
 
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
 
 /**
  * Represents a JPEG picture data in a PPT file
- *
- * @author Yegor Kozlov
  */
 public final class JPEG extends Bitmap {
 
@@ -30,12 +27,9 @@ public final class JPEG extends Bitmap {
     
     private ColorSpace colorSpace = ColorSpace.rgb;
     
-    /**
-     * @return type of  this picture
-     * @see  org.apache.poi.hslf.usermodel.HSLFPictureShape#JPEG
-     */
-    public int getType(){
-        return HSLFPictureShape.JPEG;
+    @Override
+    public PictureType getType(){
+        return PictureType.JPEG;
     }
 
     public ColorSpace getColorSpace() {
@@ -82,8 +76,4 @@ public final class JPEG extends Bitmap {
                 throw new IllegalArgumentException(signature+" is not a valid instance/signature value for JPEG");
         }        
     }
-
-    public String getContentType() {
-        return "image/jpeg";
-    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java Sun Aug  2 20:21:35 2015
@@ -23,19 +23,14 @@ import java.io.IOException;
 import java.util.zip.InflaterInputStream;
 
 import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
 import org.apache.poi.util.Units;
 
 /**
  * Represents Macintosh PICT picture data.
- *
- * @author Yegor Kozlov
  */
 public final class PICT extends Metafile {
 
-    /**
-     * Extract compressed PICT data from a ppt
-     */
+    @Override
     public byte[] getData(){
         byte[] rawdata = getRawData();
         try {
@@ -74,6 +69,7 @@ public final class PICT extends Metafile
         return out.toByteArray();
     }
 
+    @Override
     public void setData(byte[] data) throws IOException {
         int pos = 512; //skip the first 512 bytes - they are MAC specific crap
         byte[] compressed = compress(data, pos, data.length-pos);
@@ -97,11 +93,9 @@ public final class PICT extends Metafile
         setRawData(out.toByteArray());
     }
 
-    /**
-     * @see org.apache.poi.hslf.usermodel.HSLFPictureShape#PICT
-     */
-    public int getType(){
-        return HSLFPictureShape.PICT;
+    @Override
+    public PictureType getType(){
+        return PictureType.PICT;
     }
 
     /**
@@ -128,9 +122,4 @@ public final class PICT extends Metafile
                 throw new IllegalArgumentException(signature+" is not a valid instance/signature value for PICT");
         }        
     }
-
-    public String getContentType() {
-        return "image/x-pict";
-    }
-
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java Sun Aug  2 20:21:35 2015
@@ -17,19 +17,14 @@
 
 package org.apache.poi.hslf.blip;
 
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
 import org.apache.poi.util.PngUtils;
 
 /**
  * Represents a PNG picture data in a PPT file
- *
- * @author Yegor Kozlov
  */
 public final class PNG extends Bitmap {
 
-    /**
-     * @return PNG data
-     */
+    @Override
     public byte[] getData() {
         byte[] data = super.getData();
 
@@ -44,12 +39,9 @@ public final class PNG extends Bitmap {
         return data;
     }
 
-    /**
-     * @return type of  this picture
-     * @see  org.apache.poi.hslf.usermodel.HSLFPictureShape#PNG
-     */
-    public int getType(){
-        return HSLFPictureShape.PNG;
+    @Override
+    public PictureType getType(){
+        return PictureType.PNG;
     }
 
     /**
@@ -76,8 +68,4 @@ public final class PNG extends Bitmap {
                 throw new IllegalArgumentException(signature+" is not a valid instance/signature value for PNG");
         }        
     }
-
-    public String getContentType() {
-        return "image/png";
-    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java Sun Aug  2 20:21:35 2015
@@ -25,21 +25,16 @@ import java.io.OutputStream;
 import java.util.zip.InflaterInputStream;
 
 import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.usermodel.HSLFPictureShape;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.Units;
 
 /**
  * Represents a WMF (Windows Metafile) picture data.
- *
- * @author Yegor Kozlov
  */
 public final class WMF extends Metafile {
 
-    /**
-     * Extract compressed WMF data from a ppt
-     */
+    @Override
     public byte[] getData(){
         try {
             byte[] rawdata = getRawData();
@@ -70,6 +65,7 @@ public final class WMF extends Metafile
         }
     }
 
+    @Override
     public void setData(byte[] data) throws IOException {
         int pos = 0;
         AldusHeader aldus = new AldusHeader();
@@ -97,11 +93,9 @@ public final class WMF extends Metafile
         setRawData(out.toByteArray());
     }
 
-    /**
-     * We are of type <code>Picture.WMF</code>
-     */
-    public int getType(){
-        return HSLFPictureShape.WMF;
+    @Override
+    public PictureType getType(){
+        return PictureType.WMF;
     }
 
     /**
@@ -208,10 +202,4 @@ public final class WMF extends Metafile
             return 22;
         }
     }
-
-
-    public String getContentType() {
-        return "image/x-wmf";
-    }
-
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java Sun Aug  2 20:21:35 2015
@@ -18,6 +18,7 @@
 package org.apache.poi.hslf.extractor;
 
 import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 
 import java.io.IOException;
 import java.io.FileOutputStream;
@@ -44,31 +45,8 @@ public final class ImageExtractor {
             // picture data
             byte[] data = pict.getData();
 
-            int type = pict.getType();
-            String ext;
-            switch (type) {
-                case HSLFPictureShape.JPEG:
-                    ext = ".jpg";
-                    break;
-                case HSLFPictureShape.PNG:
-                    ext = ".png";
-                    break;
-                case HSLFPictureShape.WMF:
-                    ext = ".wmf";
-                    break;
-                case HSLFPictureShape.EMF:
-                    ext = ".emf";
-                    break;
-                case HSLFPictureShape.PICT:
-                    ext = ".pict";
-                    break;
-                case HSLFPictureShape.DIB:
-                    ext = ".dib";
-                    break;
-                default:
-                    continue;
-            }
-            FileOutputStream out = new FileOutputStream("pict_" + i + ext);
+            PictureType type = pict.getType();
+            FileOutputStream out = new FileOutputStream("pict_" + i + type.extension);
             out.write(data);
             out.close();
         }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java Sun Aug  2 20:21:35 2015
@@ -52,10 +52,10 @@ public final class ActiveXShape extends
     /**
      * Create a new <code>Picture</code>
      *
-    * @param pictureIdx the index of the picture
+    * @param pictureData the picture data
      */
-    public ActiveXShape(int movieIdx, int pictureIdx){
-        super(pictureIdx, null);
+    public ActiveXShape(int movieIdx, HSLFPictureData pictureData){
+        super(pictureData, null);
         setActiveXIndex(movieIdx);
     }
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java Sun Aug  2 20:21:35 2015
@@ -41,10 +41,10 @@ public final class MovieShape extends HS
     /**
      * Create a new <code>Picture</code>
      *
-    * @param pictureIdx the index of the picture
+    * @param pictureData the picture data
      */
-    public MovieShape(int movieIdx, int pictureIdx){
-        super(pictureIdx, null);
+    public MovieShape(int movieIdx, HSLFPictureData pictureData){
+        super(pictureData, null);
         setMovieIndex(movieIdx);
         setAutoPlay(true);
     }
@@ -52,11 +52,11 @@ public final class MovieShape extends HS
     /**
      * Create a new <code>Picture</code>
      *
-     * @param idx the index of the picture
+     * @param pictureData the picture data
      * @param parent the parent shape
      */
-    public MovieShape(int movieIdx, int idx, ShapeContainer<HSLFShape> parent) {
-        super(idx, parent);
+    public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer<HSLFShape> parent) {
+        super(pictureData, parent);
         setMovieIndex(movieIdx);
     }
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java Sun Aug  2 20:21:35 2015
@@ -39,10 +39,10 @@ public final class OLEShape extends HSLF
     /**
      * Create a new <code>OLEShape</code>
      *
-    * @param idx the index of the picture
+    * @param data the picture data
      */
-    public OLEShape(int idx){
-        super(idx);
+    public OLEShape(HSLFPictureData data){
+        super(data);
     }
 
     /**
@@ -51,8 +51,8 @@ public final class OLEShape extends HSLF
      * @param idx the index of the picture
      * @param parent the parent shape
      */
-    public OLEShape(int idx, ShapeContainer<HSLFShape> parent) {
-        super(idx, parent);
+    public OLEShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) {
+        super(data, parent);
     }
 
     /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java Sun Aug  2 20:21:35 2015
@@ -295,16 +295,14 @@ public final class HSLFFill {
     /**
      * Assign picture used to fill the underlying shape.
      *
-     * @param idx 0-based index of the picture added to this ppt by <code>SlideShow.addPicture</code> method.
+     * @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method.
      */
-    public void setPictureData(int idx){
+    public void setPictureData(HSLFPictureData data){
         EscherOptRecord opt = shape.getEscherOptRecord();
-        HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx);
-        if( idx != 0 ) {
-            if( shape.getSheet() != null ) {
-                EscherBSERecord bse = getEscherBSERecord(idx);
-                bse.setRef(bse.getRef() + 1);
-            }
+        HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), (data == null ? 0 : data.getIndex()));
+        if(data != null && shape.getSheet() != null) {
+            EscherBSERecord bse = getEscherBSERecord(data.getIndex());
+            bse.setRef(bse.getRef() + 1);
         }
     }
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java Sun Aug  2 20:21:35 2015
@@ -54,35 +54,13 @@ public abstract class HSLFPictureData im
      * The instance type/signatures defines if one or two UID instances will be included
      */
     protected int uidInstanceCount = 1;
-    
-    /**
-     * Returns type of this picture.
-     * Must be one of the static constants defined in the <code>Picture<code> class.
-     *
-     * @return type of this picture.
-     */
-    public abstract int getType();
-
 
     /**
-     * Returns content type (mime type) of this picture.
-     *
-     * @return content type of this picture.
+     * The 1-based index within the pictures stream 
      */
-    public abstract String getContentType();
+    protected int index = -1;
     
     /**
-     * Returns the binary data of this Picture
-     * @return picture data
-     */
-    public abstract byte[] getData();
-
-    /**
-     *  Set picture data
-     */
-    public abstract void setData(byte[] data) throws IOException;
-
-    /**
      * Blip signature.
      */
     protected abstract int getSignature();
@@ -159,7 +137,8 @@ public abstract class HSLFPictureData im
         out.write(data);
 
         data = new byte[LittleEndian.SHORT_SIZE];
-        LittleEndian.putUShort(data, 0, getType() + 0xF018);
+        PictureType pt = getType();
+        LittleEndian.putUShort(data, 0, pt.nativeId + 0xF018);
         out.write(data);
 
         byte[] rawdata = getRawData();
@@ -178,27 +157,15 @@ public abstract class HSLFPictureData im
      * Must be one of the static constants defined in the <code>Picture<code> class.
      * @return concrete instance of <code>PictureData</code>
      */
-     public static HSLFPictureData create(int type){
+     public static HSLFPictureData create(PictureType type){
         HSLFPictureData pict;
         switch (type){
-            case HSLFPictureShape.EMF:
-                pict = new EMF();
-                break;
-            case HSLFPictureShape.WMF:
-                pict = new WMF();
-                break;
-            case HSLFPictureShape.PICT:
-                pict = new PICT();
-                break;
-            case HSLFPictureShape.JPEG:
-                pict = new JPEG();
-                break;
-            case HSLFPictureShape.PNG:
-                pict = new PNG();
-                break;
-            case HSLFPictureShape.DIB:
-                pict = new DIB();
-                break;
+            case EMF: pict = new EMF(); break;
+            case WMF: pict = new WMF(); break;
+            case PICT: pict = new PICT(); break;
+            case JPEG: pict = new JPEG(); break;
+            case PNG: pict = new PNG(); break;
+            case DIB: pict = new DIB(); break;
             default:
                 throw new IllegalArgumentException("Unsupported picture type: " + type);
         }
@@ -231,4 +198,23 @@ public abstract class HSLFPictureData im
     public int getSize(){
         return getData().length;
     }
+
+    /**
+     * @return the 1-based index of this pictures within the pictures stream
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * @param index sets the 1-based index of this pictures within the pictures stream
+     */
+    public void setIndex(int index) {
+        this.index = index;
+    }
+    
+    @Override
+    public final String getContentType() {
+        return getType().contentType;
+    }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java Sun Aug  2 20:21:35 2015
@@ -52,42 +52,12 @@ import org.apache.poi.util.Units;
 public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
 
     /**
-    *  Windows Enhanced Metafile (EMF)
-    */
-    public static final int EMF = 2;
-
-    /**
-    *  Windows Metafile (WMF)
-    */
-    public static final int WMF = 3;
-
-    /**
-    * Macintosh PICT
-    */
-    public static final int PICT = 4;
-
-    /**
-    *  JPEG
-    */
-    public static final int JPEG = 5;
-
-    /**
-    *  PNG
-    */
-    public static final int PNG = 6;
-
-    /**
-     * Windows DIB (BMP)
-     */
-    public static final byte DIB = 7;
-
-    /**
      * Create a new <code>Picture</code>
      *
     * @param idx the index of the picture
      */
-    public HSLFPictureShape(int idx){
-        this(idx, null);
+    public HSLFPictureShape(HSLFPictureData data){
+        this(data, null);
     }
 
     /**
@@ -96,9 +66,9 @@ public class HSLFPictureShape extends HS
      * @param idx the index of the picture
      * @param parent the parent shape
      */
-    public HSLFPictureShape(int idx, ShapeContainer<HSLFShape> parent) {
+    public HSLFPictureShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) {
         super(null, parent);
-        _escherContainer = createSpContainer(idx, parent instanceof HSLFGroupShape);
+        _escherContainer = createSpContainer(data.getIndex(), parent instanceof HSLFGroupShape);
     }
 
     /**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Sun Aug  2 20:21:35 2015
@@ -25,46 +25,31 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.poi.ddf.EscherBSERecord;
 import org.apache.poi.ddf.EscherContainerRecord;
 import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hpsf.ClassID;
 import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
 import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.record.DocumentAtom;
-import org.apache.poi.hslf.record.ExAviMovie;
-import org.apache.poi.hslf.record.ExControl;
-import org.apache.poi.hslf.record.ExEmbed;
-import org.apache.poi.hslf.record.ExEmbedAtom;
-import org.apache.poi.hslf.record.ExHyperlink;
-import org.apache.poi.hslf.record.ExHyperlinkAtom;
-import org.apache.poi.hslf.record.ExMCIMovie;
-import org.apache.poi.hslf.record.ExObjList;
-import org.apache.poi.hslf.record.ExObjListAtom;
-import org.apache.poi.hslf.record.ExOleObjAtom;
-import org.apache.poi.hslf.record.ExOleObjStg;
-import org.apache.poi.hslf.record.ExVideoContainer;
-import org.apache.poi.hslf.record.FontCollection;
-import org.apache.poi.hslf.record.FontEntityAtom;
-import org.apache.poi.hslf.record.HeadersFootersContainer;
-import org.apache.poi.hslf.record.PersistPtrHolder;
-import org.apache.poi.hslf.record.PositionDependentRecord;
-import org.apache.poi.hslf.record.PositionDependentRecordContainer;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.SlideListWithText;
+import org.apache.poi.hslf.model.HeadersFooters;
+import org.apache.poi.hslf.model.MovieShape;
+import org.apache.poi.hslf.model.PPFont;
+import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
-import org.apache.poi.hslf.record.SlidePersistAtom;
-import org.apache.poi.hslf.record.UserEditAtom;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.MasterSheet;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.apache.poi.sl.usermodel.Resources;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.Units;
@@ -752,19 +737,20 @@ public final class HSLFSlideShow impleme
 		return slide;
 	}
 
-	/**
-	 * Adds a picture to this presentation and returns the associated index.
-	 *
-	 * @param data
-	 *            picture data
-	 * @param format
-	 *            the format of the picture. One of constans defined in the
-	 *            <code>Picture</code> class.
-	 * @return the index to this picture (1 based).
-	 */
-	public int addPicture(byte[] data, int format) throws IOException {
-		byte[] uid = HSLFPictureData.getChecksum(data);
+	@Override
+	public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
+	    if (format == null || format.nativeId == -1) {
+	        throw new IllegalArgumentException("Unsupported picture format: " + format); 
+	    }
+	    
+	    byte[] uid = HSLFPictureData.getChecksum(data);
 
+		for (HSLFPictureData pd : getPictureData()) {
+		    if (Arrays.equals(pd.getUID(), uid)) {
+		        return pd;
+		    }
+		}
+		
 		EscherContainerRecord bstore;
 
 		EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
@@ -775,14 +761,6 @@ public final class HSLFSlideShow impleme
 			bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
 
 			dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
-		} else {
-			Iterator<EscherRecord> iter = bstore.getChildIterator();
-			for (int i = 0; iter.hasNext(); i++) {
-				EscherBSERecord bse = (EscherBSERecord) iter.next();
-				if (Arrays.equals(bse.getUid(), uid)) {
-					return i + 1;
-				}
-			}
 		}
 
 		HSLFPictureData pict = HSLFPictureData.create(format);
@@ -792,19 +770,20 @@ public final class HSLFSlideShow impleme
 
 		EscherBSERecord bse = new EscherBSERecord();
 		bse.setRecordId(EscherBSERecord.RECORD_ID);
-		bse.setOptions((short) (0x0002 | (format << 4)));
+		bse.setOptions((short) (0x0002 | (format.nativeId << 4)));
 		bse.setSize(pict.getRawData().length + 8);
 		bse.setUid(uid);
 
-		bse.setBlipTypeMacOS((byte) format);
-		bse.setBlipTypeWin32((byte) format);
+		bse.setBlipTypeMacOS((byte) format.nativeId);
+		bse.setBlipTypeWin32((byte) format.nativeId);
 
-		if (format == HSLFPictureShape.EMF)
-			bse.setBlipTypeMacOS((byte) HSLFPictureShape.PICT);
-		else if (format == HSLFPictureShape.WMF)
-			bse.setBlipTypeMacOS((byte) HSLFPictureShape.PICT);
-		else if (format == HSLFPictureShape.PICT)
-			bse.setBlipTypeWin32((byte) HSLFPictureShape.WMF);
+		if (format == PictureType.EMF) {
+			bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
+		} else if (format == PictureType.WMF) {
+			bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
+		} else if (format == PictureType.PICT) {
+			bse.setBlipTypeWin32((byte) PictureType.WMF.nativeId);
+		}
 
 		bse.setRef(0);
 		bse.setOffset(offset);
@@ -814,7 +793,7 @@ public final class HSLFSlideShow impleme
 		int count = bstore.getChildRecords().size();
 		bstore.setOptions((short) ((count << 4) | 0xF));
 
-		return count;
+		return pict;
 	}
 
 	/**
@@ -827,7 +806,7 @@ public final class HSLFSlideShow impleme
 	 *            <code>Picture</code> class.
 	 * @return the index to this picture (1 based).
 	 */
-	public int addPicture(File pict, int format) throws IOException {
+	public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
 		int length = (int) pict.length();
 		byte[] data = new byte[length];
         FileInputStream is = null;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java?rev=1693825&r1=1693824&r2=1693825&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java Sun Aug  2 20:21:35 2015
@@ -52,6 +52,7 @@ import org.apache.poi.poifs.filesystem.D
 import org.apache.poi.poifs.filesystem.EntryUtils;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -407,13 +408,14 @@ public final class HSLFSlideShowImpl ext
 			}
 
 			// If they type (including the bonus 0xF018) is 0, skip it
-			if(type == 0) {
+			PictureType pt = PictureType.forNativeID(type - 0xF018);
+			if(type == 0 || pt == null) {
 				logger.log(POILogger.ERROR, "Problem reading picture: Invalid image type 0, on picture with length " + imgsize + ".\nYou document will probably become corrupted if you save it!");
 				logger.log(POILogger.ERROR, "" + pos);
 			} else {
 				// Build the PictureData object from the data
-				try {
-					HSLFPictureData pict = HSLFPictureData.create(type - 0xF018);
+                try {
+					HSLFPictureData pict = HSLFPictureData.create(pt);
 
                     // Copy the data, ready to pass to PictureData
                     byte[] imgdata = new byte[imgsize];
@@ -421,6 +423,7 @@ public final class HSLFSlideShowImpl ext
                     pict.setRawData(imgdata);
 
                     pict.setOffset(offset);
+                    pict.setIndex(_pictures.size());
 					_pictures.add(pict);
 				} catch(IllegalArgumentException e) {
 					logger.log(POILogger.ERROR, "Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
@@ -711,6 +714,7 @@ public final class HSLFSlideShowImpl ext
 	      offset = prev.getOffset() + prev.getRawData().length + 8;
 	   }
 	   img.setOffset(offset);
+	   img.setIndex(_pictures.size()+1);
 	   _pictures.add(img);
 	   return offset;
    }



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


Mime
View raw message