Search in sources :

Example 11 with MCRParameterCollector

use of org.mycore.common.xsl.MCRParameterCollector in project mycore by MyCoRe-Org.

the class MCRMailer method transform.

/**
 * Transforms the given input element using xsl stylesheet.
 *
 * @param input the input document to transform.
 * @param stylesheet the name of the xsl stylesheet to use, without the ".xsl" ending.
 * @param parameters the optionally empty table of xsl parameters
 * @return the output document generated by the transformation process
 */
private static Document transform(Document input, String stylesheet, Map<String, String> parameters) throws Exception {
    MCRJDOMContent source = new MCRJDOMContent(input);
    MCRXSL2XMLTransformer transformer = MCRXSL2XMLTransformer.getInstance("xsl/" + stylesheet + ".xsl");
    MCRParameterCollector parameterCollector = MCRParameterCollector.getInstanceFromUserSession();
    parameterCollector.setParameters(parameters);
    MCRContent result = transformer.transform(source, parameterCollector);
    return result.asXML();
}
Also used : MCRXSL2XMLTransformer(org.mycore.common.content.transformer.MCRXSL2XMLTransformer) MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRContent(org.mycore.common.content.MCRContent)

Example 12 with MCRParameterCollector

use of org.mycore.common.xsl.MCRParameterCollector 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();
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRException(org.mycore.common.MCRException) MCRPathContent(org.mycore.common.content.MCRPathContent) MCRParameterizedTransformer(org.mycore.common.content.transformer.MCRParameterizedTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRContent(org.mycore.common.content.MCRContent)

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