Search in sources :

Example 1 with CTNum

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum in project poi by apache.

the class XWPFNumbering method onDocumentRead.

/**
     * read numbering form an existing package
     */
@Override
protected void onDocumentRead() throws IOException {
    NumberingDocument numberingDoc = null;
    InputStream is;
    is = getPackagePart().getInputStream();
    try {
        numberingDoc = NumberingDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        ctNumbering = numberingDoc.getNumbering();
        //get any Nums
        for (CTNum ctNum : ctNumbering.getNumArray()) {
            nums.add(new XWPFNum(ctNum, this));
        }
        for (CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumArray()) {
            abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
        }
        isNew = false;
    } catch (XmlException e) {
        throw new POIXMLException();
    } finally {
        is.close();
    }
}
Also used : CTNum(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) POIXMLException(org.apache.poi.POIXMLException) NumberingDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument) CTAbstractNum(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum)

Example 2 with CTNum

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum in project poi by apache.

the class XWPFNumbering method addNum.

/**
     * Add a new num with an abstractNumID
     *
     * @return return NumId of the added num
     */
public BigInteger addNum(BigInteger abstractNumID) {
    CTNum ctNum = this.ctNumbering.addNewNum();
    ctNum.addNewAbstractNumId();
    ctNum.getAbstractNumId().setVal(abstractNumID);
    ctNum.setNumId(BigInteger.valueOf(nums.size() + 1));
    XWPFNum num = new XWPFNum(ctNum, this);
    nums.add(num);
    return ctNum.getNumId();
}
Also used : CTNum(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum)

Example 3 with CTNum

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum in project poi by apache.

the class TestXWPFNumbering method testOverrideList.

public void testOverrideList() throws IOException {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("NumberingWOverrides.docx");
    XWPFParagraph p = doc.getParagraphs().get(4);
    XWPFNumbering numbering = doc.getNumbering();
    CTNum ctNum = numbering.getNum(p.getNumID()).getCTNum();
    assertEquals(9, ctNum.sizeOfLvlOverrideArray());
    CTNumLvl ctNumLvl = ctNum.getLvlOverrideArray(0);
    assertEquals("upperLetter", ctNumLvl.getLvl().getNumFmt().getVal().toString());
}
Also used : CTNum(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum) CTNumLvl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl)

Example 4 with CTNum

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum in project tika by apache.

the class XWPFListManager method loadOverrideTuples.

private LevelTuple[] loadOverrideTuples(CTNum ctNum, int length) {
    LevelTuple[] levelTuples = new LevelTuple[length];
    int overrideLength = ctNum.sizeOfLvlOverrideArray();
    if (overrideLength == 0) {
        return null;
    }
    for (int i = 0; i < length; i++) {
        LevelTuple tuple;
        if (i >= overrideLength) {
            tuple = new LevelTuple("%" + i + ".");
        } else {
            CTNumLvl ctNumLvl = ctNum.getLvlOverrideArray(i);
            if (ctNumLvl != null) {
                tuple = buildTuple(i, ctNumLvl.getLvl());
            } else {
                tuple = new LevelTuple("%" + i + ".");
            }
        }
        levelTuples[i] = tuple;
    }
    return levelTuples;
}
Also used : CTNumLvl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl)

Example 5 with CTNum

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum in project tika by apache.

the class XWPFListManager method getFormattedNumber.

public String getFormattedNumber(BigInteger numId, int iLvl) {
    if (numbering == null || iLvl < 0 || numId == null) {
        return "";
    }
    int currNumId = numId.intValue();
    XWPFNum xwpfNum = numbering.getNum(numId);
    if (xwpfNum == null) {
        return "";
    }
    CTNum ctNum = xwpfNum.getCTNum();
    CTDecimalNumber abNum = ctNum.getAbstractNumId();
    int currAbNumId = abNum.getVal().intValue();
    ParagraphLevelCounter lc = listLevelMap.get(currAbNumId);
    LevelTuple[] overrideTuples = overrideTupleMap.get(currNumId);
    if (lc == null) {
        lc = loadLevelTuples(abNum);
    }
    if (overrideTuples == null) {
        overrideTuples = loadOverrideTuples(ctNum, lc.getNumberOfLevels());
    }
    String formattedString = lc.incrementLevel(iLvl, overrideTuples);
    listLevelMap.put(currAbNumId, lc);
    overrideTupleMap.put(currNumId, overrideTuples);
    return formattedString;
}
Also used : CTNum(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum) CTDecimalNumber(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber) XWPFNum(org.apache.poi.xwpf.usermodel.XWPFNum)

Aggregations

CTNum (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum)4 CTNumLvl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl)2 InputStream (java.io.InputStream)1 POIXMLException (org.apache.poi.POIXMLException)1 XWPFNum (org.apache.poi.xwpf.usermodel.XWPFNum)1 XmlException (org.apache.xmlbeans.XmlException)1 CTAbstractNum (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum)1 CTDecimalNumber (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber)1 NumberingDocument (org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument)1