#62319 - handle slide layouts in extractor

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1829677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-04-20 20:00:46 +00:00
parent 7ddef62cc4
commit a276d5d3f6
5 changed files with 52 additions and 28 deletions

View File

@ -116,8 +116,46 @@ public class SlideShowExtractor<
public String getText() {
final StringBuilder sb = new StringBuilder();
for (final Slide<S, P> slide : slideshow.getSlides()) {
sb.append(getText(slide));
}
return sb.toString();
}
public String getText(final Slide<S,P> slide) {
final StringBuilder sb = new StringBuilder();
if (slidesByDefault) {
printShapeText(slide, sb);
}
if (masterByDefault) {
for (final MasterSheet<S,P> master : slideshow.getSlideMasters()) {
final MasterSheet<S,P> ms = slide.getMasterSheet();
printSlideMaster(ms, sb);
// only print slide layout, if it's a different instance
final MasterSheet<S,P> sl = slide.getSlideLayout();
if (sl != ms) {
printSlideMaster(sl, sb);
}
}
if (commentsByDefault) {
printComments(slide, sb);
}
if (notesByDefault) {
printNotes(slide, sb);
}
return sb.toString();
}
private void printSlideMaster(final MasterSheet<S,P> master, final StringBuilder sb) {
if (master == null) {
return;
}
for (final Shape<S,P> shape : master) {
if (shape instanceof TextShape) {
final TextShape<S,P> ts = (TextShape<S,P>)shape;
@ -138,32 +176,6 @@ public class SlideShowExtractor<
}
}
}
}
for (final Slide<S, P> slide : slideshow.getSlides()) {
sb.append(getText(slide));
}
return sb.toString();
}
public String getText(final Slide<S,P> slide) {
final StringBuilder sb = new StringBuilder();
if (slidesByDefault) {
printShapeText(slide, sb);
}
if (commentsByDefault) {
printComments(slide, sb);
}
if (notesByDefault) {
printNotes(slide, sb);
}
return sb.toString();
}
private String printHeaderReturnFooter(final Sheet<S,P> sheet, final StringBuilder sb) {
final Sheet<S, P> m = (sheet instanceof Slide) ? sheet.getMasterSheet() : sheet;

View File

@ -76,4 +76,11 @@ public interface Slide<
* @return the comment(s) for this slide
*/
List<? extends Comment> getComments();
/**
* @return the assigned slide layout
*
* @since POI 4.0.0
*/
MasterSheet getSlideLayout();
}

View File

@ -141,6 +141,7 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
return getSlideLayout();
}
@Override
public XSLFSlideLayout getSlideLayout(){
if(_layout == null){
for (POIXMLDocumentPart p : getRelations()) {

View File

@ -177,7 +177,6 @@ public class TestXSLFPowerPointExtractor {
}
@Test
@Ignore("currently slidelayouts aren't yet supported")
public void testGetMasterText() throws Exception {
try (XMLSlideShow xml = openPPTX("WithMaster.pptx");
SlideShowExtractor extractor = new SlideShowExtractor(xml)) {
@ -205,13 +204,10 @@ public class TestXSLFPowerPointExtractor {
String wholeText =
"First page title\n" +
"First page subtitle\n" +
"This is the Master Title\n" +
"This text comes from the Master Slide\n" +
"\n" +
// TODO Detect we didn't have a title, and include the master one
"2nd page subtitle\n" +
"Footer from the master slide\n" +
"This is the Master Title\n" +
"This text comes from the Master Slide\n";
assertEquals(wholeText, text);
}

View File

@ -501,4 +501,12 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
return false;
}
}
@Override
public HSLFMasterSheet getSlideLayout(){
// TODO: find out how we can find the mastersheet base on the slide layout type, i.e.
// getSlideRecord().getSlideAtom().getSSlideLayoutAtom().getGeometryType()
return getMasterSheet();
}
}