Search in sources :

Example 1 with CTCommentAuthor

use of org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor in project poi by apache.

the class XSLFPowerPointExtractor method getText.

/**
    * Gets the requested text from the slide
    * 
    * @param slide the slide to retrieve the text from
    * @param slideText Should we retrieve text from slides?
    * @param notesText Should we retrieve text from notes?
    * @param masterText Should we retrieve text from master slides?
    * 
    * @return the extracted text
    */
public static String getText(XSLFSlide slide, boolean slideText, boolean notesText, boolean masterText) {
    StringBuilder text = new StringBuilder();
    XSLFCommentAuthors commentAuthors = slide.getSlideShow().getCommentAuthors();
    XSLFNotes notes = slide.getNotes();
    XSLFComments comments = slide.getComments();
    XSLFSlideLayout layout = slide.getSlideLayout();
    XSLFSlideMaster master = layout.getSlideMaster();
    // Do the slide's text if requested
    if (slideText) {
        extractText(slide, false, text);
        // If requested, get text from the master and it's layout 
        if (masterText) {
            assert (layout != null);
            extractText(layout, true, text);
            assert (master != null);
            extractText(master, true, text);
        }
        // If the slide has comments, do those too
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmArray()) {
                // 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");
            }
        }
    }
    // Do the notes if requested
    if (notesText && notes != null) {
        extractText(notes, false, text);
    }
    return text.toString();
}
Also used : XSLFCommentAuthors(org.apache.poi.xslf.usermodel.XSLFCommentAuthors) XSLFSlideMaster(org.apache.poi.xslf.usermodel.XSLFSlideMaster) CTComment(org.openxmlformats.schemas.presentationml.x2006.main.CTComment) XSLFComments(org.apache.poi.xslf.usermodel.XSLFComments) CTCommentAuthor(org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor) XSLFSlideLayout(org.apache.poi.xslf.usermodel.XSLFSlideLayout) XSLFNotes(org.apache.poi.xslf.usermodel.XSLFNotes)

Example 2 with CTCommentAuthor

use of org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor in project tika by apache.

the class XSLFPowerPointExtractorDecorator method buildXHTML.

/**
     * @see org.apache.poi.xslf.extractor.XSLFPowerPointExtractor#getText()
     */
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, IOException {
    XMLSlideShow slideShow = (XMLSlideShow) extractor.getDocument();
    XSLFCommentAuthors commentAuthors = slideShow.getCommentAuthors();
    List<XSLFSlide> slides = slideShow.getSlides();
    for (XSLFSlide slide : slides) {
        String slideDesc;
        if (slide.getPackagePart() != null && slide.getPackagePart().getPartName() != null) {
            slideDesc = getJustFileName(slide.getPackagePart().getPartName().toString());
            slideDesc += "_";
        } else {
            slideDesc = null;
        }
        // slide content
        xhtml.startElement("div", "class", "slide-content");
        extractContent(slide.getShapes(), false, xhtml, slideDesc);
        xhtml.endElement("div");
        // slide layout which is the master sheet for this slide
        xhtml.startElement("div", "class", "slide-master-content");
        XSLFSlideLayout slideLayout = slide.getMasterSheet();
        extractContent(slideLayout.getShapes(), true, xhtml, null);
        xhtml.endElement("div");
        // slide master which is the master sheet for all text layouts
        XSLFSheet slideMaster = slideLayout.getMasterSheet();
        extractContent(slideMaster.getShapes(), true, xhtml, null);
        // notes (if present)
        XSLFNotes slideNotes = slide.getNotes();
        if (slideNotes != null) {
            xhtml.startElement("div", "class", "slide-notes");
            extractContent(slideNotes.getShapes(), false, xhtml, slideDesc);
            // master sheet for this notes
            XSLFNotesMaster notesMaster = slideNotes.getMasterSheet();
            if (notesMaster != null) {
                extractContent(notesMaster.getShapes(), true, xhtml, null);
            }
            xhtml.endElement("div");
        }
        // comments (if present)
        XSLFComments comments = slide.getComments();
        if (comments != null) {
            StringBuilder authorStringBuilder = new StringBuilder();
            for (int i = 0; i < comments.getNumberOfComments(); i++) {
                authorStringBuilder.setLength(0);
                CTComment comment = comments.getCommentAt(i);
                xhtml.startElement("p", "class", "slide-comment");
                CTCommentAuthor cta = commentAuthors.getAuthorById(comment.getAuthorId());
                if (cta != null) {
                    if (cta.getName() != null) {
                        authorStringBuilder.append(cta.getName());
                    }
                    if (cta.getInitials() != null) {
                        if (authorStringBuilder.length() > 0) {
                            authorStringBuilder.append(" ");
                        }
                        authorStringBuilder.append("(" + cta.getInitials() + ")");
                    }
                    if (comment.getText() != null && authorStringBuilder.length() > 0) {
                        authorStringBuilder.append(" - ");
                    }
                    if (authorStringBuilder.length() > 0) {
                        xhtml.startElement("b");
                        xhtml.characters(authorStringBuilder.toString());
                        xhtml.endElement("b");
                    }
                }
                xhtml.characters(comment.getText());
                xhtml.endElement("p");
            }
        }
    }
}
Also used : CTComment(org.openxmlformats.schemas.presentationml.x2006.main.CTComment) CTCommentAuthor(org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor)

Aggregations

CTComment (org.openxmlformats.schemas.presentationml.x2006.main.CTComment)2 CTCommentAuthor (org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor)2 XSLFCommentAuthors (org.apache.poi.xslf.usermodel.XSLFCommentAuthors)1 XSLFComments (org.apache.poi.xslf.usermodel.XSLFComments)1 XSLFNotes (org.apache.poi.xslf.usermodel.XSLFNotes)1 XSLFSlideLayout (org.apache.poi.xslf.usermodel.XSLFSlideLayout)1 XSLFSlideMaster (org.apache.poi.xslf.usermodel.XSLFSlideMaster)1