com.deepoove.poi.xwpf.IdenifierManagerWrapper 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.xwpf;
import org.apache.poi.ooxml.util.IdentifierManager;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.deepoove.poi.util.ReflectionUtils;
public class IdenifierManagerWrapper {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
public static final String XPATH_DRAWING = "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' \n"
+ " declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' .//mc:AlternateContent/mc:Choice/w:drawing";
private IdentifierManager drawingIdManager;
public IdenifierManagerWrapper(XWPFDocument document) {
try {
drawingIdManager = (IdentifierManager) ReflectionUtils.getValue("drawingIdManager", document);
// 0 will corrupt the document
reserve(0);
} catch (Exception e) {
logger.info("Cannot get the global drawingIdManager, use custom identifier.");
}
}
public boolean isValid() {
return null != drawingIdManager;
}
public long reserveNew() {
return drawingIdManager.reserveNew();
}
public long reserve(long id) {
return drawingIdManager.reserve(id);
}
}