public OpcPackage get() throws Docx4JException {
long startTime = System.currentTimeMillis();
// 1. Get [Content_Types].xml
ContentTypeManager ctm = new ContentTypeManager();
InputStream is = null;
try {
is = partStore.loadPart("[Content_Types].xml");
ctm.parseContentTypesFile(is);
} catch (Docx4JException e) {
throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
} catch (NullPointerException e) {
throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
} finally {
IOUtils.closeQuietly(is);
}
// .. now find the name of the main part
RelationshipsPart rp = RelationshipsPart.createPackageRels();
populatePackageRels(rp);
String mainPartName = PackageRelsUtil.getNameOfMainPart(rp);
PartName mainPartNameObj;
if (mainPartName.startsWith("/")) {
// OpenXML SDK 2.0 writes Target="/word/document.xml" (note leading "/")
mainPartNameObj = new PartName(mainPartName);
} else {
// Microsoft Word, docx4j etc write Target="word/document.xml"
mainPartNameObj = new PartName("/" + mainPartName);
}
String pkgContentType = ctm.getContentType(mainPartNameObj);
// 2. Create a new Package; this'll return the appropriate subclass
OpcPackage p = ctm.createPackage(pkgContentType);
log.info("Instantiated package of type " + p.getClass().getName() );
p.setSourcePartStore(partStore);
p.setRelationships(rp);
rp.setSourceP(p); //