2007-12-30 12:46:20 -05:00
|
|
|
/* ====================================================================
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2008-03-09 10:21:34 -04:00
|
|
|
package org.apache.poi.xslf;
|
2007-12-30 12:46:20 -05:00
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
2016-06-18 19:48:00 -04:00
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
2015-12-31 21:22:31 -05:00
|
|
|
import java.io.IOException;
|
2014-08-27 20:08:41 -04:00
|
|
|
|
2009-08-23 08:34:24 -04:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2015-12-31 21:22:31 -05:00
|
|
|
import org.apache.poi.POIXMLProperties.CoreProperties;
|
|
|
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
2009-03-18 14:54:01 -04:00
|
|
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
2009-01-29 07:44:31 -05:00
|
|
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
2016-06-18 19:48:00 -04:00
|
|
|
import org.apache.poi.sl.usermodel.ShapeType;
|
|
|
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
|
|
|
import org.apache.poi.xslf.usermodel.XSLFAutoShape;
|
|
|
|
import org.apache.poi.xslf.usermodel.XSLFBackground;
|
2010-07-29 08:02:03 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
2016-06-18 19:48:00 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
2015-09-30 19:06:39 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
|
2015-12-31 21:22:31 -05:00
|
|
|
import org.apache.xmlbeans.XmlException;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
|
2007-12-30 12:46:20 -05:00
|
|
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
|
|
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
public class TestXSLFSlideShow {
|
2009-08-23 08:34:24 -04:00
|
|
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
|
|
|
private OPCPackage pack;
|
2007-12-30 12:46:20 -05:00
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
2009-08-23 08:34:24 -04:00
|
|
|
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
|
2007-12-30 12:46:20 -05:00
|
|
|
}
|
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
@Test
|
2007-12-30 12:46:20 -05:00
|
|
|
public void testContainsMainContentType() throws Exception {
|
|
|
|
boolean found = false;
|
|
|
|
for(PackagePart part : pack.getParts()) {
|
2010-07-29 08:02:03 -04:00
|
|
|
if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
|
2007-12-30 12:46:20 -05:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertTrue(found);
|
|
|
|
}
|
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
@Test
|
|
|
|
public void testOpen() throws IOException, OpenXML4JException, XmlException {
|
|
|
|
// With the finalized uri, should be fine
|
|
|
|
XSLFSlideShow xml = new XSLFSlideShow(pack);
|
2007-12-30 12:46:20 -05:00
|
|
|
// Check the core
|
|
|
|
assertNotNull(xml.getPresentation());
|
|
|
|
|
|
|
|
// Check it has some slides
|
2015-12-31 21:22:31 -05:00
|
|
|
assertNotEquals(0, xml.getSlideReferences().sizeOfSldIdArray());
|
|
|
|
assertNotEquals(0, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
|
|
|
|
|
|
|
|
xml.close();
|
2007-12-30 12:46:20 -05:00
|
|
|
}
|
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
@Test
|
|
|
|
public void testSlideBasics() throws IOException, OpenXML4JException, XmlException {
|
2009-08-23 08:34:24 -04:00
|
|
|
XSLFSlideShow xml = new XSLFSlideShow(pack);
|
2007-12-30 12:46:20 -05:00
|
|
|
|
|
|
|
// Should have 1 master
|
|
|
|
assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
|
2014-08-27 20:08:41 -04:00
|
|
|
|
2007-12-30 12:46:20 -05:00
|
|
|
// Should have three sheets
|
|
|
|
assertEquals(2, xml.getSlideReferences().sizeOfSldIdArray());
|
2014-08-27 20:08:41 -04:00
|
|
|
|
2007-12-30 12:46:20 -05:00
|
|
|
// Check they're as expected
|
2014-08-27 20:08:41 -04:00
|
|
|
CTSlideIdListEntry[] slides = xml.getSlideReferences().getSldIdArray();
|
|
|
|
|
2007-12-30 12:46:20 -05:00
|
|
|
assertEquals(256, slides[0].getId());
|
|
|
|
assertEquals(257, slides[1].getId());
|
|
|
|
assertEquals("rId2", slides[0].getId2());
|
|
|
|
assertEquals("rId3", slides[1].getId2());
|
|
|
|
|
|
|
|
// Now get those objects
|
|
|
|
assertNotNull(xml.getSlide(slides[0]));
|
|
|
|
assertNotNull(xml.getSlide(slides[1]));
|
|
|
|
|
|
|
|
// And check they have notes as expected
|
|
|
|
assertNotNull(xml.getNotes(slides[0]));
|
|
|
|
assertNotNull(xml.getNotes(slides[1]));
|
|
|
|
|
|
|
|
// And again for the master
|
2014-08-27 20:08:41 -04:00
|
|
|
CTSlideMasterIdListEntry[] masters = xml.getSlideMasterReferences().getSldMasterIdArray();
|
2010-07-02 17:45:40 -04:00
|
|
|
|
2007-12-30 12:46:20 -05:00
|
|
|
assertEquals(2147483648l, masters[0].getId());
|
|
|
|
assertEquals("rId1", masters[0].getId2());
|
|
|
|
assertNotNull(xml.getSlideMaster(masters[0]));
|
2015-12-31 21:22:31 -05:00
|
|
|
|
|
|
|
xml.close();
|
2007-12-30 12:46:20 -05:00
|
|
|
}
|
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
@Test
|
|
|
|
public void testMetadataBasics() throws IOException, OpenXML4JException, XmlException {
|
2009-08-23 08:34:24 -04:00
|
|
|
XSLFSlideShow xml = new XSLFSlideShow(pack);
|
2007-12-30 12:46:20 -05:00
|
|
|
|
2008-04-09 08:22:23 -04:00
|
|
|
assertNotNull(xml.getProperties().getCoreProperties());
|
|
|
|
assertNotNull(xml.getProperties().getExtendedProperties());
|
2008-01-03 09:28:46 -05:00
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
CTProperties props = xml.getProperties().getExtendedProperties().getUnderlyingProperties();
|
|
|
|
assertEquals("Microsoft Office PowerPoint", props.getApplication());
|
|
|
|
assertEquals(0, props.getCharacters());
|
|
|
|
assertEquals(0, props.getLines());
|
|
|
|
|
|
|
|
CoreProperties cprops = xml.getProperties().getCoreProperties();
|
|
|
|
assertNull(cprops.getTitle());
|
|
|
|
assertNull(cprops.getUnderlyingProperties().getSubjectProperty().getValue());
|
2008-01-03 09:28:46 -05:00
|
|
|
|
2015-12-31 21:22:31 -05:00
|
|
|
xml.close();
|
2007-12-30 12:46:20 -05:00
|
|
|
}
|
2016-06-18 19:48:00 -04:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMasterBackground() throws IOException {
|
|
|
|
XMLSlideShow ppt = new XMLSlideShow();
|
|
|
|
XSLFBackground b = ppt.getSlideMasters().get(0).getBackground();
|
|
|
|
b.setFillColor(Color.RED);
|
|
|
|
|
|
|
|
XSLFSlide sl = ppt.createSlide();
|
|
|
|
XSLFAutoShape as = sl.createAutoShape();
|
|
|
|
as.setAnchor(new Rectangle2D.Double(100,100,100,100));
|
|
|
|
as.setShapeType(ShapeType.CLOUD);
|
|
|
|
|
|
|
|
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
|
|
|
ppt.close();
|
|
|
|
|
|
|
|
XSLFBackground b2 = ppt2.getSlideMasters().get(0).getBackground();
|
|
|
|
assertEquals(Color.RED, b2.getFillColor());
|
|
|
|
|
|
|
|
ppt2.close();
|
|
|
|
}
|
2007-12-30 12:46:20 -05:00
|
|
|
}
|