You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/08/11 10:38:20 UTC
svn commit: r1156539 [1/3] - in /poi/trunk: src/documentation/content/xdocs/
src/examples/src/org/apache/poi/xslf/
src/examples/src/org/apache/poi/xslf/usermodel/
src/ooxml/java/org/apache/poi/util/ src/ooxml/java/org/apache/poi/xslf/
src/ooxml/java/or...
Author: yegor
Date: Thu Aug 11 08:38:19 2011
New Revision: 1156539
URL: http://svn.apache.org/viewvc?rev=1156539&view=rev
Log:
initial support for XSLF usermodel API
Added:
poi/trunk/src/examples/src/org/apache/poi/xslf/
poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/
poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java
poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDecoration.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndLength.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndWidth.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFConnectorShape.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFFreeformShape.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFGroupShape.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFShape.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSheet.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java (with props)
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java
poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/
poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/
poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/usermodel/empty.pptx (with props)
poi/trunk/test-data/slideshow/shapes.pptx (with props)
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingParagraph.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTable.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTableRow.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTextBody.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/XSLFTestDataSamples.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Aug 11 08:38:19 2011
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta4" date="2011-??-??">
+ <action dev="poi-developers" type="add">initial support for XSLF usermodel API</action>
<action dev="poi-developers" type="fix">51187 - fixed OPCPackage to correctly handle self references</action>
<action dev="poi-developers" type="fix">51635 - Improved performance of XSSFSheet#write</action>
<action dev="poi-developers" type="fix">47731 - Word Extractor considers text copied from some website as an embedded object</action>
Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,86 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.io.FileOutputStream;
+
+/**
+ * Simple demo that creates a pptx slide show using the XSLF API
+ *
+ * @author Yegor Kozlov
+ */
+public class SlidesAndShapes {
+
+ public static void main(String[] args) throws Exception {
+ XMLSlideShow ppt = new XMLSlideShow();
+ ppt.setPageSize(new Dimension(792, 612));
+
+ XSLFSlide slide1 = ppt.createSlide();
+ XSLFTextBox textBox = slide1.createTextBox();
+ XSLFTextRun r1 = textBox.addNewTextParagraph().addNewTextRun();
+ r1.setBold(true);
+ r1.setItalic(true);
+ r1.setFontColor(Color.yellow);
+ r1.setFontFamily("Arial");
+ r1.setFontSize(24);
+ r1.setText("Apache");
+ XSLFTextRun r2 = textBox.addNewTextParagraph().addNewTextRun();
+ r2.setStrikethrough(true);
+ r2.setUnderline(true);
+ r2.setText("POI\u2122");
+ XSLFTextRun r3 = textBox.addNewTextParagraph().addNewTextRun();
+ r3.setFontFamily("Wingdings");
+ r3.setText(" Version 3.8");
+
+ textBox.setAnchor(new Rectangle(50, 50, 200, 100));
+ textBox.setLineColor(Color.black);
+ textBox.setFillColor(Color.orange);
+
+ XSLFAutoShape shape2 = slide1.createAutoShape();
+
+ shape2.setAnchor(new Rectangle(100, 100, 200, 200));
+
+ XSLFFreeformShape shape3 = slide1.createFreeform();
+ Rectangle rect = new Rectangle(150, 150, 300, 300);
+ GeneralPath path = new GeneralPath(rect);
+ path.append(new Ellipse2D.Double(200, 200, 100, 50), false);
+ shape3.setPath(path);
+ shape3.setAnchor(path.getBounds2D());
+ shape3.setLineColor(Color.black);
+ shape3.setFillColor(Color.lightGray);
+
+ XSLFSlide slide2 = ppt.createSlide();
+ XSLFGroupShape group = slide2.createGroup();
+
+ group.setAnchor(new Rectangle(0, 0, 792, 612));
+ group.setInteriorAnchor(new Rectangle(-10, -10, 20, 20));
+
+ XSLFAutoShape shape4 = group.createAutoShape();
+ shape4.setAnchor(new Rectangle(0, 0, 5, 5));
+ shape4.setLineWidth(5);
+ shape4.setLineColor(Color.black);
+
+
+ FileOutputStream out = new FileOutputStream("xslf-demo.pptx");
+ ppt.write(out);
+ out.close();
+ }
+
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,17 @@
+package org.apache.poi.util;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class Units {
+ public static final int EMU_PER_PIXEL = 9525;
+ public static final int EMU_PER_POINT = 12700;
+
+ public static int toEMU(double value){
+ return (int)Math.round(EMU_PER_POINT*value);
+ }
+
+ public static double toPoints(long emu){
+ return (double)emu/EMU_PER_POINT;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/util/Units.java
------------------------------------------------------------------------------
svn:executable = *
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java Thu Aug 11 08:38:19 2011
@@ -16,20 +16,16 @@
==================================================================== */
package org.apache.poi.xslf;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-
import org.apache.poi.POIXMLDocument;
-import org.apache.poi.util.Internal;
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
-import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.util.Internal;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
@@ -46,6 +42,10 @@ import org.openxmlformats.schemas.presen
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
/**
* Experimental class to do low level processing of pptx files.
*
@@ -80,10 +80,10 @@ public class XSLFSlideShow extends POIXM
for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
PackagePart slidePart =
getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
-
+
for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
embedds.add(getTargetPart(rel)); // TODO: Add this reference to each slide as well
-
+
for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
embedds.add(getTargetPart(rel));
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java Thu Aug 11 08:38:19 2011
@@ -26,7 +26,10 @@ import org.apache.poi.xslf.usermodel.XSL
import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.xmlbeans.XmlException;
-import org.openxmlformats.schemas.presentationml.x2006.main.*;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTComment;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import java.io.IOException;
@@ -42,11 +45,11 @@ public class XSLFPowerPointExtractor ext
private boolean notesByDefault = false;
public XSLFPowerPointExtractor(XMLSlideShow slideshow) {
- super(slideshow._getXSLFSlideShow());
+ super(slideshow);
this.slideshow = slideshow;
}
public XSLFPowerPointExtractor(XSLFSlideShow slideshow) throws XmlException, IOException {
- this(new XMLSlideShow(slideshow));
+ this(new XMLSlideShow(slideshow.getPackage()));
}
public XSLFPowerPointExtractor(OPCPackage container) throws XmlException, OpenXML4JException, IOException {
this(new XSLFSlideShow(container));
@@ -55,7 +58,7 @@ public class XSLFPowerPointExtractor ext
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Use:");
- System.err.println(" HXFPowerPointExtractor <filename.pptx>");
+ System.err.println(" XSLFPowerPointExtractor <filename.pptx>");
System.exit(1);
}
POIXMLTextExtractor extractor =
@@ -95,41 +98,41 @@ public class XSLFPowerPointExtractor ext
StringBuffer text = new StringBuffer();
XSLFSlide[] slides = slideshow.getSlides();
- for(int i = 0; i < slides.length; i++) {
- CTSlide rawSlide = slides[i]._getCTSlide();
- CTSlideIdListEntry slideId = slides[i]._getCTSlideId();
-
- try {
- // For now, still very low level
- CTNotesSlide notes =
- slideshow._getXSLFSlideShow().getNotes(slideId);
- CTCommentList comments =
- slideshow._getXSLFSlideShow().getSlideComments(slideId);
-
- if(slideText) {
- extractText(slides[i].getCommonSlideData(), text);
-
- // Comments too for the slide
- if(comments != null) {
- for(CTComment comment : comments.getCmList()) {
- // TODO - comment authors too
- // (They're in another stream)
- text.append(
- comment.getText() + "\n"
- );
- }
- }
- }
-
- if(notesText && notes != null) {
- extractText(new XSLFCommonSlideData(notes.getCSld()), text);
- }
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- return text.toString();
+ try {
+ XSLFSlideShow xsl = new XSLFSlideShow(slideshow.getPackage());
+ for (int i = 0; i < slides.length; i++) {
+ CTSlideIdListEntry slideId = slideshow.getCTPresentation().getSldIdLst().getSldIdArray(i);
+
+ // For now, still very low level
+ CTNotesSlide notes =
+ xsl.getNotes(slideId);
+ CTCommentList comments =
+ xsl.getSlideComments(slideId);
+
+ if (slideText) {
+ extractText(new XSLFCommonSlideData(slides[i].getXmlObject().getCSld()), text);
+
+ // Comments too for the slide
+ if (comments != null) {
+ for (CTComment comment : comments.getCmList()) {
+ // TODO - comment authors too
+ // (They're in another stream)
+ text.append(
+ comment.getText() + "\n"
+ );
+ }
+ }
+ }
+
+ if (notesText && notes != null) {
+ extractText(new XSLFCommonSlideData(notes.getCSld()), text);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return text.toString();
}
private void extractText(XSLFCommonSlideData data, StringBuffer text) {
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingParagraph.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingParagraph.java Thu Aug 11 08:38:19 2011
@@ -17,11 +17,11 @@
package org.apache.poi.xslf.usermodel;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
public class DrawingParagraph {
private final CTTextParagraph p;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTable.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTable.java Thu Aug 11 08:38:19 2011
@@ -17,11 +17,11 @@
package org.apache.poi.xslf.usermodel;
-import java.util.List;
-
import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
+import java.util.List;
+
public class DrawingTable {
private final CTTable table;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTableRow.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTableRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTableRow.java Thu Aug 11 08:38:19 2011
@@ -17,10 +17,10 @@
package org.apache.poi.xslf.usermodel;
-import java.util.List;
-
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
+
+import java.util.List;
public class DrawingTableRow {
private final CTTableRow row;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTextBody.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTextBody.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTextBody.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/DrawingTextBody.java Thu Aug 11 08:38:19 2011
@@ -17,11 +17,11 @@
package org.apache.poi.xslf.usermodel;
-import java.util.List;
-
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import java.util.List;
+
public class DrawingTextBody {
private final CTTextBody textBody;
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,19 @@
+package org.apache.poi.xslf.usermodel;
+
+/**
+ */
+public enum LineCap {
+ /**
+ * Rounded ends - the default
+ */
+ ROUND,
+ /**
+ * Square protrudes by half line width
+ */
+ SQUARE,
+
+ /**
+ * Line ends at end point
+ */
+ FLAT;
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,17 @@
+package org.apache.poi.xslf.usermodel;
+
+/**
+ */
+public enum LineDash {
+ SOLID,
+ DOT,
+ DASH,
+ LG_DASH,
+ DASH_DOT,
+ LG_DASH_DOT,
+ LG_DASH_DOT_DOT,
+ SYS_DASH,
+ SYS_DOT,
+ SYS_DASH_DOT,
+ SYS_DASH_DOT_DOT;
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDecoration.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDecoration.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDecoration.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDecoration.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,29 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+/**
+ * Represents the shape decoration that appears at the ends of lines.
+ */
+public enum LineDecoration {
+ NONE,
+ TRIANGLE,
+ STEALTH,
+ DIAMOND,
+ OVAL,
+ ARROW
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndLength.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndLength.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndLength.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndLength.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,14 @@
+package org.apache.poi.xslf.usermodel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: yegor
+ * Date: Aug 9, 2011
+ * Time: 9:39:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public enum LineEndLength {
+ SMALL,
+ MEDIUM,
+ LARGE
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndWidth.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndWidth.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndWidth.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/LineEndWidth.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,14 @@
+package org.apache.poi.xslf.usermodel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: yegor
+ * Date: Aug 9, 2011
+ * Time: 9:39:26 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public enum LineEndWidth {
+ SMALL,
+ MEDIUM,
+ LARGE
+}
\ No newline at end of file
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java Thu Aug 11 08:38:19 2011
@@ -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.xslf.usermodel;
+
+/**
+ * @author Yegor Kozlov
+ */
+public enum Placeholder {
+ TITLE,
+ BODY,
+ CENTERED_TITLE,
+ SUBTITLE,
+ DATETIME,
+ SLIDE_NUMBER,
+ FOOTER,
+ HEADER,
+ OBJECT,
+ CHART,
+ TABLE
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,47 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+/**
+ * Specified a list of text alignment types
+ *
+ * @author Yegor Kozlov
+ */
+public enum TextAlign {
+ /**
+ * Align text to the left margin.
+ */
+ LEFT,
+ /**
+ * Align text in the center.
+ */
+ CENTER,
+
+ /**
+ * Align text to the right margin.
+ */
+ RIGHT,
+
+ /**
+ * Align text so that it is justified across the whole line. It
+ * is smart in the sense that it will not justify sentences
+ * which are short
+ */
+ JUSTIFY
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,59 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+/**
+ * Specifies alist of auto-fit types.
+ * <p>
+ * Autofit specofies that a shape should be auto-fit to fully contain the text described within it.
+ * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public enum TextAutofit {
+ /**
+ * Specifies that text within the text body should not be auto-fit to the bounding box.
+ * Auto-fitting is when text within a text box is scaled in order to remain inside
+ * the text box.
+ */
+ NONE,
+ /**
+ * Specifies that text within the text body should be normally auto-fit to the bounding box.
+ * Autofitting is when text within a text box is scaled in order to remain inside the text box.
+ *
+ * <p>
+ * <em>Example:</em> Consider the situation where a user is building a diagram and needs
+ * to have the text for each shape that they are using stay within the bounds of the shape.
+ * An easy way this might be done is by using NORMAL autofit
+ * </p>
+ */
+ NORMAL,
+ /**
+ * Specifies that a shape should be auto-fit to fully contain the text described within it.
+ * Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
+ *
+ * <p>
+ * <em>Example:</em> Consider the situation where a user is building a diagram and needs to have
+ * the text for each shape that they are using stay within the bounds of the shape.
+ * An easy way this might be done is by using SHAPE autofit
+ * </p>
+ */
+ SHAPE
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,48 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+/**
+ * Vertical Text Types
+ */
+public enum TextDirection {
+ /**
+ * Horizontal text. This should be default.
+ */
+ HORIZONTAL,
+ /**
+ * Vertical orientation.
+ * (each line is 90 degrees rotated clockwise, so it goes
+ * from top to bottom; each next line is to the left from
+ * the previous one).
+ */
+ VERTICAL,
+ /**
+ * Vertical orientation.
+ * (each line is 270 degrees rotated clockwise, so it goes
+ * from bottom to top; each next line is to the right from
+ * the previous one).
+ */
+ VERTICAL_270,
+ /**
+ * Determines if all of the text is vertical
+ * ("one letter on top of another").
+ */
+ STACKED;
+}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+/**
+ * Specifies a list of available anchoring types for text
+ *
+ * @author Yegor Kozlov
+ */
+public enum VerticalAlignment {
+ /**
+ * Anchor the text at the top of the bounding rectangle
+ */
+ TOP,
+
+ /**
+ * Anchor the text at the middle of the bounding rectangle
+ */
+ MIDDLE,
+
+ /**
+ * Anchor the text at the bottom of the bounding rectangle.
+ */
+ BOTTOM,
+
+ /**
+ * Anchor the text so that it is justified vertically.
+ * <p>
+ * When text is horizontal, this spaces out the actual lines of
+ * text and is almost always identical in behavior to
+ * {@link #DISTRIBUTED} (special case: if only 1 line, then anchored at top).
+ * </p>
+ * <p>
+ * When text is vertical, then it justifies the letters
+ * vertically. This is different than {@link #DISTRIBUTED},
+ * because in some cases such as very little text in a line,
+ * it will not justify.
+ * </p>
+ */
+ JUSTIFIED,
+
+ /**
+ * Anchor the text so that it is distributed vertically.
+ * <p>
+ * When text is horizontal, this spaces out the actual lines
+ * of text and is almost always identical in behavior to
+ * {@link #JUSTIFIED} (special case: if only 1 line, then anchored in middle).
+ * </p>
+ * <p>
+ * When text is vertical, then it distributes the letters vertically.
+ * This is different than {@link #JUSTIFIED}, because it always forces distribution
+ * of the words, even if there are only one or two words in a line.
+ */
+ DISTRIBUTED
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java
------------------------------------------------------------------------------
svn:executable = *
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=1156539&r1=1156538&r2=1156539&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 Thu Aug 11 08:38:19 2011
@@ -16,20 +16,42 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import java.io.IOException;
-
+import org.apache.poi.POIXMLDocument;
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.sl.usermodel.MasterSheet;
-import org.apache.poi.sl.usermodel.Resources;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
-import org.apache.poi.xslf.XSLFSlideShow;
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Internal;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.PackageHelper;
+import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlException;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
+import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
+
+import java.awt.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
/**
* High level representation of a ooxml slideshow.
@@ -37,57 +59,261 @@ import org.openxmlformats.schemas.presen
* they are reading or writing a slideshow. It is also the
* top level object for creating new slides/etc.
*/
-public class XMLSlideShow implements SlideShow {
- private XSLFSlideShow slideShow;
- private XSLFSlide[] slides;
-
- public XMLSlideShow(XSLFSlideShow xml) throws XmlException, IOException {
- this.slideShow = xml;
-
- // Build the main masters list - TODO
- CTSlideMasterIdList masterIds = slideShow.getSlideMasterReferences();
-
- // Build the slides list
- CTSlideIdList slideIds = slideShow.getSlideReferences();
- slides = new XSLFSlide[slideIds.getSldIdList().size()];
- for(int i=0; i<slides.length; i++) {
- CTSlideIdListEntry slideId = slideIds.getSldIdArray(i);
- CTSlide slide = slideShow.getSlide(slideId);
- slides[i] = new XSLFSlide(slide, slideId, this);
- }
-
- // Build the notes list - TODO
- }
-
- public XMLSlideShow(OPCPackage pkg) throws XmlException, IOException, OpenXML4JException {
- this(new XSLFSlideShow(pkg));
- }
-
- public XSLFSlideShow _getXSLFSlideShow() {
- return slideShow;
- }
-
- public MasterSheet createMasterSheet() throws IOException {
- throw new IllegalStateException("Not implemented yet!");
- }
- public Slide createSlide() throws IOException {
- throw new IllegalStateException("Not implemented yet!");
- }
-
- public MasterSheet[] getMasterSheet() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Return all the slides in the slideshow
- */
- public XSLFSlide[] getSlides() {
- return slides;
- }
-
- public Resources getResources() {
- // TODO Auto-generated method stub
- return null;
- }
+@Beta
+public class XMLSlideShow extends POIXMLDocument {
+
+ private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
+
+ private CTPresentation _presentation;
+ private List<XSLFSlide> _slides;
+ private Map<String, XSLFSlideMaster> _masters;
+ protected List<XSLFPictureData> _pictures;
+
+ public XMLSlideShow() {
+ this(empty());
+ }
+
+ public XMLSlideShow(OPCPackage pkg) {
+ super(pkg);
+
+ try {
+ if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
+ rebase(getPackage());
+ }
+
+ //build a tree of POIXMLDocumentParts, this presentation being the root
+ load(XSLFFactory.getInstance());
+ } catch (Exception e){
+ throw new POIXMLException(e);
+ }
+ }
+
+ public XMLSlideShow(InputStream is) throws IOException {
+ this(PackageHelper.open(is));
+ }
+
+ static final OPCPackage empty() {
+ InputStream is = XMLSlideShow.class.getResourceAsStream("empty.pptx");
+ if (is == null) {
+ throw new RuntimeException("Missing resource 'empty.pptx'");
+ }
+ try {
+ return OPCPackage.open(is);
+ } catch (Exception e){
+ throw new POIXMLException(e);
+ }
+ }
+
+ // TODO get rid of this method
+ @Deprecated
+ public XSLFSlideShow _getXSLFSlideShow() throws OpenXML4JException, IOException, XmlException{
+ return new XSLFSlideShow(getPackage());
+ }
+
+ @Override
+ protected void onDocumentRead() throws IOException {
+ try {
+ PresentationDocument doc =
+ PresentationDocument.Factory.parse(getCorePart().getInputStream());
+ _presentation = doc.getPresentation();
+ Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
+
+ _masters = new HashMap<String, XSLFSlideMaster>();
+ for (POIXMLDocumentPart p : getRelations()) {
+ if (p instanceof XSLFSlide) {
+ shIdMap.put(p.getPackageRelationship().getId(), (XSLFSlide) p);
+ } else if (p instanceof XSLFSlideMaster){
+ XSLFSlideMaster master = (XSLFSlideMaster)p;
+ _masters.put(p.getPackageRelationship().getId(), master);
+ }
+ }
+
+ _slides = new ArrayList<XSLFSlide>();
+ if (_presentation.isSetSldIdLst()) {
+ List<CTSlideIdListEntry> slideIds = _presentation.getSldIdLst().getSldIdList();
+ for (CTSlideIdListEntry slId : slideIds) {
+ XSLFSlide sh = shIdMap.get(slId.getId2());
+ if (sh == null) {
+ _logger.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
+ continue;
+ }
+ _slides.add(sh);
+ }
+ }
+ } catch (XmlException e) {
+ throw new POIXMLException(e);
+ }
+ }
+
+
+ @Override
+ protected void commit() throws IOException {
+ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
+ xmlOptions.setSaveSuggestedPrefixes(map);
+
+ PackagePart part = getPackagePart();
+ OutputStream out = part.getOutputStream();
+ _presentation.save(out, xmlOptions);
+ out.close();
+ }
+
+ /**
+ * Get the document's embedded files.
+ */
+ public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+ return Collections.unmodifiableList(
+ getPackage().getPartsByName(Pattern.compile("/ppt/embeddings/.*?"))
+ );
+ }
+
+ /**
+ * Returns all Pictures, which are referenced from the document itself.
+ * @return a {@link List} of {@link PackagePart}.
+ * The returned {@link List} is unmodifiable.
+ */
+ public List<XSLFPictureData> getAllPictures() {
+ if(_pictures == null){
+ 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));
+ }
+ }
+ return Collections.unmodifiableList(_pictures);
+ }
+
+ public XSLFSlide createSlide() {
+ int slideNumber = 256, cnt = 1;
+ CTSlideIdList slideList;
+ if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
+ else {
+ slideList = _presentation.getSldIdLst();
+ for(CTSlideIdListEntry slideId : slideList.getSldIdList()){
+ slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
+ cnt++;
+ }
+ }
+
+ XSLFSlide slide = (XSLFSlide)createRelationship(
+ XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt);
+
+ CTSlideIdListEntry slideId = slideList.addNewSldId();
+ slideId.setId(slideNumber);
+ slideId.setId2(slide.getPackageRelationship().getId());
+
+ String masterId = _presentation.getSldMasterIdLst().getSldMasterIdArray(0).getId2();
+ XSLFSlideMaster master = _masters.get(masterId);
+
+ XSLFSlideLayout layout = master.getLayout("blank");
+ if(layout == null) throw new IllegalArgumentException("Blank layout was not found");
+
+ slide.addRelation(layout.getPackageRelationship().getId(), layout);
+
+ PackagePartName ppName = layout.getPackagePart().getPartName();
+ slide.getPackagePart().addRelationship(ppName, TargetMode.INTERNAL,
+ layout.getPackageRelationship().getRelationshipType());
+
+ _slides.add(slide);
+ return slide;
+ }
+
+ public XSLFSlideMaster[] getSlideMasters() {
+ return _masters.values().toArray(new XSLFSlideMaster[_masters.size()]);
+ }
+
+ /**
+ * Return all the slides in the slideshow
+ */
+ public XSLFSlide[] getSlides() {
+ return _slides.toArray(new XSLFSlide[_slides.size()]);
+ }
+
+ /**
+ *
+ * @param newIndex 0-based index of the slide
+ */
+ public void setSlideOrder(XSLFSlide slide, int newIndex){
+ int oldIndex = _slides.indexOf(slide);
+ if(oldIndex == -1) throw new IllegalArgumentException("Slide not found");
+
+ // fix the usermodel container
+ _slides.add(newIndex, _slides.remove(oldIndex));
+
+ // fix ordering in the low-level xml
+ List<CTSlideIdListEntry> slideIds = _presentation.getSldIdLst().getSldIdList();
+ CTSlideIdListEntry oldEntry = slideIds.get(oldIndex);
+ slideIds.add(newIndex, oldEntry);
+ slideIds.remove(oldEntry);
+ }
+
+ public XSLFSlide removeSlide(int index){
+ XSLFSlide slide = _slides.remove(index);
+ removeRelation(slide);
+ _presentation.getSldIdLst().getSldIdList().remove(index);
+ return slide;
+ }
+
+ /**
+ * Returns the current page size
+ *
+ * @return the page size
+ */
+ public Dimension getPageSize(){
+ CTSlideSize sz = _presentation.getSldSz();
+ int cx = sz.getCx();
+ int cy = sz.getCy();
+ return new Dimension((int)Units.toPoints(cx), (int)Units.toPoints(cy));
+ }
+
+ /**
+ * Sets the page size to the given <code>Dimension</code> object.
+ *
+ * @param pgSize page size
+ */
+ public void setPageSize(Dimension pgSize){
+ CTSlideSize sz = CTSlideSize.Factory.newInstance();
+ sz.setCx(Units.toEMU(pgSize.getWidth()));
+ sz.setCy(Units.toEMU(pgSize.getHeight()));
+ _presentation.setSldSz(sz);
+ }
+
+
+ @Internal
+ public CTPresentation getCTPresentation(){
+ return _presentation;
+ }
+
+ /**
+ * Adds a picture to the workbook.
+ *
+ * @param pictureData The bytes of the picture
+ * @param format The format of the picture.
+ *
+ * @return the index to this picture (1 based).
+ * @see XSLFPictureData#PICTURE_TYPE_EMF
+ * @see XSLFPictureData#PICTURE_TYPE_WMF
+ * @see XSLFPictureData#PICTURE_TYPE_PICT
+ * @see XSLFPictureData#PICTURE_TYPE_JPEG
+ * @see XSLFPictureData#PICTURE_TYPE_PNG
+ * @see XSLFPictureData#PICTURE_TYPE_DIB
+ */
+ public int addPicture(byte[] pictureData, int format) {
+ getAllPictures();
+
+ int imageNumber = getPackage().getPartsByName(Pattern.compile("/ppt/media/.*?")).size() + 1;
+ XSLFPictureData img = (XSLFPictureData) createRelationship(
+ XSLFPictureData.RELATIONS[format], XSLFFactory.getInstance(), imageNumber, true);
+ _pictures.add(img);
+ try {
+ OutputStream out = img.getPackagePart().getOutputStream();
+ out.write(pictureData);
+ out.close();
+ } catch (IOException e) {
+ throw new POIXMLException(e);
+ }
+ return imageNumber - 1;
+ }
+
}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,427 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextWrappingType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
+import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a preset geometric shape.
+ *
+ * @author Yegor Kozlov
+ */
+@Beta
+public class XSLFAutoShape extends XSLFSimpleShape {
+ private final List<XSLFTextParagraph> _paragraphs;
+
+ /*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
+ super(shape, sheet);
+
+ _paragraphs = new ArrayList<XSLFTextParagraph>();
+ if (shape.isSetTxBody()) {
+ CTTextBody txBody = shape.getTxBody();
+ for (CTTextParagraph p : txBody.getPList()) {
+ _paragraphs.add(new XSLFTextParagraph(p));
+ }
+ }
+ }
+
+ /*package*/
+ static XSLFAutoShape create(CTShape shape, XSLFSheet sheet) {
+ if (shape.getSpPr().isSetCustGeom()) {
+ return new XSLFFreeformShape(shape, sheet);
+ } else if (shape.getNvSpPr().getCNvSpPr().isSetTxBox()) {
+ return new XSLFTextBox(shape, sheet);
+ } else {
+ return new XSLFAutoShape(shape, sheet);
+ }
+ }
+
+ // textual properties
+ public String getText() {
+ StringBuilder out = new StringBuilder();
+ for (XSLFTextParagraph p : _paragraphs) {
+ if (out.length() > 0) out.append('\n');
+ out.append(p.getText());
+ }
+ return out.toString();
+ }
+
+ public List<XSLFTextParagraph> getTextParagraphs() {
+ return _paragraphs;
+ }
+
+ public XSLFTextParagraph addNewTextParagraph() {
+ CTShape shape = (CTShape) getXmlObject();
+ CTTextBody txBody;
+ if (!shape.isSetTxBody()) {
+ txBody = shape.addNewTxBody();
+ txBody.addNewBodyPr();
+ txBody.addNewLstStyle();
+ } else {
+ txBody = shape.getTxBody();
+ }
+ CTTextParagraph p = txBody.addNewP();
+ XSLFTextParagraph paragraph = new XSLFTextParagraph(p);
+ _paragraphs.add(paragraph);
+ return paragraph;
+ }
+
+ /**
+ * @param shapeId 1-based shapeId
+ */
+ static CTShape prototype(int shapeId) {
+ CTShape ct = CTShape.Factory.newInstance();
+ CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
+ CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
+ cnv.setName("AutoShape " + shapeId);
+ cnv.setId(shapeId + 1);
+ nvSpPr.addNewCNvSpPr();
+ nvSpPr.addNewNvPr();
+ CTShapeProperties spPr = ct.addNewSpPr();
+ CTPresetGeometry2D prst = spPr.addNewPrstGeom();
+ prst.setPrst(STShapeType.RECT);
+ prst.addNewAvLst();
+ return ct;
+ }
+
+ /**
+ * Specifies a solid color fill. The shape is filled entirely with the specified color.
+ *
+ * @param color the solid color fill.
+ * The value of <code>null</code> unsets the solidFIll attribute from the underlying xml
+ */
+ public void setFillColor(Color color) {
+ CTShapeProperties spPr = getSpPr();
+ if (color == null) {
+ if(spPr.isSetSolidFill()) spPr.unsetSolidFill();
+ }
+ else {
+ CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill();
+
+ CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
+ rgb.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()});
+
+ fill.setSrgbClr(rgb);
+ }
+ }
+
+ /**
+ *
+ * @return solid fill color of null if not set
+ */
+ public Color getFillColor(){
+ CTShapeProperties spPr = getSpPr();
+ if(!spPr.isSetSolidFill() ) return null;
+
+ CTSolidColorFillProperties fill = spPr.getSolidFill();
+ if(!fill.isSetSrgbClr()) {
+ // TODO for now return null for all colors except explicit RGB
+ return null;
+ }
+ byte[] val = fill.getSrgbClr().getVal();
+ return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
+ }
+
+ /**
+ * Sets the type of vertical alignment for the text.
+ * One of the <code>Anchor*</code> constants defined in this class.
+ *
+ * @param anchor - the type of alignment. Default is {@link VerticalAlignment#TOP}
+ */
+ public void setVerticalAlignment(VerticalAlignment anchor){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(anchor == null) {
+ if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
+ } else {
+ bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
+ }
+ }
+ }
+
+ /**
+ * Returns the type of vertical alignment for the text.
+ *
+ * @return the type of alignment
+ */
+ public VerticalAlignment getVerticalAlignment(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ STTextAnchoringType.Enum val = shape.getTxBody().getBodyPr().getAnchor();
+ if(val != null){
+ return VerticalAlignment.values()[val.intValue() - 1];
+ }
+ }
+ return VerticalAlignment.TOP;
+ }
+
+ /**
+ *
+ * @param orientation vertical orientation of the text
+ */
+ public void setTextDirection(TextDirection orientation){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(orientation == null) {
+ if(bodyPr.isSetVert()) bodyPr.unsetVert();
+ } else {
+ bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
+ }
+ }
+ }
+
+ /**
+ * @return vertical orientation of the text
+ */
+ public TextDirection getTextDirection(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ STTextVerticalType.Enum val = shape.getTxBody().getBodyPr().getVert();
+ if(val != null){
+ return TextDirection.values()[val.intValue() - 1];
+ }
+ }
+ return TextDirection.HORIZONTAL;
+ }
+ /**
+ * Returns the distance (in points) between the bottom of the text frame
+ * and the bottom of the inscribed rectangle of the shape that contains the text.
+ *
+ * @return the bottom margin or -1 if not set
+ */
+ public double getMarginBottom(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ return bodyPr.isSetBIns() ? Units.toPoints(bodyPr.getBIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the left edge of the text frame
+ * and the left edge of the inscribed rectangle of the shape that contains
+ * the text.
+ *
+ * @return the left margin
+ */
+ public double getMarginLeft(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ return bodyPr.isSetLIns() ? Units.toPoints(bodyPr.getLIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the right edge of the
+ * text frame and the right edge of the inscribed rectangle of the shape
+ * that contains the text.
+ *
+ * @return the right margin
+ */
+ public double getMarginRight(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ return bodyPr.isSetRIns() ? Units.toPoints(bodyPr.getRIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the distance (in points) between the top of the text frame
+ * and the top of the inscribed rectangle of the shape that contains the text.
+ *
+ * @return the top margin
+ */
+ public double getMarginTop(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ return bodyPr.isSetTIns() ? Units.toPoints(bodyPr.getTIns()) : -1;
+ }
+ return -1;
+ }
+
+ /**
+ * Sets the botom margin.
+ * @see #getMarginBottom()
+ *
+ * @param margin the bottom margin
+ */
+ public void setMarginBottom(double margin){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(margin == -1) bodyPr.unsetBIns();
+ else bodyPr.setBIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the left margin.
+ * @see #getMarginLeft()
+ *
+ * @param margin the left margin
+ */
+ public void setMarginLeft(double margin){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(margin == -1) bodyPr.unsetLIns();
+ else bodyPr.setLIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the right margin.
+ * @see #getMarginRight()
+ *
+ * @param margin the right margin
+ */
+ public void setMarginRight(double margin){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(margin == -1) bodyPr.unsetRIns();
+ else bodyPr.setRIns(Units.toEMU(margin));
+ }
+ }
+
+ /**
+ * Sets the top margin.
+ * @see #getMarginTop()
+ *
+ * @param margin the top margin
+ */
+ public void setMarginTop(double margin){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(margin == -1) bodyPr.unsetTIns();
+ else bodyPr.setTIns(Units.toEMU(margin));
+ }
+ }
+
+
+ /**
+ * Returns the value indicating word wrap.
+ * One of the <code>Wrap*</code> constants defined in this class.
+ *
+ * @return the value indicating word wrap
+ */
+ public boolean getWordWrap(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ return shape.getTxBody().getBodyPr().getWrap() == STTextWrappingType.SQUARE;
+ }
+ return false;
+ }
+
+ /**
+ * Specifies how the text should be wrapped
+ *
+ * @param wrap the value indicating how the text should be wrapped
+ */
+ public void setWordWrap(boolean wrap){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ shape.getTxBody().getBodyPr().setWrap(wrap ? STTextWrappingType.SQUARE : STTextWrappingType.NONE);
+ }
+ }
+
+ /**
+ *
+ * Specifies that a shape should be auto-fit to fully contain the text described within it.
+ * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
+ *
+ * @param value type of autofit
+ */
+ public void setTextAutofit(TextAutofit value){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
+ if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
+ if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
+
+ switch(value){
+ case NONE: bodyPr.addNewNoAutofit(); break;
+ case NORMAL: bodyPr.addNewNormAutofit(); break;
+ case SHAPE: bodyPr.addNewSpAutoFit(); break;
+ }
+ }
+ }
+
+ /**
+ *
+ * @return type of autofit
+ */
+ public TextAutofit getTextAutofit(){
+ CTShape shape = (CTShape) getXmlObject();
+ if (shape.isSetTxBody()) {
+ CTTextBodyProperties bodyPr = shape.getTxBody().getBodyPr();
+ if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
+ else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
+ else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
+ }
+ return TextAutofit.NORMAL;
+ }
+
+
+ @Override
+ void onCopy(XSLFSheet srcSheet){
+ CTShape shape = (CTShape) getXmlObject();
+ if (!shape.isSetTxBody()) return;
+
+ CTPlaceholder ph = shape.getNvSpPr().getNvPr().getPh();
+ if(ph == null || !ph.isSetType()) return;
+
+ if(ph.getType() == STPlaceholderType.TITLE){
+
+ }
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
------------------------------------------------------------------------------
svn:executable = *
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java?rev=1156539&r1=1156538&r2=1156539&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFCommonSlideData.java Thu Aug 11 08:38:19 2011
@@ -18,6 +18,7 @@
package org.apache.poi.xslf.usermodel;
import org.apache.poi.POIXMLException;
+import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
@@ -34,6 +35,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+@Beta
public class XSLFCommonSlideData {
private final CTCommonSlideData data;
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,195 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+import org.apache.poi.util.Beta;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual;
+
+/**
+ *
+ * Specifies a connection shape.
+ *
+ * @author Yegor Kozlov
+ */
+@Beta
+public class XSLFConnectorShape extends XSLFSimpleShape {
+
+ /*package*/ XSLFConnectorShape(CTConnector shape, XSLFSheet sheet){
+ super(shape, sheet);
+ }
+
+ /**
+ * @param shapeId 1-based shapeId
+ */
+ static CTConnector prototype(int shapeId) {
+ CTConnector ct = CTConnector.Factory.newInstance();
+ CTConnectorNonVisual nvSpPr = ct.addNewNvCxnSpPr();
+ CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
+ cnv.setName("Connector " + shapeId);
+ cnv.setId(shapeId + 1);
+ nvSpPr.addNewCNvCxnSpPr();
+ nvSpPr.addNewNvPr();
+ CTShapeProperties spPr = ct.addNewSpPr();
+ CTPresetGeometry2D prst = spPr.addNewPrstGeom();
+ prst.setPrst(STShapeType.LINE);
+ prst.addNewAvLst();
+ CTLineProperties ln = spPr.addNewLn();
+ return ct;
+ }
+
+ /**
+ * Specifies the line end decoration, such as a triangle or arrowhead.
+ */
+ public void setLineHeadDecoration(LineDecoration style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetHeadEnd() ? ln.getHeadEnd() : ln.addNewHeadEnd();
+ if(style == null){
+ if(lnEnd.isSetType()) lnEnd.unsetType();
+ } else {
+ lnEnd.setType(STLineEndType.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineDecoration getLineHeadDecoration(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetHeadEnd()) return LineDecoration.NONE;
+
+ STLineEndType.Enum end = ln.getHeadEnd().getType();
+ return end == null ? LineDecoration.NONE : LineDecoration.values()[end.intValue() - 1];
+ }
+
+ /**
+ * specifies decorations which can be added to the head of a line.
+ */
+ public void setLineHeadWidth(LineEndWidth style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetHeadEnd() ? ln.getHeadEnd() : ln.addNewHeadEnd();
+ if(style == null){
+ if(lnEnd.isSetW()) lnEnd.unsetW();
+ } else {
+ lnEnd.setW(STLineEndWidth.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineEndWidth getLineHeadWidth(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetHeadEnd()) return null;
+
+ STLineEndWidth.Enum w = ln.getHeadEnd().getW();
+ return w == null ? null : LineEndWidth.values()[w.intValue() - 1];
+ }
+
+ /**
+ * Specifies the line end width in relation to the line width.
+ */
+ public void setLineHeadLength(LineEndLength style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetHeadEnd() ? ln.getHeadEnd() : ln.addNewHeadEnd();
+
+ if(style == null){
+ if(lnEnd.isSetLen()) lnEnd.unsetLen();
+ } else {
+ lnEnd.setLen(STLineEndLength.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineEndLength getLineHeadLength(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetHeadEnd()) return null;
+
+ STLineEndLength.Enum len = ln.getHeadEnd().getLen();
+ return len == null ? null : LineEndLength.values()[len.intValue() - 1];
+ }
+
+ /**
+ * Specifies the line end decoration, such as a triangle or arrowhead.
+ */
+ public void setLineTailDecoration(LineDecoration style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetTailEnd() ? ln.getTailEnd() : ln.addNewTailEnd();
+ if(style == null){
+ if(lnEnd.isSetType()) lnEnd.unsetType();
+ } else {
+ lnEnd.setType(STLineEndType.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineDecoration getLineTailDecoration(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetTailEnd()) return LineDecoration.NONE;
+
+ STLineEndType.Enum end = ln.getTailEnd().getType();
+ return end == null ? LineDecoration.NONE : LineDecoration.values()[end.intValue() - 1];
+ }
+
+ /**
+ * specifies decorations which can be added to the tail of a line.
+ */
+ public void setLineTailWidth(LineEndWidth style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetTailEnd() ? ln.getTailEnd() : ln.addNewTailEnd();
+ if(style == null){
+ if(lnEnd.isSetW()) lnEnd.unsetW();
+ } else {
+ lnEnd.setW(STLineEndWidth.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineEndWidth getLineTailWidth(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetTailEnd()) return null;
+
+ STLineEndWidth.Enum w = ln.getTailEnd().getW();
+ return w == null ? null : LineEndWidth.values()[w.intValue() - 1];
+ }
+
+ /**
+ * Specifies the line end width in relation to the line width.
+ */
+ public void setLineTailLength(LineEndLength style){
+ CTLineProperties ln = getSpPr().getLn();
+ CTLineEndProperties lnEnd = ln.isSetTailEnd() ? ln.getTailEnd() : ln.addNewTailEnd();
+
+ if(style == null){
+ if(lnEnd.isSetLen()) lnEnd.unsetLen();
+ } else {
+ lnEnd.setLen(STLineEndLength.Enum.forInt(style.ordinal() + 1));
+ }
+ }
+
+ public LineEndLength getLineTailLength(){
+ CTLineProperties ln = getSpPr().getLn();
+ if(!ln.isSetTailEnd()) return null;
+
+ STLineEndLength.Enum len = ln.getTailEnd().getLen();
+ return len == null ? null : LineEndLength.values()[len.intValue() - 1];
+ }
+
+}
\ No newline at end of file
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,84 @@
+package org.apache.poi.xslf.usermodel;
+
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.util.Beta;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
+
+import java.awt.*;
+
+
+/**
+ * @author Yegor Kozlov
+ */
+@Beta
+public class XSLFDrawing {
+ private XSLFSheet _sheet;
+ private int _shapeId = 1;
+ private CTGroupShape _spTree;
+
+ /*package*/ XSLFDrawing(XSLFSheet sheet, CTGroupShape spTree){
+ _sheet = sheet;
+ _spTree = spTree;
+ XmlObject[] cNvPr = sheet.getSpTree().selectPath(
+ "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
+ for(XmlObject o : cNvPr) {
+ CTNonVisualDrawingProps p = (CTNonVisualDrawingProps)o;
+ _shapeId = (int)Math.max(_shapeId, p.getId());
+ }
+ }
+
+ public XSLFAutoShape createAutoShape(){
+ CTShape sp = _spTree.addNewSp();
+ sp.set(XSLFAutoShape.prototype(_shapeId++));
+ XSLFAutoShape shape = new XSLFAutoShape(sp, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
+
+ public XSLFFreeformShape createFreeform(){
+ CTShape sp = _spTree.addNewSp();
+ sp.set(XSLFFreeformShape.prototype(_shapeId++));
+ XSLFFreeformShape shape = new XSLFFreeformShape(sp, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
+
+ public XSLFTextBox createTextBox(){
+ CTShape sp = _spTree.addNewSp();
+ sp.set(XSLFTextBox.prototype(_shapeId++));
+ XSLFTextBox shape = new XSLFTextBox(sp, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
+
+ public XSLFConnectorShape createConnector(){
+ CTConnector sp = _spTree.addNewCxnSp();
+ sp.set(XSLFConnectorShape.prototype(_shapeId++));
+ XSLFConnectorShape shape = new XSLFConnectorShape(sp, _sheet);
+ shape.setAnchor(new Rectangle());
+ shape.setLineColor(Color.black);
+ shape.setLineWidth(0.75);
+ return shape;
+ }
+
+ public XSLFGroupShape createGroup(){
+ CTGroupShape obj = _spTree.addNewGrpSp();
+ obj.set(XSLFGroupShape.prototype(_shapeId++));
+ XSLFGroupShape shape = new XSLFGroupShape(obj, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
+
+ public XSLFPictureShape createPicture(String rel){
+ CTPicture obj = _spTree.addNewPic();
+ obj.set(XSLFPictureShape.prototype(_shapeId++, rel));
+ XSLFPictureShape shape = new XSLFPictureShape(obj, _sheet);
+ shape.setAnchor(new Rectangle());
+ return shape;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java?rev=1156539&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java Thu Aug 11 08:38:19 2011
@@ -0,0 +1,81 @@
+/*
+ * ====================================================================
+ * 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.xslf.usermodel;
+
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.POIXMLFactory;
+import org.apache.poi.POIXMLRelation;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Instantiates sub-classes of POIXMLDocumentPart depending on their relationship type
+ *
+ * @author Yegor Kozlov
+ */
+@Beta
+public final class XSLFFactory extends POIXMLFactory {
+ private static final POILogger logger = POILogFactory.getLogger(XSLFFactory.class);
+
+ private XSLFFactory(){
+
+ }
+
+ private static final XSLFFactory inst = new XSLFFactory();
+
+ public static XSLFFactory getInstance(){
+ return inst;
+ }
+
+ @Override
+ public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackageRelationship rel, PackagePart part){
+ POIXMLRelation descriptor = XSLFRelation.getInstance(rel.getRelationshipType());
+ if(descriptor == null || descriptor.getRelationClass() == null){
+ logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
+ return new POIXMLDocumentPart(part, rel);
+ }
+
+ try {
+ Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
+ Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
+ return constructor.newInstance(part, rel);
+ } catch (Exception e){
+ throw new POIXMLException(e);
+ }
+ }
+
+ @Override
+ public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
+ try {
+ Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
+ Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
+ return constructor.newInstance();
+ } catch (Exception e){
+ throw new POIXMLException(e);
+ }
+ }
+
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFactory.java
------------------------------------------------------------------------------
svn:executable = *
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org