poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r629170 - in /poi/branches/ooxml/src: java/org/apache/poi/hssf/usermodel/ ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/ ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/xssf/user...
Date Tue, 19 Feb 2008 17:34:51 GMT
Author: ugo
Date: Tue Feb 19 09:34:39 2008
New Revision: 629170

URL: http://svn.apache.org/viewvc?rev=629170&view=rev
Log:
Return a list of all pictures for a workbook. This shows a discrepancy between the way pictures
are stored in OLE2 files and the way they are stored in OOXML files. In the former case, pictures
are associated with the workbook, in the latter they are referred to in "drawings" which are,
in turn, referred to in sheets.

Added:
    poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
  (with props)
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
  (with props)
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java 
 (with props)
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/data/picture.xlsx   (with props)
Modified:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java?rev=629170&r1=629169&r2=629170&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java Tue Feb
19 09:34:39 2008
@@ -17,15 +17,15 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import org.apache.poi.ddf.EscherBitmapBlip;
 import org.apache.poi.ddf.EscherBlipRecord;
+import org.apache.poi.ss.usermodel.PictureData;
 
 /**
  * Represents binary data stored in the file.  Eg. A GIF, JPEG etc...
  *
  * @author Daniel Noll
  */
-public class HSSFPictureData
+public class HSSFPictureData implements PictureData
 {
     // MSOBI constants for various formats.
     public static final short MSOBI_WMF   = 0x2160;
@@ -52,20 +52,16 @@
         this.blip = blip;
     }
 
-    /**
-     * Gets the picture data.
-     *
-     * @return the picture data.
+    /* (non-Javadoc)
+     * @see org.apache.poi.hssf.usermodel.PictureData#getData()
      */
     public byte[] getData()
     {
         return blip.getPicturedata();
     }
 
-    /**
-     * Suggests a file extension for this image.
-     *
-     * @return the file extension.
+    /* (non-Javadoc)
+     * @see org.apache.poi.hssf.usermodel.PictureData#suggestFileExtension()
      */
     public String suggestFileExtension()
     {

Added: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java?rev=629170&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
(added)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
Tue Feb 19 09:34:39 2008
@@ -0,0 +1,20 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+public interface PictureData {}
\ No newline at end of file

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java?rev=629170&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
(added)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
Tue Feb 19 09:34:39 2008
@@ -0,0 +1,36 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+public interface PictureData {
+
+    /**
+     * Gets the picture data.
+     *
+     * @return the picture data.
+     */
+    byte[] getData();
+
+    /**
+     * Suggests a file extension for this image.
+     *
+     * @return the file extension.
+     */
+    String suggestFileExtension();
+
+}
\ No newline at end of file

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/PictureData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=629170&r1=629169&r2=629170&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java Tue Feb 19 09:34:39
2008
@@ -65,7 +65,14 @@
         return this.corePart;
     }
 
