try {
Unmarshaller u = Context.jc.createUnmarshaller();
Object o = u.unmarshal( is );
log.info(o.getClass().getName());
PartName name = part.getPartName();
if (o instanceof CoverPageProperties) {
part = new DocPropsCoverPagePart(name);
((DocPropsCoverPagePart)part).setJaxbElement(
(CoverPageProperties)o);
} else if (o instanceof org.opendope.conditions.Conditions) {
part = new ConditionsPart(name);
((ConditionsPart)part).setJaxbElement(
(org.opendope.conditions.Conditions)o);
} else if (o instanceof org.opendope.xpaths.Xpaths) {
part = new XPathsPart(name);
((XPathsPart)part).setJaxbElement(
(org.opendope.xpaths.Xpaths)o);
} else if (o instanceof org.opendope.questions.Questionnaire) {
part = new QuestionsPart(name);
((QuestionsPart)part).setJaxbElement(
(org.opendope.questions.Questionnaire)o);
} else if (o instanceof org.opendope.answers.Answers) {
part = new StandardisedAnswersPart(name);
((StandardisedAnswersPart)part).setJaxbElement(
(org.opendope.answers.Answers)o);
} else if (o instanceof org.opendope.components.Components) {
part = new ComponentsPart(name);
((ComponentsPart)part).setJaxbElement(
(org.opendope.components.Components)o);
} else if (o instanceof JAXBElement<?>
&& XmlUtils.unwrap(o) instanceof org.docx4j.bibliography.CTSources) {
part = new BibliographyPart(name);
((BibliographyPart) part)
.setJaxbElement((JAXBElement<org.docx4j.bibliography.CTSources>)o);
} else {
log.warn("No known part after all for CustomXmlPart " + o.getClass().getName());
CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();
is.reset();
data.setDocument(is); // Not necessarily JAXB, that's just our method name
((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);
}
} catch (javax.xml.bind.UnmarshalException ue) {
// No ...
CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();
is.reset();
data.setDocument(is); // Not necessarily JAXB, that's just our method name
((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);
}
} else {
// Shouldn't happen, since ContentTypeManagerImpl should
// return an instance of one of the above, or throw an
// Exception.
log.error("No suitable part found for: " + resolvedPartUri);
return null;
}
} catch (PartUnrecognisedException e) {
// Try to get it as a binary part
part = new BinaryPart(new PartName("/" + resolvedPartUri));
((BinaryPart) part).setBinaryData(is);
}
} catch (Exception ex) {
// PathNotFoundException, ValueFormatException, RepositoryException, URISyntaxException