Convert the XSLF text extractor from using the old style low level code to use usermodel

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1165109 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-09-04 20:51:21 +00:00
parent a88a80e615
commit 80741fdf37
1 changed files with 41 additions and 43 deletions

View File

@ -16,22 +16,21 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xslf.extractor; package org.apache.poi.xslf.extractor;
import java.io.IOException;
import org.apache.poi.POIXMLTextExtractor; import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFComments;
import org.apache.poi.xslf.usermodel.XSLFCommonSlideData; import org.apache.poi.xslf.usermodel.XSLFCommonSlideData;
import org.apache.poi.xslf.usermodel.XSLFNotes;
import org.apache.poi.xslf.usermodel.XSLFRelation; import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.CTComment; 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;
public class XSLFPowerPointExtractor extends POIXMLTextExtractor { public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
public static final XSLFRelation[] SUPPORTED_TYPES = new XSLFRelation[] { public static final XSLFRelation[] SUPPORTED_TYPES = new XSLFRelation[] {
@ -98,23 +97,21 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
XSLFSlide[] slides = slideshow.getSlides(); XSLFSlide[] slides = slideshow.getSlides();
for (XSLFSlide slide : slides) {
try { try {
XSLFSlideShow xsl = new XSLFSlideShow(slideshow.getPackage()); XSLFNotes notes = slide.getNotes();
for (int i = 0; i < slides.length; i++) { XSLFComments comments = slide.getComments();
CTSlideIdListEntry slideId = slideshow.getCTPresentation().getSldIdLst().getSldIdArray(i);
// For now, still very low level // TODO Do the slide's name
CTNotesSlide notes =
xsl.getNotes(slideId);
CTCommentList comments =
xsl.getSlideComments(slideId);
// Do the slide's text if requested
if (slideText) { if (slideText) {
extractText(new XSLFCommonSlideData(slides[i].getXmlObject().getCSld()), text); extractText(slide.getCommonSlideData(), text);
// Comments too for the slide // If the slide has comments, do those too
if (comments != null) { if (comments != null) {
for (CTComment comment : comments.getCmList()) { for (CTComment comment : comments.getCTCommentsList().getCmList()) {
// TODO - comment authors too // TODO - comment authors too
// (They're in another stream) // (They're in another stream)
text.append( text.append(
@ -124,13 +121,14 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
} }
} }
// Do the notes if requested
if (notesText && notes != null) { if (notesText && notes != null) {
extractText(new XSLFCommonSlideData(notes.getCSld()), text); extractText(notes.getCommonSlideData(), text);
}
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}
return text.toString(); return text.toString();
} }