Search in sources :

Example 1 with MCREditorOutValidator

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);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRObject(org.mycore.datamodel.metadata.MCRObject) StringWriter(java.io.StringWriter) MCREditorOutValidator(org.mycore.datamodel.metadata.validator.MCREditorOutValidator) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Aggregations

StringWriter (java.io.StringWriter)1 Document (org.jdom2.Document)1 XMLOutputter (org.jdom2.output.XMLOutputter)1 MCRObject (org.mycore.datamodel.metadata.MCRObject)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCREditorOutValidator (org.mycore.datamodel.metadata.validator.MCREditorOutValidator)1