use of org.mycore.common.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRLayoutService method doLayout.
public void doLayout(HttpServletRequest req, HttpServletResponse res, MCRContent source) throws IOException, TransformerException, SAXException {
if (res.isCommitted()) {
LOGGER.warn("Response already committed: {}:{}", res.getStatus(), res.getContentType());
return;
}
String docType = source.getDocType();
try {
MCRParameterCollector parameter = new MCRParameterCollector(req);
MCRContentTransformer transformer = getContentTransformer(docType, parameter);
String filename = getFileName(req, parameter);
transform(res, transformer, source, parameter, filename);
} catch (IOException | TransformerException | SAXException ex) {
throw ex;
} catch (MCRException ex) {
// generating an error page when there is an error in the stylesheet
if (!"mcr_error".equals(docType)) {
throw ex;
}
String msg = "Error while generating error page!";
LOGGER.warn(msg, ex);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
} catch (Exception e) {
throw new MCRException(e);
}
}
use of org.mycore.common.xsl.MCRParameterCollector 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.xsl.MCRParameterCollector 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.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRSolrTransformerInputDocumentFactory method getDocuments.
@Override
public Iterator<SolrInputDocument> getDocuments(Map<MCRObjectID, MCRContent> contentMap) throws IOException, SAXException {
if (contentMap.isEmpty()) {
return Collections.emptyIterator();
}
try {
Document doc = getMergedDocument(contentMap);
if (isJAXBTransformer) {
MCRParameterCollector param = new MCRParameterCollector();
@SuppressWarnings("unchecked") MCRXSL2JAXBTransformer<MCRSolrInputDocumentList> jaxbTransformer = (MCRXSL2JAXBTransformer<MCRSolrInputDocumentList>) transformer;
MCRSolrInputDocumentList input = jaxbTransformer.getJAXBObject(new MCRJDOMContent(doc), param);
return MCRSolrInputDocumentGenerator.getSolrInputDocuments(input.getDoc()).iterator();
} else {
MCRContent result = transformer.transform(new MCRJDOMContent(doc));
return getSolrInputDocuments(result);
}
} catch (TransformerConfigurationException | JAXBException | JDOMException | ParserConfigurationException e) {
throw new IOException(e);
}
}
use of org.mycore.common.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRSolrTransformerInputDocumentFactory method getDocument.
/* (non-Javadoc)
* @see org.mycore.solr.index.document.MCRSolrInputDocumentFactory#getDocument(org.mycore.datamodel.metadata.MCRObjectID, org.mycore.common.content.MCRContent)
*/
@Override
public SolrInputDocument getDocument(MCRObjectID id, MCRContent content) throws SAXException, IOException {
// we need no parameter for searchfields - hopefully
try {
SolrInputDocument document;
if (isJAXBTransformer) {
MCRParameterCollector param = new MCRParameterCollector();
@SuppressWarnings("unchecked") MCRXSL2JAXBTransformer<MCRSolrInputDocumentList> jaxbTransformer = (MCRXSL2JAXBTransformer<MCRSolrInputDocumentList>) transformer;
MCRSolrInputDocumentList input = jaxbTransformer.getJAXBObject(content, param);
document = MCRSolrInputDocumentGenerator.getSolrInputDocument(input.getDoc().iterator().next());
} else {
MCRContent result = transformer.transform(content);
document = MCRSolrInputDocumentGenerator.getSolrInputDocument(result.asXML().getRootElement());
}
return document;
} catch (TransformerConfigurationException | JAXBException | JDOMException | ParserConfigurationException e) {
throw new IOException(e);
}
}
Aggregations