Example usage for org.apache.poi.xslf.usermodel XSLFSlide getComments

List of usage examples for org.apache.poi.xslf.usermodel XSLFSlide getComments

Introduction

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

Prototype

@Override
    public List<XSLFComment> getComments() 

Source Link

Usage

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

License:Apache License

/**
 * Declined from XSLFPowerPointExtractor.java
 * //from  w w  w  .  ja  va2s. 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   w  w w  .j a v  a 2 s.  co  m
 */
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//from   w  ww  .  j  a  va 2s.  c o  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:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XSLFPowerPointExtractorDecorator.java

License:Apache License

/**
 * @see org.apache.poi.xslf.extractor.XSLFPowerPointExtractor#getText()
 *///from   w  ww.  java  2 s.c om
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, IOException {
    XMLSlideShow slideShow = (XMLSlideShow) extractor.getDocument();

    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
        extractContent(slide.getShapes(), false, xhtml, slideDesc);

        // slide layout which is the master sheet for this slide
        XSLFSheet slideLayout = slide.getMasterSheet();
        extractContent(slideLayout.getShapes(), true, xhtml, null);

        // slide master which is the master sheet for all text layouts
        XSLFSheet slideMaster = slideLayout.getMasterSheet();
        extractContent(slideMaster.getShapes(), true, xhtml, null);

        // notes (if present)
        XSLFSheet slideNotes = slide.getNotes();
        if (slideNotes != null) {
            extractContent(slideNotes.getShapes(), false, xhtml, slideDesc);
            // master sheet for this notes
            XSLFSheet notesMaster = slideNotes.getMasterSheet();
            extractContent(notesMaster.getShapes(), true, xhtml, null);
        }

        // comments (if present)
        XSLFComments comments = slide.getComments();
        if (comments != null) {
            for (CTComment comment : comments.getCTCommentsList().getCmList()) {
                xhtml.element("p", comment.getText());
            }
        }
    }

    if (Config.inst().getProp(ConfigBool.ENABLE_IMAGE_OCR)) {
        TikaImageHelper helper = new TikaImageHelper(metadata);
        try {
            List<XSLFPictureData> pictures = slideShow.getAllPictures();
            for (XSLFPictureData picture : pictures) {
                ByteArrayInputStream imageData = new ByteArrayInputStream(picture.getData());
                BufferedImage image = ImageIO.read(imageData);
                helper.addImage(image);
                helper.addTextToHandler(xhtml);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (extractor != null) {
                extractor.close();
            }
            if (helper != null) {
                helper.close();
            }
        }
    }
}

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

License:Apache License

/**
 * @see org.apache.poi.xslf.extractor.XSLFPowerPointExtractor#getText()
 *///from  w w  w .ja va  2  s .  c  o m
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");
            }
        }
    }
}