use of org.mycore.common.content.transformer.MCRContentTransformer in project mycore by MyCoRe-Org.
the class MCRJerseyUtil method transform.
/**
* Transforms a jdom document to a <code>MCRContent</code> via the <code>MCRLayoutService</code>.
*
* @param document
* the document to transform
* @param request
* the http request
*/
public static MCRContent transform(Document document, HttpServletRequest request) throws Exception {
MCRParameterCollector parameter = new MCRParameterCollector(request);
MCRContent result;
MCRJDOMContent source = new MCRJDOMContent(document);
MCRContentTransformer transformer = MCRLayoutService.getContentTransformer(source.getDocType(), parameter);
if (transformer instanceof MCRParameterizedTransformer) {
result = ((MCRParameterizedTransformer) transformer).transform(source, parameter);
} else {
result = transformer.transform(source);
}
return result;
}
use of org.mycore.common.content.transformer.MCRContentTransformer 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);
}
}
use of org.mycore.common.content.transformer.MCRContentTransformer in project mycore by MyCoRe-Org.
the class MCRLayoutService method getTransformedContent.
public MCRContent getTransformedContent(HttpServletRequest req, HttpServletResponse res, MCRContent source) throws IOException, TransformerException, SAXException {
String docType = source.getDocType();
try {
MCRParameterCollector parameter = new MCRParameterCollector(req);
MCRContentTransformer transformer = getContentTransformer(docType, parameter);
String filename = getFileName(req, parameter);
return transform(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);
return null;
} catch (Exception e) {
throw new MCRException(e);
}
}
use of org.mycore.common.content.transformer.MCRContentTransformer 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.content.transformer.MCRContentTransformer in project mycore by MyCoRe-Org.
the class MCRLayoutTransformerFactory method buildLayoutTransformer.
private static MCRContentTransformer buildLayoutTransformer(String id) throws Exception {
String idStripped = id.replaceAll("-default$", "");
LOGGER.info("Configure property MCR.ContentTransformer.{}.Class if you do not want to use default behaviour.", idStripped);
String stylesheet = getResourceName(id);
if (stylesheet == null) {
LOGGER.info("Using noop transformer for {}", idStripped);
return NOOP_TRANSFORMER;
}
String[] stylesheets = getStylesheets(idStripped, stylesheet);
MCRContentTransformer transformer = MCRXSLTransformer.getInstance(stylesheets);
String mimeType = transformer.getMimeType();
if (isPDF(mimeType)) {
transformer = new MCRTransformerPipe(transformer, fopper);
LOGGER.info("Using stylesheet '{}' for {} and MCRFopper for PDF output.", Lists.newArrayList(stylesheets), idStripped);
} else {
LOGGER.info("Using stylesheet '{}' for {}", Lists.newArrayList(stylesheets), idStripped);
}
transformers.put(id, transformer);
return transformer;
}
Aggregations