Search in sources :

Example 21 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRDerivateContentTransformerServlet method getContent.

@Override
public MCRContent getContent(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String pathInfo = req.getPathInfo();
    if (pathInfo.startsWith("/")) {
        pathInfo = pathInfo.substring(1);
    }
    String[] pathTokens = pathInfo.split("/");
    String derivate = pathTokens[0];
    String path = pathInfo.substring(derivate.length());
    LOGGER.debug("Derivate : {}", derivate);
    LOGGER.debug("Path : {}", path);
    MCRPath mcrPath = MCRPath.getPath(derivate, path);
    MCRContent pc = new MCRPathContent(mcrPath);
    FileTime lastModifiedTime = Files.getLastModifiedTime(mcrPath);
    MCRFrontendUtil.writeCacheHeaders(resp, (long) CACHE_TIME, lastModifiedTime.toMillis(), true);
    try {
        return getLayoutService().getTransformedContent(req, resp, pc);
    } catch (TransformerException | SAXException e) {
        throw new IOException("could not transform content", e);
    }
}
Also used : MCRPathContent(org.mycore.common.content.MCRPathContent) FileTime(java.nio.file.attribute.FileTime) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRContent(org.mycore.common.content.MCRContent) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 22 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRDOIRegistrationService method transformToDatacite.

protected Document transformToDatacite(MCRDigitalObjectIdentifier doi, MCRBase mcrBase) throws MCRPersistentIdentifierException {
    MCRObjectID id = mcrBase.getId();
    MCRBaseContent content = new MCRBaseContent(mcrBase);
    try {
        MCRContent transform = MCRContentTransformerFactory.getTransformer(this.transformer).transform(content);
        Document dataciteDocument = transform.asXML();
        insertDOI(dataciteDocument, doi);
        Schema dataciteSchema = loadDataciteSchema();
        try {
            dataciteSchema.newValidator().validate(new JDOMSource(dataciteDocument));
        } catch (SAXException e) {
            String translatedInformation = MCRTranslation.translate(TRANSLATE_PREFIX + ERR_CODE_1_2);
            throw new MCRPersistentIdentifierException("The document " + id + " does not generate well formed Datacite!", translatedInformation, ERR_CODE_1_2, e);
        }
        return dataciteDocument;
    } catch (IOException | JDOMException | SAXException e) {
        throw new MCRPersistentIdentifierException("Could not transform the content of " + id + " with the transformer " + transformer, e);
    }
}
Also used : Schema(javax.xml.validation.Schema) MCRBaseContent(org.mycore.common.content.MCRBaseContent) JDOMSource(org.jdom2.transform.JDOMSource) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) SAXException(org.xml.sax.SAXException)

Example 23 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRWorksPublisher method buildWorkXMLFrom.

/**
 * Retrieves the MyCoRe object, transforms it to ORCID work xml and validates
 */
private Document buildWorkXMLFrom(MCRObjectID objectID) throws IOException, SAXParseException {
    MCRContent mcrObject = MCRXMLMetadataManager.instance().retrieveContent(objectID);
    MCRContent workXML = T_MCR2WORK.transform(mcrObject);
    return MCRXMLParserFactory.getValidatingParser().parseXML(workXML);
}
Also used : MCRContent(org.mycore.common.content.MCRContent)

Example 24 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRNormalizeUnicodeTransformer method process.

public Document process(Document xml) throws IOException, JDOMException, SAXException {
    if (stylesheet == null)
        return xml.clone();
    MCRContent source = new MCRJDOMContent(xml);
    MCRContent transformed = MCRXSL2XMLTransformer.getInstance("xsl/" + stylesheet).transform(source);
    MCRContent normalized = new MCRNormalizeUnicodeTransformer().transform(transformed);
    return normalized.asXML();
}
Also used : MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRContent(org.mycore.common.content.MCRContent)

Example 25 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRXEditorTransformer method transform.

public MCRContent transform(MCRContent editorSource) throws IOException, JDOMException, SAXException {
    editorSession.getValidator().clearRules();
    editorSession.getSubmission().clear();
    MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer("xeditor");
    if (transformer instanceof MCRParameterizedTransformer) {
        String key = MCRXEditorTransformerStore.storeTransformer(this);
        transformationParameters.setParameter("XEditorTransformerKey", key);
        MCRContent result = ((MCRParameterizedTransformer) transformer).transform(editorSource, transformationParameters);
        if (result instanceof MCRWrappedContent && result.getClass().getName().contains(MCRXSLTransformer.class.getName())) {
            // lazy transformation make JUnit tests fail
            result = ((MCRWrappedContent) result).getBaseContent();
        }
        editorSession.getValidator().clearValidationResults();
        return result;
    } else {
        throw new MCRException("Xeditor needs parameterized MCRContentTransformer: " + transformer);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRWrappedContent(org.mycore.common.content.MCRWrappedContent) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3