import org.apache.poi.xslf.usermodel.XSLFNotes;
import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTComment;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor;
try {
XSLFNotes notes = slide.getNotes();
XSLFComments comments = slide.getComments();
+ XSLFSlideMaster master = slide.getMasterSheet();
// TODO Do the slide's name
+ // (Stored in docProps/app.xml)
// Do the slide's text if requested
if (slideText) {
extractText(slide.getCommonSlideData(), text);
+
+ // If there's a master sheet, grab text from there
+ if(master != null) {
+ extractText(master.getCommonSlideData(), text);
+ }
// If the slide has comments, do those too
if (comments != null) {
* Tests for HXFPowerPointExtractor
*/
public class TestXSLFPowerPointExtractor extends TestCase {
- /**
- * A simple file
- */
- private XSLFSlideShow xmlA;
- private OPCPackage pkg;
+ /**
+ * A simple file
+ */
+ private XSLFSlideShow xmlA;
+ private OPCPackage pkg;
+
+ private POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- protected void setUp() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- pkg = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
- xmlA = new XSLFSlideShow(pkg);
- }
+ protected void setUp() throws Exception {
+ slTests = POIDataSamples.getSlideShowInstance();
+ pkg = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
+ xmlA = new XSLFSlideShow(pkg);
+ }
/**
* Get text out of the simple file
// Check Basics
assertTrue(text.startsWith("Lorem ipsum dolor sit amet\n"));
- assertTrue(text.endsWith("amet\n\n"));
+ assertTrue(text.contains("amet\n\n"));
+
+ // Our master text, for tests
+ String masterText =
+ "Click to edit Master title style\n" +
+ "Click to edit Master text styles\n" +
+ "Second level\n" +
+ "Third level\n" +
+ "Fourth level\n" +
+ "Fifth level\n";
// Just slides, no notes
text = extractor.getText(true, false);
"Lorem ipsum dolor sit amet\n" +
"Nunc at risus vel erat tempus posuere. Aenean non ante.\n" +
"\n" +
+ masterText +
+ "\n\n\n" +
"Lorem ipsum dolor sit amet\n" +
"Lorem\n" +
"ipsum\n" +
"dolor\n" +
"sit\n" +
"amet\n" +
- "\n", text
+ "\n" +
+ masterText +
+ "\n\n\n"
+ , text
);
// Just notes, no slides
assertEquals(
"Lorem ipsum dolor sit amet\n" +
"Nunc at risus vel erat tempus posuere. Aenean non ante.\n" +
- "\n\n\n" +
+ "\n" +
+ masterText +
+ "\n\n\n\n\n" +
"Lorem ipsum dolor sit amet\n" +
"Lorem\n" +
"ipsum\n" +
"dolor\n" +
"sit\n" +
"amet\n" +
- "\n\n\n", text
+ "\n" +
+ masterText +
+ "\n\n\n\n\n"
+ , text
);
// Via set defaults
);
}
- public void testGetComments() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx")));
- XSLFPowerPointExtractor extractor =
- new XSLFPowerPointExtractor(xmlA);
-
- String text = extractor.getText();
- assertTrue(text.length() > 0);
-
- // Check comments are there
- assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
+ public void testGetComments() throws Exception {
+ XSLFSlideShow xml =
+ new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("45545_Comment.pptx")));
+ XSLFPowerPointExtractor extractor =
+ new XSLFPowerPointExtractor(xml);
+
+ String text = extractor.getText();
+ assertTrue(text.length() > 0);
+
+ // Check comments are there
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
-
- // Check the authors came through too
+
+ // Check the authors came through too
assertTrue("Unable to find expected word in text\n" + text, text.contains("XPVMWARE01"));
+ }
+
+ public void testGetMasterText() throws Exception {
+ XSLFSlideShow xml =
+ new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("WithMaster.pptx")));
+ XSLFPowerPointExtractor extractor =
+ new XSLFPowerPointExtractor(xml);
+
+ String text = extractor.getText();
+ assertTrue(text.length() > 0);
+
+ // Check master text is there
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("Master footer is here"));
}
public void testTable() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("present1.pptx")));
+ XSLFSlideShow xml =
+ new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream("present1.pptx")));
XSLFPowerPointExtractor extractor =
- new XSLFPowerPointExtractor(xmlA);
+ new XSLFPowerPointExtractor(xml);
String text = extractor.getText();
assertTrue(text.length() > 0);
* well as from the normal file
*/
public void testDifferentSubformats() throws Exception {
- POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String[] extensions = new String[] {
"pptx", "pptm", "ppsm", "ppsx",
"thmx",
};
for(String extension : extensions) {
String filename = "testPPT." + extension;
- xmlA = new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream(filename)));
+ XSLFSlideShow xml =
+ new XSLFSlideShow(OPCPackage.open(slTests.openResourceAsStream(filename)));
XSLFPowerPointExtractor extractor =
- new XSLFPowerPointExtractor(xmlA);
+ new XSLFPowerPointExtractor(xml);
String text = extractor.getText();
if(extension.equals("thmx")) {