Start on XSLF notes master support, and add a XMLSlideShow basics test, along with making it easier to get to the common slide data via XSLFSheet
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1165104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47c706b997
commit
407ec57e37
@ -0,0 +1,78 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
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.openxml4j.opc.PackagePart;
|
||||||
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
|
import org.apache.poi.sl.usermodel.MasterSheet;
|
||||||
|
import org.apache.poi.util.Beta;
|
||||||
|
import org.apache.xmlbeans.XmlException;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMaster;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes master object associated with this layout.
|
||||||
|
* <p>
|
||||||
|
* Within a notes master slide are contained all elements
|
||||||
|
* that describe the objects and their corresponding formatting
|
||||||
|
* for within a presentation slide.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Within a nodes master slide are two main elements.
|
||||||
|
* The cSld element specifies the common slide elements such as shapes and
|
||||||
|
* their attached text bodies. Then the notesStyles element specifies the
|
||||||
|
* formatting for the text within each of these shapes.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Yegor Kozlov
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
public class XSLFNotesMaster extends XSLFSheet {
|
||||||
|
private CTNotesMaster _slide;
|
||||||
|
private Map<String, XSLFSlideLayout> _layouts;
|
||||||
|
private XSLFTheme _theme;
|
||||||
|
|
||||||
|
XSLFNotesMaster() {
|
||||||
|
super();
|
||||||
|
_slide = CTNotesMaster.Factory.newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected XSLFNotesMaster(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
||||||
|
super(part, rel);
|
||||||
|
NotesMasterDocument doc =
|
||||||
|
NotesMasterDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
|
_slide = doc.getNotesMaster();
|
||||||
|
setCommonSlideData(_slide.getCSld());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CTNotesMaster getXmlObject() {
|
||||||
|
return _slide;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getRootElementName(){
|
||||||
|
return "notesMaster";
|
||||||
|
}
|
||||||
|
}
|
@ -97,6 +97,13 @@ public class XSLFRelation extends POIXMLRelation {
|
|||||||
XSLFSlideMaster.class
|
XSLFSlideMaster.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final XSLFRelation NOTES_MASTER = new XSLFRelation(
|
||||||
|
"application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml",
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster",
|
||||||
|
"/ppt/notesMasters/notesMaster#.xml",
|
||||||
|
XSLFNotesMaster.class
|
||||||
|
);
|
||||||
|
|
||||||
public static final XSLFRelation COMMENTS = new XSLFRelation(
|
public static final XSLFRelation COMMENTS = new XSLFRelation(
|
||||||
"application/vnd.openxmlformats-officedocument.presentationml.comments+xml",
|
"application/vnd.openxmlformats-officedocument.presentationml.comments+xml",
|
||||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||||
|
@ -24,11 +24,13 @@ import org.apache.poi.util.Beta;
|
|||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -41,6 +43,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public abstract class XSLFSheet extends POIXMLDocumentPart {
|
public abstract class XSLFSheet extends POIXMLDocumentPart {
|
||||||
|
private XSLFCommonSlideData _commonSlideData;
|
||||||
private XSLFDrawing _drawing;
|
private XSLFDrawing _drawing;
|
||||||
private List<XSLFShape> _shapes;
|
private List<XSLFShape> _shapes;
|
||||||
private CTGroupShape _spTree;
|
private CTGroupShape _spTree;
|
||||||
@ -79,6 +82,16 @@ public abstract class XSLFSheet extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
public abstract XmlObject getXmlObject();
|
public abstract XmlObject getXmlObject();
|
||||||
|
|
||||||
|
public XSLFCommonSlideData getCommonSlideData() {
|
||||||
|
return _commonSlideData;
|
||||||
|
}
|
||||||
|
protected void setCommonSlideData(CTCommonSlideData data) {
|
||||||
|
if(data == null) {
|
||||||
|
_commonSlideData = null;
|
||||||
|
} else {
|
||||||
|
_commonSlideData = new XSLFCommonSlideData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XSLFDrawing getDrawing(){
|
private XSLFDrawing getDrawing(){
|
||||||
if(_drawing == null) {
|
if(_drawing == null) {
|
||||||
|
@ -70,6 +70,7 @@ public final class XSLFSlide extends XSLFSheet {
|
|||||||
SldDocument doc =
|
SldDocument doc =
|
||||||
SldDocument.Factory.parse(getPackagePart().getInputStream());
|
SldDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
_slide = doc.getSld();
|
_slide = doc.getSld();
|
||||||
|
setCommonSlideData(_slide.getCSld());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ public class XSLFSlideLayout extends XSLFSheet {
|
|||||||
SldLayoutDocument doc =
|
SldLayoutDocument doc =
|
||||||
SldLayoutDocument.Factory.parse(getPackagePart().getInputStream());
|
SldLayoutDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
_layout = doc.getSldLayout();
|
_layout = doc.getSldLayout();
|
||||||
|
setCommonSlideData(_layout.getCSld());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ import java.util.Map;
|
|||||||
SldMasterDocument doc =
|
SldMasterDocument doc =
|
||||||
SldMasterDocument.Factory.parse(getPackagePart().getInputStream());
|
SldMasterDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
_slide = doc.getSldMaster();
|
_slide = doc.getSldMaster();
|
||||||
|
setCommonSlideData(_slide.getCSld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
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 junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||||
|
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
||||||
|
|
||||||
|
public class TestXMLSlideShow extends TestCase {
|
||||||
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
private OPCPackage pack;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testContainsMainContentType() throws Exception {
|
||||||
|
boolean found = false;
|
||||||
|
for(PackagePart part : pack.getParts()) {
|
||||||
|
if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
//System.out.println(part);
|
||||||
|
}
|
||||||
|
assertTrue(found);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOpen() throws Exception {
|
||||||
|
XMLSlideShow xml;
|
||||||
|
|
||||||
|
// With the finalised uri, should be fine
|
||||||
|
xml = new XMLSlideShow(pack);
|
||||||
|
// Check the core
|
||||||
|
assertNotNull(xml.getCTPresentation());
|
||||||
|
|
||||||
|
// Check it has some slides
|
||||||
|
assertNotNull(xml.getSlides().length);
|
||||||
|
assertTrue(xml.getSlides().length > 0);
|
||||||
|
|
||||||
|
assertNotNull(xml.getSlideMasters().length);
|
||||||
|
assertTrue(xml.getSlideMasters().length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSlideBasics() throws Exception {
|
||||||
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
|
|
||||||
|
// Should have 1 master
|
||||||
|
assertEquals(1, xml.getSlideMasters().length);
|
||||||
|
|
||||||
|
// Should have two sheets
|
||||||
|
assertEquals(2, xml.getSlides().length);
|
||||||
|
|
||||||
|
// Check they're as expected
|
||||||
|
CTSlideIdListEntry[] slides = new CTSlideIdListEntry[
|
||||||
|
xml.getCTPresentation().getSldIdLst().getSldIdList().size()];
|
||||||
|
xml.getCTPresentation().getSldIdLst().getSldIdList().toArray(slides);
|
||||||
|
|
||||||
|
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.getSlides()[0]);
|
||||||
|
assertNotNull(xml.getSlides()[0]);
|
||||||
|
|
||||||
|
// And check they have notes as expected
|
||||||
|
// TODO
|
||||||
|
// assertNotNull(xml.getNotes(slides[0]));
|
||||||
|
// assertNotNull(xml.getNotes(slides[1]));
|
||||||
|
|
||||||
|
// Next up look for the slide master
|
||||||
|
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
||||||
|
xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().size()];
|
||||||
|
xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().toArray(masters);
|
||||||
|
|
||||||
|
assertEquals(2147483648l, masters[0].getId());
|
||||||
|
assertEquals("rId1", masters[0].getId2());
|
||||||
|
assertNotNull(xml.getSlideMasters()[0]);
|
||||||
|
|
||||||
|
// Finally look for the notes master
|
||||||
|
CTNotesMasterIdListEntry notesMaster =
|
||||||
|
xml.getCTPresentation().getNotesMasterIdLst().getNotesMasterId();
|
||||||
|
assertNotNull(notesMaster);
|
||||||
|
// TODO Get the wrapper
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMetadataBasics() throws Exception {
|
||||||
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
|
|
||||||
|
assertNotNull(xml.getProperties().getCoreProperties());
|
||||||
|
assertNotNull(xml.getProperties().getExtendedProperties());
|
||||||
|
|
||||||
|
assertEquals("Microsoft Office PowerPoint", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
|
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
||||||
|
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
||||||
|
|
||||||
|
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
|
||||||
|
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user