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();
}
}
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();
}
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());
}
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;
}
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;
}
Aggregations