-    protected PackagePart getPart(PackageRelationship rel) throws InvalidFormatException
{
+    /**
+     * Get the PackagePart that is the target of a relationship.
+     * 
+     * @param rel The relationship
+     * @return The target part
+     * @throws InvalidFormatException
+     */
+    protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
{
         PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
         PackagePart part = getPackage().getPart(relName);
         if (part == null) {

Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java?rev=629170&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java Tue
Feb 19 09:34:39 2008
@@ -0,0 +1,42 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.PictureData;
+import org.openxml4j.opc.PackagePart;
+
+
+public class XSSFPictureData implements PictureData {
+
+    private PackagePart packagePart;
+    
+    public XSSFPictureData(PackagePart packagePart) {
+        this.packagePart = packagePart;
+    }
+
+    public byte[] getData() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String suggestFileExtension() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=629170&r1=629169&r2=629170&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Tue Feb
19 09:34:39 2008
@@ -17,6 +17,7 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -28,6 +29,7 @@
 import org.apache.poi.ss.usermodel.Footer;
 import org.apache.poi.ss.usermodel.Header;
 import org.apache.poi.ss.usermodel.Patriarch;
+import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.PrintSetup;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=629170&r1=629169&r2=629170&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Tue
Feb 19 09:34:39 2008
@@ -31,6 +31,7 @@
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Palette;
+import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.SharedStringSource;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -66,6 +67,10 @@
 
     private static final String SHARED_STRINGS_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
     
+    private static final String DRAWING_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
+    
+    private static final String IMAGE_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
+    
     private CTWorkbook workbook;
     
     private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
@@ -92,17 +97,15 @@
             Iterator<PackageRelationship> it = prc.iterator();
             if (it.hasNext()) { 
                 PackageRelationship rel = it.next();
-                PackagePart part = getPart(rel);
+                PackagePart part = getTargetPart(rel);
                 this.sharedStringSource = new SharedStringsTable(part);
             }
             // Load individual sheets
             for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
-                PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId());
-                if (rel == null) {
-                    log.log(log.WARN, "No relationship found for sheet " + ctSheet.getId());
+                PackagePart part = getPackagePart(ctSheet);
+                if (part == null) {
                     continue;
                 }
-                PackagePart part = getPart(rel);
                 WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream());
                 XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet(), this);
                 this.sheets.add(sheet);
@@ -117,6 +120,22 @@
     protected CTWorkbook getWorkbook() {
         return this.workbook;
     }
+
+    /**
+     * Get the PackagePart corresponding to a given sheet.
+     * 
+     * @param ctSheet The sheet
+     * @return A PackagePart, or null if no matching part found.
+     * @throws InvalidFormatException
+     */
+    private PackagePart getPackagePart(CTSheet ctSheet) throws InvalidFormatException {
+        PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId());
+        if (rel == null) {
+            log.log(POILogger.WARN, "No relationship found for sheet " + ctSheet.getId());
+            return null;
+        }
+        return getTargetPart(rel);
+    }
     
     public int addPicture(byte[] pictureData, int format) {
         // TODO Auto-generated method stub
@@ -209,9 +228,30 @@
         return null;
     }
 
-    public List getAllPictures() {
-        // TODO Auto-generated method stub
-        return null;
+    public List<PictureData> getAllPictures() {
+        // In OOXML pictures are referred to in sheets
+        List<PictureData> pictures = new LinkedList<PictureData>();
+        for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
+            try {
+                PackagePart sheetPart = getPackagePart(ctSheet);
+                if (sheetPart == null) {
+                    continue;
+                }
+                PackageRelationshipCollection prc = sheetPart.getRelationshipsByType(DRAWING_RELATIONSHIP);
+                for (PackageRelationship rel : prc) {
+                    PackagePart drawingPart = getTargetPart(rel);
+                    PackageRelationshipCollection prc2 = drawingPart.getRelationshipsByType(IMAGE_RELATIONSHIP);
+                    for (PackageRelationship rel2 : prc2) {
+                        PackagePart imagePart = getTargetPart(rel2);
+                        XSSFPictureData pd = new XSSFPictureData(imagePart);
+                        pictures.add(pd);
+                    }
+                }
+            } catch (InvalidFormatException e) {
+                throw new RuntimeException(e.getMessage(), e);
+            }
+        }
+        return pictures;
     }
 
     public boolean getBackupFlag() {

Added: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/data/picture.xlsx
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/data/picture.xlsx?rev=629170&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/data/picture.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java?rev=629170&r1=629169&r2=629170&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java Tue
Feb 19 09:34:39 2008
@@ -18,11 +18,13 @@
 package org.apache.poi.xssf.io;
 
 import java.io.File;
+import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -61,6 +63,12 @@
         Cell cell = row.getCell((short) 0);
         CellStyle style = cell.getCellStyle();
         // assertNotNull(style);
+    }
+    
+    public void testLoadPictures() throws Exception {
+        XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "picture.xlsx").getAbsolutePath());
+        List<PictureData> pictures = workbook.getAllPictures();
+        assertEquals(1, pictures.size());
     }
 
 }



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


Mime
View raw message