use of org.mycore.common.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRXEditorTransformerTest method testTransformation.
private void testTransformation(String inputFile, String editedXMLFile, MCREditorSession session, String expectedOutputFile) throws TransformerException, IOException, JDOMException, SAXException, JaxenException {
MCRParameterCollector pc = new MCRParameterCollector(false);
if (editedXMLFile != null) {
pc.setParameter("input", editedXMLFile);
}
MCRContent input = MCRSourceContent.getInstance("resource:" + inputFile);
MCRContent transformed = new MCRXEditorTransformer(session, pc).transform(input);
Document expected = MCRSourceContent.getInstance("resource:" + expectedOutputFile).asXML();
MCRBinding binding = new MCRBinding("//input[@type='hidden'][@name='_xed_session']/@value", true, new MCRBinding(expected));
binding.setValue(session.getID() + "-" + session.getChangeTracker().getChangeCounter());
String msg = "Transformed output is different to " + expectedOutputFile;
boolean isEqual = MCRXMLHelper.deepEqual(expected, transformed.asXML());
if (!isEqual)
System.out.println(transformed.asString());
assertTrue(msg, isEqual);
}
use of org.mycore.common.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRXEditorTransformerTest method buildEditorSession.
private MCREditorSession buildEditorSession(String editedXMLFile) {
HashMap<String, String[]> parameters = new HashMap<>();
if (editedXMLFile != null) {
parameters.put("input", new String[] { editedXMLFile });
}
MCRParameterCollector collector = new MCRParameterCollector(false);
collector.setParameter("input", editedXMLFile);
MCREditorSession editorSession = new MCREditorSession(parameters, collector);
editorSession.setID("1");
return editorSession;
}
use of org.mycore.common.xsl.MCRParameterCollector 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.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.
the class MCRStaticXEditorFileServlet method doExpandEditorElements.
public static MCRContent doExpandEditorElements(MCRContent content, HttpServletRequest request, HttpServletResponse response, String sessionID, String pageURL) throws IOException, JDOMException, SAXException {
MCRParameterCollector pc = new MCRParameterCollector(request, false);
MCREditorSession session = null;
if (sessionID != null) {
session = MCREditorSessionStoreFactory.getSessionStore().getSession(sessionID);
if (session == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Editor session timed out.");
return null;
}
} else {
session = new MCREditorSession(request.getParameterMap(), pc);
session.setPageURL(pageURL);
MCREditorSessionStoreFactory.getSessionStore().storeSession(session);
}
return new MCRXEditorTransformer(session, pc).transform(content);
}
use of org.mycore.common.xsl.MCRParameterCollector 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);
}
}
Aggregations