As you can read in
OpcPackage.load, it depends on whether you bring an XML or ZIP (docx) file. Thus you either have
- Code: Select all
protected OpcPackage loadDocxPackageFromClasspath(final InputStream stream) throws Docx4JException {
final LoadFromZipNG loader = new LoadFromZipNG();
final OpcPackage content = loader.get(stream);
return content;
}
or go for
- Code: Select all
protected OpcPackage loadXMLFromClasspath(final InputStream stream) throws Docx4JException, JAXBException {
final StreamSource source = new StreamSource(stream);
JAXBElement<Package> packageElement;
final Unmarshaller unmarshaller = Context.jcXmlPackage.createUnmarshaller();
unmarshaller.setEventHandler(new JaxbValidationEventHandler());
packageElement = unmarshaller.unmarshal(source, Package.class);
final Package wmlPackage = packageElement.getValue();
final FlatOpcXmlImporter importer = new FlatOpcXmlImporter(wmlPackage);
final OpcPackage content = importer.get();
return content;
}
where multiplexing can be done e.g. on the file name.