poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r997037 - in /poi/trunk/src/ooxml: java/org/apache/poi/util/OOXMLLite.java java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java java/org/apache/poi/xwpf/usermodel/XWPFRun.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
Date Tue, 14 Sep 2010 18:50:10 GMT
Author: nick
Date: Tue Sep 14 18:50:10 2010
New Revision: 997037

URL: http://svn.apache.org/viewvc?rev=997037&view=rev
Log:
Various XWPF picture tweaks and more unit tests
Note that XWPFRun -> XWPFPicture currently only works with the full ooxml schemas file,
and not with poi-ooxml-schemas, due to some sort of missing resources around the namespace
switch

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/util/OOXMLLite.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/util/OOXMLLite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/OOXMLLite.java?rev=997037&r1=997036&r2=997037&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/OOXMLLite.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/OOXMLLite.java Tue Sep 14 18:50:10 2010
@@ -129,10 +129,9 @@ public final class OOXMLLite {
         JarFile jar = new  JarFile(_ooxmlJar);
         for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){
             JarEntry je = e.nextElement();
-            if(je.getName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")){
-                File destFile = new File(_destDest, je.getName());
-                //System.out.println(je.getName() + "  -->  " + destFile);
-                copyFile(jar.getInputStream(je), destFile);
+            if(je.getName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb"))
{
+                 File destFile = new File(_destDest, je.getName());
+                 copyFile(jar.getInputStream(je), destFile);
             }
         }
         jar.close();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java?rev=997037&r1=997036&r2=997037&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java Tue Sep 14
18:50:10 2010
@@ -93,6 +93,18 @@ public class XWPFPictureData extends POI
     }
     
     /**
+     * Returns the file name of the image, eg image7.jpg .
+     * The original filename isn't always available, but if it
+     *  can be found it's likely to be in the CTDrawing 
+     */
+    public String getFileName() {
+       String name = getPackagePart().getPartName().getName();
+       if(name == null)
+          return null;
+       return name.substring(name.lastIndexOf('/') + 1);
+    }
+    
+    /**
      * Suggests a file extension for this image.
      *
      * @return the file extension.
@@ -123,6 +135,4 @@ public class XWPFPictureData extends POI
         }
         return 0;
     }
-    
-    
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=997037&r1=997036&r2=997037&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Tue Sep 14 18:50:10
2010
@@ -26,6 +26,7 @@ import org.apache.poi.util.Internal;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlString;
+import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
@@ -94,9 +95,10 @@ public class XWPFRun {
                  .selectPath("declare namespace pic='http://schemas.openxmlformats.org/drawingml/2006/picture'
.//pic:pic");
            for(XmlObject pict : picts) {
               if(pict instanceof org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture)
{
-                 pictures.add(new XWPFPicture(
+                 XWPFPicture picture = new XWPFPicture(
                        (org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture)pict,
p
-                 ));
+                 );
+                 pictures.add(picture);
               }
            }
         }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java?rev=997037&r1=997036&r2=997037&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java Tue
Sep 14 18:50:10 2010
@@ -38,6 +38,9 @@ import org.openxmlformats.schemas.wordpr
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
+import        org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
+import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
+import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
 
 /**
  * Tests for XWPF Paragraphs
@@ -250,6 +253,74 @@ public final class TestXWPFParagraph ext
     }
     
     public void testPictures() throws Exception {
-       // TODO
+       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
+       assertEquals(7, doc.getParagraphs().size());
+       
+       XWPFParagraph p;
+       XWPFRun r;
+
+       // Text paragraphs
+       assertEquals("Sheet with various pictures", doc.getParagraphs().get(0).getText());
+       assertEquals("(jpeg, png, wmf, emf and pict) ", doc.getParagraphs().get(1).getText());
+       
+       // Spacer ones
+       assertEquals("", doc.getParagraphs().get(2).getText());
+       assertEquals("", doc.getParagraphs().get(3).getText());
+       assertEquals("", doc.getParagraphs().get(4).getText());
+       
+       // Image one
+       p = doc.getParagraphs().get(5);
+       assertEquals(6, p.getRuns().size());
+
+       r = p.getRuns().get(0);
+       assertEquals("", r.toString());
+       assertEquals(1, r.getEmbeddedPictures().size());
+       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+       assertEquals("image1.wmf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+       r = p.getRuns().get(1);
+       assertEquals("", r.toString());
+       assertEquals(1, r.getEmbeddedPictures().size());
+       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+       assertEquals("image2.png", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+       r = p.getRuns().get(2);
+       assertEquals("", r.toString());
+       assertEquals(1, r.getEmbeddedPictures().size());
+       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+       assertEquals("image3.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+       r = p.getRuns().get(3);
+       assertEquals("", r.toString());
+       assertEquals(1, r.getEmbeddedPictures().size());
+       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+       assertEquals("image4.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+       r = p.getRuns().get(4);
+       assertEquals("", r.toString());
+       assertEquals(1, r.getEmbeddedPictures().size());
+       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+       assertEquals("image5.jpeg", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+       
+       r = p.getRuns().get(5);
+       assertEquals(" ", r.toString());
+       assertEquals(0, r.getEmbeddedPictures().size());
+       
+       // Final spacer
+       assertEquals("", doc.getParagraphs().get(6).getText());
+       
+       
+       // Look in detail at one
+       r = p.getRuns().get(4);
+       XWPFPicture pict = r.getEmbeddedPictures().get(0);
+       CTPicture picture = pict.getCTPicture();
+       assertEquals("rId8", picture.getBlipFill().getBlip().getEmbed());
+       
+       // Ensure that the ooxml compiler finds everything we need
+       r.getCTR().getDrawingArray(0);
+       r.getCTR().getDrawingArray(0).getInlineArray(0);
+       r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic();
+       r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
+       PicDocument pd = new PicDocumentImpl(null);
     }
 }



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


Mime
View raw message