From: Nick Burch Date: Sun, 4 Sep 2011 21:16:32 +0000 (+0000) Subject: Update XSLFPowerPointExtractor to include Comment Authors along with comment text X-Git-Tag: REL_3_8_BETA5~189 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9e5ce7c24895101f3d0710627f399186c80dae1b;p=poi.git Update XSLFPowerPointExtractor to include Comment Authors along with comment text git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1165112 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 71e14e0053..f7149a972b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,9 @@ + XSLFPowerPointExtractor support for including comment authors with comment text + Converted XSLFPowerPointExtractor to use UserModel for all text extraction + XSLF initial UserModel support for Notes and Comments for Slides 51678 - Extracting text from Bug51524.zip is slow diff --git a/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java b/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java index 4614591a2d..536a34bfbe 100644 --- a/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java +++ b/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java @@ -24,6 +24,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.xslf.XSLFSlideShow; import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.apache.poi.xslf.usermodel.XSLFCommentAuthors; import org.apache.poi.xslf.usermodel.XSLFComments; import org.apache.poi.xslf.usermodel.XSLFCommonSlideData; import org.apache.poi.xslf.usermodel.XSLFNotes; @@ -31,6 +32,7 @@ import org.apache.poi.xslf.usermodel.XSLFRelation; import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTComment; +import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor; public class XSLFPowerPointExtractor extends POIXMLTextExtractor { public static final XSLFRelation[] SUPPORTED_TYPES = new XSLFRelation[] { @@ -97,6 +99,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor { StringBuffer text = new StringBuffer(); XSLFSlide[] slides = slideshow.getSlides(); + XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors(); for (XSLFSlide slide : slides) { try { @@ -112,11 +115,17 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor { // If the slide has comments, do those too if (comments != null) { for (CTComment comment : comments.getCTCommentsList().getCmList()) { - // TODO - comment authors too - // (They're in another stream) - text.append( - comment.getText() + "\n" - ); + // Do the author if we can + if (commentAuthors != null) { + CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId()); + if(author != null) { + text.append(author.getName() + ": "); + } + } + + // Then the comment text, with a new line afterwards + text.append(comment.getText()); + text.append("\n"); } } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java index 12db514099..8cf2afbe6d 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java @@ -112,6 +112,10 @@ public class TestXSLFPowerPointExtractor extends TestCase { // 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 + assertTrue("Unable to find expected word in text\n" + text, text.contains("XPVMWARE01")); } public void testTable() throws Exception {