Example usage for org.apache.poi.xwpf.usermodel XWPFSDT XWPFSDT

List of usage examples for org.apache.poi.xwpf.usermodel XWPFSDT XWPFSDT

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFSDT XWPFSDT.

Prototype

public XWPFSDT(CTSdtBlock block, IBody part) 

Source Link

Usage

From source file:apachepoitest.XWPFParagraphClone.java

License:Apache License

/**
  * Identifies (in order) the parts of the paragraph /
  *  sub-paragraph that correspond to character text
  *  runs, and builds the appropriate runs for these.
  *///from w w  w .  ja v  a  2  s  . co m
private void buildRunsInOrderFromXml(XmlObject object) {
    XmlCursor c = object.newCursor();
    c.selectPath("child::*");
    while (c.toNextSelection()) {
        XmlObject o = c.getObject();
        if (o instanceof CTR) {
            XWPFRun r = new XWPFRun((CTR) o, this);
            runs.add(r);
            iruns.add(r);
        }
        if (o instanceof CTHyperlink) {
            CTHyperlink link = (CTHyperlink) o;
            for (CTR r : link.getRArray()) {
                XWPFHyperlinkRun hr = new XWPFHyperlinkRun(link, r, this);
                runs.add(hr);
                iruns.add(hr);
            }
        }
        if (o instanceof CTSdtBlock) {
            XWPFSDT cc = new XWPFSDT((CTSdtBlock) o, part);
            iruns.add(cc);
        }
        if (o instanceof CTSdtRun) {
            XWPFSDT cc = new XWPFSDT((CTSdtRun) o, part);
            iruns.add(cc);
        }
        if (o instanceof CTRunTrackChange) {
            for (CTR r : ((CTRunTrackChange) o).getRArray()) {
                XWPFRun cr = new XWPFRun(r, this);
                runs.add(cr);
                iruns.add(cr);
            }
        }
        if (o instanceof CTSimpleField) {
            for (CTR r : ((CTSimpleField) o).getRArray()) {
                XWPFRun cr = new XWPFRun(r, this);
                runs.add(cr);
                iruns.add(cr);
            }
        }
        if (o instanceof CTSmartTagRun) {
            // Smart Tags can be nested many times. 
            // This implementation does not preserve the tagging information
            buildRunsInOrderFromXml(o);
        }
    }
    c.dispose();
}