Search in sources :

Example 1 with MCRParameterCollector

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);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Example 2 with MCRParameterCollector

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;
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) HashMap(java.util.HashMap)

Example 3 with MCRParameterCollector

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;
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRContent(org.mycore.common.content.MCRContent)

Example 4 with MCRParameterCollector

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);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector)

Example 5 with MCRParameterCollector

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);
    }
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRException(org.mycore.common.MCRException) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) MCRException(org.mycore.common.MCRException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Aggregations

MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)12 MCRContent (org.mycore.common.content.MCRContent)6 MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)6 IOException (java.io.IOException)4 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)4 MCRException (org.mycore.common.MCRException)3 MCRParameterizedTransformer (org.mycore.common.content.transformer.MCRParameterizedTransformer)3 JAXBException (javax.xml.bind.JAXBException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 Document (org.jdom2.Document)2 JDOMException (org.jdom2.JDOMException)2 MCRXSL2JAXBTransformer (org.mycore.common.content.transformer.MCRXSL2JAXBTransformer)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 MCRSolrInputDocumentList (org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList)2 SAXException (org.xml.sax.SAXException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1