Example usage for org.apache.poi.xslf.usermodel XSLFComments getCTCommentsList

List of usage examples for org.apache.poi.xslf.usermodel XSLFComments getCTCommentsList

Introduction

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

Prototype

public CTCommentList getCTCommentsList() 

Source Link

Usage

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

License:Apache License

/**
 * Declined from XSLFPowerPointExtractor.java
 * //from  w  w  w  .  j a  v a  2s .  c om
 * @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/* ww  w . j av a 2  s. c  o 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  w w  .j ava 2s.  c om*/
 * @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   ww w . j  a  v  a2  s.co m
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();
            }
        }
    }
}