Search in sources :

Example 6 with MCRContentTransformer

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

the class MCRCompressServlet method getMetaDataContent.

private byte[] getMetaDataContent(MCRContent content, HttpServletRequest req) throws Exception {
    // zip the object's Metadata
    MCRParameterCollector parameters = new MCRParameterCollector(req);
    if (parameters.getParameter("Style", null) == null) {
        parameters.setParameter("Style", "compress");
    }
    MCRContentTransformer contentTransformer = MCRLayoutService.getContentTransformer(content.getDocType(), parameters);
    ByteArrayOutputStream out = new ByteArrayOutputStream(32 * 1024);
    if (contentTransformer instanceof MCRParameterizedTransformer) {
        ((MCRParameterizedTransformer) contentTransformer).transform(content, out, parameters);
    } else {
        contentTransformer.transform(content, out);
    }
    return out.toByteArray();
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with MCRContentTransformer

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

the class MCRMetsIIIFPresentationImpl method getTransformer.

protected MCRContentTransformer getTransformer() {
    String transformerID = getProperties().get(TRANSFORMER_ID_CONFIGURATION_KEY);
    MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer(transformerID);
    if (transformer == null) {
        throw new MCRConfigurationException("Could not resolve transformer with id : " + transformerID);
    }
    return transformer;
}
Also used : MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 8 with MCRContentTransformer

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

the class MCRViewerResource method getContent.

protected MCRContent getContent(final HttpServletRequest req) throws Exception {
    // get derivate id from request object
    String derivate = MCRViewerConfiguration.getDerivate(req);
    if (derivate == null) {
        MCRJerseyUtil.throwException(Status.BAD_REQUEST, "Could not locate derivate identifer in path.");
    }
    // get mycore object id
    final MCRObjectID derivateID = MCRObjectID.getInstance(derivate);
    if (!MCRMetadataManager.exists(derivateID)) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.object.not.found", derivateID);
        MCRJerseyUtil.throwException(Status.NOT_FOUND, errorMessage);
    }
    // check permission
    if (IVIEW_ACL_PROVDER != null && !IVIEW_ACL_PROVDER.checkAccess(req.getSession(), derivateID)) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.noRights", derivateID);
        MCRJerseyUtil.throwException(Status.UNAUTHORIZED, errorMessage);
    }
    // build configuration object
    MCRViewerConfigurationStrategy configurationStrategy = MCRConfiguration.instance().getInstanceOf("MCR.Viewer.configuration.strategy", new MCRViewerDefaultConfigurationStrategy());
    MCRJDOMContent source = new MCRJDOMContent(buildResponseDocument(configurationStrategy.get(req)));
    MCRParameterCollector parameter = new MCRParameterCollector(req);
    MCRContentTransformer transformer = getContentTransformer(source.getDocType(), parameter);
    return transformer.transform(source);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRViewerConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerConfigurationStrategy) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRViewerDefaultConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerDefaultConfigurationStrategy) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 9 with MCRContentTransformer

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

the class MCRSolrTransformerInputDocumentFactory method getTransformer.

private static MCRContentTransformer getTransformer() {
    String property = CONFIG_PREFIX + "SolrInputDocument.Transformer";
    String transformerId = MCRConfiguration.instance().getString(property);
    MCRContentTransformer contentTransformer = MCRContentTransformerFactory.getTransformer(transformerId);
    isJAXBTransformer = contentTransformer instanceof MCRXSL2JAXBTransformer;
    return contentTransformer;
}
Also used : MCRXSL2JAXBTransformer(org.mycore.common.content.transformer.MCRXSL2JAXBTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer)

Example 10 with MCRContentTransformer

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

the class MCRMetsIIIFPresentationImpl method getMets.

public Document getMets(String id) throws IOException, JDOMException, SAXException {
    String objectid = MCRLinkTableManager.instance().getSourceOf(id).iterator().next();
    MCRContentTransformer transformer = getTransformer();
    MCRParameterCollector parameter = new MCRParameterCollector();
    if (objectid != null && objectid.length() != 0) {
        MCRDerivate derObj = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(id));
        MCRObjectID ownerID = derObj.getOwnerID();
        objectid = ownerID.toString();
        parameter.setParameter("objectID", objectid);
        parameter.setParameter("derivateID", id);
    }
    MCRPath metsPath = MCRPath.getPath(id, "mets.xml");
    if (!Files.exists(metsPath)) {
        throw new MCRException("File not found: " + id);
    }
    MCRPathContent source = new MCRPathContent(metsPath);
    MCRContent content = transformer instanceof MCRParameterizedTransformer ? ((MCRParameterizedTransformer) transformer).transform(source, parameter) : transformer.transform(source);
    return content.asXML();
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRException(org.mycore.common.MCRException) MCRPathContent(org.mycore.common.content.MCRPathContent) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)12 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 MCRException (org.mycore.common.MCRException)5 MCRParameterizedTransformer (org.mycore.common.content.transformer.MCRParameterizedTransformer)4 IOException (java.io.IOException)3 MCRContent (org.mycore.common.content.MCRContent)3 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)3 SAXException (org.xml.sax.SAXException)3 TransformerException (javax.xml.transform.TransformerException)2 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 Comment (org.jdom2.Comment)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1 XMLOutputter (org.jdom2.output.XMLOutputter)1 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)1 MCRPathContent (org.mycore.common.content.MCRPathContent)1