
com.deepoove.poi.NumberingWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of poi-tl Show documentation
Show all versions of poi-tl Show documentation
Generate word(docx) with template
package com.deepoove.poi;
import java.lang.reflect.Field;
import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFAbstractNum;
import org.apache.poi.xwpf.usermodel.XWPFNum;
import org.apache.poi.xwpf.usermodel.XWPFNumbering;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is a utility class so that I can get access to the protected fields
* within XWPFNumbering.
*/
public class NumberingWrapper {
private static Logger logger = LoggerFactory.getLogger(NumberingWrapper.class);
private final XWPFNumbering numbering;
private List nums;
private List abstractNums;
public NumberingWrapper(XWPFNumbering numbering) {
this.numbering = numbering;
this.nums = tryGetNums();
this.abstractNums = tryGetAbstractNums();
}
@SuppressWarnings("unchecked")
private List tryGetNums() {
try {
Field field = XWPFNumbering.class.getDeclaredField("nums");
field.setAccessible(true);
return (List) field.get(this.numbering);
} catch (Exception e) {
logger.error("Cannot get XWPFNumbering nums", e);
}
return null;
}
@SuppressWarnings("unchecked")
private List tryGetAbstractNums() {
try {
Field field = XWPFNumbering.class.getDeclaredField("abstractNums");
field.setAccessible(true);
return (List) field.get(this.numbering);
} catch (Exception e) {
logger.error("Cannot get XWPFNumbering abstractNums", e);
}
return null;
}
public List getAbstractNums() {
return abstractNums;
}
public List getNums() {
return nums;
}
public XWPFNumbering getNumbering() {
return numbering;
}
public int getAbstractNumsSize() {
return abstractNums == null ? 0 : abstractNums.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy