use of org.mycore.datamodel.metadata.validator.MCREditorOutValidator in project mycore by MyCoRe-Org.
the class MCRPersistenceHelper method getMCRObject.
/**
* creates a MCRObject instance on base of JDOM document
* @param doc
* MyCoRe object as XML.
* @return
* @throws JDOMException
* exception from underlying {@link MCREditorOutValidator}
* @throws IOException
* exception from underlying {@link MCREditorOutValidator} or {@link XMLOutputter}
* @throws SAXParseException
* @throws MCRException
*/
static MCRObject getMCRObject(Document doc) throws JDOMException, IOException, MCRException, SAXParseException {
String id = doc.getRootElement().getAttributeValue("ID");
MCRObjectID objectID = MCRObjectID.getInstance(id);
MCREditorOutValidator ev = new MCREditorOutValidator(doc, objectID);
Document jdom_out = ev.generateValidMyCoReObject();
if (ev.getErrorLog().size() > 0 && LOGGER.isDebugEnabled()) {
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
StringWriter swOrig = new StringWriter();
xout.output(doc, swOrig);
LOGGER.debug("Input document \n{}", swOrig);
for (String logMsg : ev.getErrorLog()) {
LOGGER.debug(logMsg);
}
StringWriter swClean = new StringWriter();
xout.output(jdom_out, swClean);
LOGGER.debug("Results in \n{}", swClean);
}
return new MCRObject(jdom_out);
}
Aggregations