poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1694340 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/
Date Wed, 05 Aug 2015 22:46:43 GMT
Author: kiwiwings
Date: Wed Aug  5 22:46:42 2015
New Revision: 1694340

URL: http://svn.apache.org/r1694340
Log:
#58206 - provide a mechanism to find slide layouts by name

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1694340&r1=1694339&r2=1694340&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Wed Aug  5 22:46:42 2015
@@ -39,6 +39,7 @@
     </devs>
 
     <release version="3.13-beta2" date="2015-10-??">
+        <action dev="PD" type="fix" fixes-bug="58206">provide a mechanism to find slide
layouts by name</action>
         <action dev="PD" type="fix" fixes-bug="58204">STYLE: ShapeContainer interface
makes internal getShapesList() redundant</action>
         <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>

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=1694340&r1=1694339&r2=1694340&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 Wed Aug  5 22:46:42
2015
@@ -476,6 +476,24 @@ public class XMLSlideShow extends POIXML
         return null;
     }
 
+
+    /**
+     * Scan the master slides for the first slide layout with the given name.
+     *
+     * @param name  The layout name (case-insensitive). Cannot be null.
+     * @return the first layout found or null on failure
+     */
+    public XSLFSlideLayout findLayout(String name) {
+        for (XSLFSlideMaster master : getSlideMasters()) {
+            XSLFSlideLayout layout = master.getLayout(name);
+            if (layout != null) {
+                return layout;
+            }
+        }
+        return null;
+    }
+
+
     public XSLFTableStyles getTableStyles(){
         return _tableStyles;
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java?rev=1694340&r1=1694339&r2=1694340&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java Wed Aug  5
22:46:42 2015
@@ -108,6 +108,13 @@ import org.openxmlformats.schemas.presen
         return getLayouts().values().toArray(new XSLFSlideLayout[_layouts.size()]);
     }
 
+    /**
+     * Get the slide layout by type.
+     *
+     * @param  type     The layout type. Cannot be null.
+     *
+     * @return the layout found or null on failure
+     */
     public XSLFSlideLayout getLayout(SlideLayout type){
         for(XSLFSlideLayout layout : getLayouts().values()){
             if(layout.getType() == type) {
@@ -117,6 +124,18 @@ import org.openxmlformats.schemas.presen
         return null;
     }
 
+    /**
+     * Get the slide layout by name.
+     *
+     * @param name  The layout name (case-insensitive). Cannot be null.
+     *
+     * @return the layout found or null on failure
+     */
+    public XSLFSlideLayout getLayout(String name) {
+        return getLayouts().get(name.toLowerCase());
+    }
+
+
     @Override
     public XSLFTheme getTheme(){
         if(_theme == null){

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java?rev=1694340&r1=1694339&r2=1694340&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java Wed
Aug  5 22:46:42 2015
@@ -16,9 +16,12 @@
 ==================================================================== */
 package org.apache.poi.xslf.usermodel;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
 
 import java.awt.Dimension;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.poi.POIXMLDocumentPart;
@@ -30,7 +33,7 @@ import org.junit.Test;
  */
 public class TestXSLFSlideShow {
     @Test
-    public void testCreateSlide(){
+    public void testCreateSlide() throws IOException {
         XMLSlideShow  ppt = new XMLSlideShow();
         assertEquals(0, ppt.getSlides().size());
 
@@ -50,13 +53,16 @@ public class TestXSLFSlideShow {
         assertSame(slide2, ppt.getSlides().get(0));
         assertSame(slide1, ppt.getSlides().get(1));
 
-        ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
-        assertEquals(2, ppt.getSlides().size());
-        rels =  ppt.getSlides().get(0).getRelations();
+        XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+        assertEquals(2, ppt2.getSlides().size());
+        rels =  ppt2.getSlides().get(0).getRelations();
+        
+        ppt2.close();
+        ppt.close();
     }
 
     @Test
-    public void testRemoveSlide(){
+    public void testRemoveSlide() throws IOException {
         XMLSlideShow  ppt = new XMLSlideShow();
         assertEquals(0, ppt.getSlides().size());
 
@@ -73,12 +79,15 @@ public class TestXSLFSlideShow {
         assertEquals(1, ppt.getSlides().size());
         assertSame(slide2, ppt.getSlides().get(0));
 
-        ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
-        assertEquals(1, ppt.getSlides().size());
+        XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);
+        assertEquals(1, ppt2.getSlides().size());
+        
+        ppt2.close();
+        ppt.close();
     }
 
     @Test
-    public void testDimension(){
+    public void testDimension() throws IOException {
         XMLSlideShow  ppt = new XMLSlideShow();
         Dimension sz = ppt.getPageSize();
         assertEquals(720, sz.width);
@@ -87,20 +96,22 @@ public class TestXSLFSlideShow {
         sz = ppt.getPageSize();
         assertEquals(792, sz.width);
         assertEquals(612, sz.height);
+        ppt.close();
     }
 
     @Test
-    public void testSlideMasters(){
+    public void testSlideMasters() throws IOException {
         XMLSlideShow  ppt = new XMLSlideShow();
         List<XSLFSlideMaster> masters = ppt.getSlideMasters();
         assertEquals(1, masters.size());
 
         XSLFSlide slide = ppt.createSlide();
         assertSame(masters.get(0), slide.getSlideMaster());
+        ppt.close();
     }
 
     @Test
-    public void testSlideLayout(){
+    public void testSlideLayout() throws IOException {
         XMLSlideShow  ppt = new XMLSlideShow();
         List<XSLFSlideMaster> masters = ppt.getSlideMasters();
         assertEquals(1, masters.size());
@@ -110,5 +121,29 @@ public class TestXSLFSlideShow {
         assertNotNull(layout);
 
         assertSame(masters.get(0), layout.getSlideMaster());
+        ppt.close();
+    }
+
+    @Test
+    public void testSlideLayoutNames() throws IOException {
+        final String names[] = {
+              "Blank", "Title Only", "Section Header", "Picture with Caption", "Title and
Content"
+            , "Title Slide", "Title and Vertical Text", "Vertical Title and Text", "Comparison"
+            , "Two Content", "Content with Caption"                
+        };
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
+        for (String name : names) {
+            assertNotNull(ppt.findLayout(name));
+        }
+        final SlideLayout layTypes[] = {
+              SlideLayout.BLANK, SlideLayout.TITLE_ONLY, SlideLayout.SECTION_HEADER
+            , SlideLayout.PIC_TX, SlideLayout.TITLE_AND_CONTENT, SlideLayout.TITLE
+            , SlideLayout.VERT_TX, SlideLayout.VERT_TITLE_AND_TX, SlideLayout.TWO_TX_TWO_OBJ
+            , SlideLayout.TWO_OBJ, SlideLayout.OBJ_TX                
+        };
+        for (SlideLayout sl : layTypes){
+            assertNotNull(ppt.getSlideMasters().get(0).getLayout(sl));
+        }
+        ppt.close();
     }
 }



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


Mime
View raw message