Example usage for org.apache.poi.hslf.usermodel HSLFTextParagraph isBullet

List of usage examples for org.apache.poi.hslf.usermodel HSLFTextParagraph isBullet

Introduction

In this page you can find the example usage for org.apache.poi.hslf.usermodel HSLFTextParagraph isBullet.

Prototype

public boolean isBullet() 

Source Link

Document

Returns whether this rich text run has bullets

Usage

From source file:org.apache.tika.parser.microsoft.HSLFExtractor.java

License:Apache License

private void textRunsToText(XHTMLContentHandler xhtml, List<List<HSLFTextParagraph>> paragraphsList)
        throws SAXException {
    if (paragraphsList == null) {
        return;//w  ww  .  ja v  a 2s .  c om
    }

    for (List<HSLFTextParagraph> run : paragraphsList) {
        // Leaving in wisdom from TIKA-712 for easy revert.
        // Avoid boiler-plate text on the master slide (0
        // = TextHeaderAtom.TITLE_TYPE, 1 = TextHeaderAtom.BODY_TYPE):
        //if (!isMaster || (run.getRunType() != 0 && run.getRunType() != 1)) {

        boolean isBullet = false;
        for (HSLFTextParagraph htp : run) {
            boolean nextBullet = htp.isBullet();
            // TODO: identify bullet/list type
            if (isBullet != nextBullet) {
                isBullet = nextBullet;
                if (isBullet) {
                    xhtml.startElement("ul");
                } else {
                    xhtml.endElement("ul");
                }
            }

            List<HSLFTextRun> textRuns = htp.getTextRuns();
            String firstLine = removePBreak(textRuns.get(0).getRawText());
            boolean showBullet = (isBullet && (textRuns.size() > 1 || !"".equals(firstLine)));
            String paraTag = showBullet ? "li" : "p";

            xhtml.startElement(paraTag);
            for (HSLFTextRun htr : textRuns) {
                String line = htr.getRawText();
                if (line != null) {
                    boolean isfirst = true;
                    for (String fragment : line.split("\\u000b")) {
                        if (!isfirst) {
                            xhtml.startElement("br");
                            xhtml.endElement("br");
                        }
                        isfirst = false;
                        xhtml.characters(removePBreak(fragment));
                    }
                    if (line.endsWith("\u000b")) {
                        xhtml.startElement("br");
                        xhtml.endElement("br");
                    }
                }
            }
            xhtml.endElement(paraTag);
        }
        if (isBullet) {
            xhtml.endElement("ul");
        }
    }
}