poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1165109 - /poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
Date Sun, 04 Sep 2011 20:51:21 GMT
Author: nick
Date: Sun Sep  4 20:51:21 2011
New Revision: 1165109

URL: http://svn.apache.org/viewvc?rev=1165109&view=rev
Log:
Convert the XSLF text extractor from using the old style low level code to use usermodel

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java?rev=1165109&r1=1165108&r2=1165109&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java Sun
Sep  4 20:51:21 2011
@@ -16,22 +16,21 @@
 ==================================================================== */
 package org.apache.poi.xslf.extractor;
 
+import java.io.IOException;
+
 import org.apache.poi.POIXMLTextExtractor;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 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.XSLFComments;
 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.XSLFSlide;
 import org.apache.xmlbeans.XmlException;
 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 static final XSLFRelation[] SUPPORTED_TYPES = new XSLFRelation[] {
@@ -89,51 +88,50 @@ public class XSLFPowerPointExtractor ext
 		return getText(slidesByDefault, notesByDefault);
 	}
 	
-	/**
-	 * Gets the requested text from the file
-	 * @param slideText Should we retrieve text from slides?
-	 * @param notesText Should we retrieve text from notes?
-	 */
-	public String getText(boolean slideText, boolean notesText) {
-		StringBuffer text = new StringBuffer();
+   /**
+    * Gets the requested text from the file
+    * @param slideText Should we retrieve text from slides?
+    * @param notesText Should we retrieve text from notes?
+    */
+   public String getText(boolean slideText, boolean notesText) {
+      StringBuffer text = new StringBuffer();
+
+      XSLFSlide[] slides = slideshow.getSlides();
+
+      for (XSLFSlide slide : slides) {
+         try {
+            XSLFNotes notes = slide.getNotes();
+            XSLFComments comments = slide.getComments();
+
+            // TODO Do the slide's name
+
+            // Do the slide's text if requested
+            if (slideText) {
+               extractText(slide.getCommonSlideData(), text);
+
+               // 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"
+                     );
+                  }
+               }
+            }
 
-		XSLFSlide[] slides = slideshow.getSlides();
-        try {
-            XSLFSlideShow xsl = new XSLFSlideShow(slideshow.getPackage());
-            for (int i = 0; i < slides.length; i++) {
-                CTSlideIdListEntry slideId = slideshow.getCTPresentation().getSldIdLst().getSldIdArray(i);
-
-                // For now, still very low level
-                CTNotesSlide notes =
-                        xsl.getNotes(slideId);
-                CTCommentList comments =
-                        xsl.getSlideComments(slideId);
-
-                if (slideText) {
-                    extractText(new XSLFCommonSlideData(slides[i].getXmlObject().getCSld()),
text);
-
-                    // Comments too for the slide
-                    if (comments != null) {
-                        for (CTComment comment : comments.getCmList()) {
-                            // TODO - comment authors too
-                            // (They're in another stream)
-                            text.append(
-                                    comment.getText() + "\n"
-                            );
-                        }
-                    }
-                }
-
-                if (notesText && notes != null) {
-                    extractText(new XSLFCommonSlideData(notes.getCSld()), text);
-                }
+            // Do the notes if requested
+            if (notesText && notes != null) {
+               extractText(notes.getCommonSlideData(), text);
             }
-        } catch (Exception e) {
+         } catch (Exception e) {
             throw new RuntimeException(e);
-        }
+         }
+      }
 
-        return text.toString();
-	}
+      return text.toString();
+   }
 	
 	private void extractText(XSLFCommonSlideData data, StringBuffer text) {
         for (DrawingParagraph p : data.getText()) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message