Example usage for org.apache.poi.xslf.usermodel XMLSlideShow getCommentAuthors

List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow getCommentAuthors

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XMLSlideShow getCommentAuthors.

Prototype

public XSLFCommentAuthors getCommentAuthors() 

Source Link

Document

Returns the list of comment authors, if there is one.

Usage

From source file:com.opensearchserver.extractor.parser.Pptx.java

License:Apache License

/**
 * Declined from XSLFPowerPointExtractor.java
 * /*w w  w . j  av a 2  s.com*/
 * @param pptSlideShow
 */
private void extractSides(XMLSlideShow slideshow) {

    XSLFSlide[] slides = (XSLFSlide[]) slideshow.getSlides();
    XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors();

    for (XSLFSlide slide : slides) {

        // One document per slide
        ParserDocument result = getNewParserDocument();

        XSLFNotes notes = slide.getNotes();
        XSLFComments comments = slide.getComments();
        XSLFSlideLayout layout = slide.getSlideLayout();
        XSLFSlideMaster master = layout.getSlideMaster();

        // TODO Do the slide's name
        // (Stored in docProps/app.xml)

        // Do the slide's text
        result.add(SLIDES, extractText(slide.getCommonSlideData(), false));
        result.add(LANG_DETECTION, languageDetection(SLIDES, 10000));

        // If requested, get text from the master and it's layout
        if (layout != null) {
            result.add(MASTER, extractText(layout.getCommonSlideData(), true));
        }
        if (master != null) {
            result.add(MASTER, extractText(master.getCommonSlideData(), true));
        }

        // If the slide has comments, do those too
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmList()) {
                StringBuilder sbComment = new StringBuilder();
                // Do the author if we can
                if (commentAuthors != null) {
                    CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
                    if (author != null) {
                        sbComment.append(author.getName());
                        sbComment.append(": ");
                    }
                }

                // Then the comment text, with a new line afterwards
                sbComment.append(comment.getText());
                sbComment.append("\n");
                if (sbComment.length() > 0)
                    result.add(COMMENTS, sbComment.toString());
            }
        }

        // Do the notes if requested
        if (notes != null) {
            result.add(NOTES, extractText(notes.getCommonSlideData(), false));
        }
    }
}

From source file:com.qwazr.extractor.parser.Pptx.java

License:Apache License

/**
 * Declined from XSLFPowerPointExtractor.java
 *
 * @param slideshow/*from   ww  w .  j a v  a  2s .  c om*/
 */
private void extractSides(XMLSlideShow slideshow) {

    List<XSLFSlide> slides = slideshow.getSlides();
    XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors();

    for (XSLFSlide slide : slides) {

        // One document per slide
        ParserDocument result = getNewParserDocument();

        XSLFNotes notes = slide.getNotes();
        XSLFComments comments = slide.getComments();
        XSLFSlideLayout layout = slide.getSlideLayout();
        XSLFSlideMaster master = layout.getSlideMaster();

        // TODO Do the slide's name
        // (Stored in docProps/app.xml)

        // Do the slide's text
        result.add(SLIDES, extractText(slide.getCommonSlideData(), false));
        result.add(LANG_DETECTION, languageDetection(SLIDES, 10000));

        // If requested, get text from the master and it's layout
        if (layout != null) {
            result.add(MASTER, extractText(layout.getCommonSlideData(), true));
        }
        if (master != null) {
            result.add(MASTER, extractText(master.getCommonSlideData(), true));
        }

        // If the slide has comments, do those too
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmList()) {
                StringBuilder sbComment = new StringBuilder();
                // Do the author if we can
                if (commentAuthors != null) {
                    CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
                    if (author != null) {
                        sbComment.append(author.getName());
                        sbComment.append(": ");
                    }
                }

                // Then the comment text, with a new line afterwards
                sbComment.append(comment.getText());
                sbComment.append("\n");
                if (sbComment.length() > 0)
                    result.add(COMMENTS, sbComment.toString());
            }
        }

        // Do the notes if requested
        if (notes != null) {
            result.add(NOTES, extractText(notes.getCommonSlideData(), false));
        }
    }
}

From source file:com.qwazr.library.poi.PptxParser.java

License:Apache License

/**
 * Declined from XSLFPowerPointExtractor.java
 *
 * @param slideshow// ww w.jav  a 2s.  co  m
 * @param resultBuilder
 */
private void extractSides(final XMLSlideShow slideshow, final ParserResultBuilder resultBuilder) {

    final List<XSLFSlide> slides = slideshow.getSlides();
    final XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors();

    for (XSLFSlide slide : slides) {

        // One document per slide
        final ParserFieldsBuilder result = resultBuilder.newDocument();

        final XSLFNotes notes = slide.getNotes();
        final XSLFComments comments = slide.getComments();
        final XSLFSlideLayout layout = slide.getSlideLayout();
        final XSLFSlideMaster master = layout.getSlideMaster();

        // TODO Do the slide's name
        // (Stored in docProps/app.xml)

        // Do the slide's text
        final String slideText = extractText(slide.getCommonSlideData(), false);
        result.add(SLIDES, slideText);
        result.add(CONTENT, slideText);

        // If requested, get text from the master and it's layout
        if (layout != null) {
            final String text = extractText(layout.getCommonSlideData(), true);
            result.add(MASTER, text);
            result.add(CONTENT, text);
        }
        if (master != null) {
            final String text = extractText(master.getCommonSlideData(), true);
            result.add(MASTER, text);
            result.add(CONTENT, text);
        }

        // If the slide has comments, do those too
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmList()) {
                final StringBuilder sbComment = new StringBuilder();
                // Do the author if we can
                if (commentAuthors != null) {
                    CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
                    if (author != null) {
                        sbComment.append(author.getName());
                        sbComment.append(": ");
                    }
                }

                // Then the comment text, with a new line afterwards
                sbComment.append(comment.getText());
                sbComment.append("\n");
                if (sbComment.length() > 0) {
                    final String text = sbComment.toString();
                    result.add(COMMENTS, text);
                    result.add(CONTENT, text);
                }
            }
        }

        // Do the notes if requested
        if (notes != null) {
            final String text = extractText(notes.getCommonSlideData(), false);
            result.add(NOTES, text);
            result.add(CONTENT, text);
        }

        result.add(LANG_DETECTION, languageDetection(result, CONTENT, 10000));

    }
}

From source file:org.apache.tika.parser.microsoft.ooxml.XSLFPowerPointExtractorDecorator.java

License:Apache License

/**
 * @see org.apache.poi.xslf.extractor.XSLFPowerPointExtractor#getText()
 *//*w  ww  .j a v a 2 s  .  c  om*/
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();
            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");
            }
        }
    }
}