]> source.dussan.org Git - poi.git/commitdiff
more progress with merging external slides
authorYegor Kozlov <yegor@apache.org>
Wed, 28 Dec 2011 12:32:07 +0000 (12:32 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 28 Dec 2011 12:32:07 +0000 (12:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1225169 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java

index 66cb5abb53fe321897ab52bfcc1d8498c770a2e4..920cf8beaf256ec62e50be76a8e8b7b02f8791b5 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.util.Beta;\r
 import org.apache.poi.util.Units;\r
 import org.apache.xmlbeans.XmlObject;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;\r
@@ -33,6 +34,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;\r
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;\r
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;\r
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;\r
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;\r
 \r
 import java.awt.Graphics2D;\r
@@ -309,4 +311,18 @@ public class XSLFGroupShape extends XSLFShape {
         \r
     }\r
 \r
+    @Override\r
+    void copy(XSLFShape src){\r
+        XSLFGroupShape gr = (XSLFGroupShape)src;\r
+        // recursively update each shape\r
+        XSLFShape[] tgtShapes = getShapes();\r
+        XSLFShape[] srcShapes = gr.getShapes();\r
+        for(int i = 0; i < tgtShapes.length; i++){\r
+            XSLFShape s1 = srcShapes[i];\r
+            XSLFShape s2 = tgtShapes[i];\r
+\r
+            s2.copy(s1);\r
+        }\r
+    }\r
+\r
 }
\ No newline at end of file
index ce568f0ff6a3925a4d67b04898d8af9d3fc385fc..0c64947b9c6f28cabd96600a4afd38079ac16959 100644 (file)
@@ -286,10 +286,11 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable<X
         _shapes = null;
         _spTree = null;
         _drawing = null;
+        _spTree = null;
         // first copy the source xml
-        getXmlObject().set(src.getXmlObject());
+        getSpTree().set(src.getSpTree());
 
-        // recursively update each shape 
+        // recursively update each shape
         List<XSLFShape> tgtShapes = getShapeList();
         List<XSLFShape> srcShapes = src.getShapeList();
         for(int i = 0; i < tgtShapes.size(); i++){
@@ -302,10 +303,52 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements Iterable<X
     }
 
     /**
+     * Append content to this sheet.
+     *
+     * @param src the source sheet
+     * @return modified <code>this</code>.
+     */
+    public XSLFSheet appendContent(XSLFSheet src){
+        CTGroupShape spTree = getSpTree();
+        int numShapes = getShapeList().size();
+
+        CTGroupShape srcTree = src.getSpTree();
+        for(XmlObject ch : srcTree.selectPath("*")){
+            if(ch instanceof CTShape){ // simple shape
+                spTree.addNewSp().set(ch);
+            } else if (ch instanceof CTGroupShape){
+                spTree.addNewGrpSp().set(ch);
+            } else if (ch instanceof CTConnector){
+                spTree.addNewCxnSp().set(ch);
+            } else if (ch instanceof CTPicture){
+                spTree.addNewPic().set(ch);
+            } else if (ch instanceof CTGraphicalObjectFrame){
+                spTree.addNewGraphicFrame().set(ch);
+            }
+        }
+
+        _shapes = null;
+        _spTree = null;
+        _drawing = null;
+        _spTree = null;
+
+        // recursively update each shape
+        List<XSLFShape> tgtShapes = getShapeList();
+        List<XSLFShape> srcShapes = src.getShapeList();
+        for(int i = 0; i < srcShapes.size(); i++){
+            XSLFShape s1 = srcShapes.get(i);
+            XSLFShape s2 = tgtShapes.get(numShapes + i);
+
+            s2.copy(s1);
+        }
+        return this;
+    }
+
+   /**
      * @return theme (shared styles) associated with this theme.
      *  By default returns <code>null</code> which means that this sheet is theme-less.
      *  Sheets that support the notion of themes (slides, masters, layouts, etc.) should override this
-     *  method and return the corresposnding package part.
+     *  method and return the corresponding package part.
      */
     XSLFTheme getTheme(){
        return null;
index 91566cb09a23dc1fdcf8c58e921e4b346682ef81..f2d4b6eff199498b142480639034ef4b51fba615 100644 (file)
@@ -225,8 +225,9 @@ public final class XSLFSlide extends XSLFSheet {
     public XSLFSlide importContent(XSLFSheet src){
         super.importContent(src);
 
-        CTBackground bg = ((CTSlide)src.getXmlObject()).getCSld().getBg();
-        if(bg != null) {
+        XSLFBackground bgShape = getBackground();
+        if(bgShape != null) {
+            CTBackground bg = (CTBackground)bgShape.getXmlObject();
             if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
                 CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
                 String blipId = blip.getEmbed();