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();
}
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;
}
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);
}
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;
}
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();
}
Aggregations