Search in sources :

Example 6 with MCRParameterCollector

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);
    }
}
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)

Example 7 with MCRParameterCollector

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

Example 8 with MCRParameterCollector

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);
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) MCRViewerConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerConfigurationStrategy) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRViewerDefaultConfigurationStrategy(org.mycore.viewer.configuration.MCRViewerDefaultConfigurationStrategy) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 9 with MCRParameterCollector

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);
    }
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) JAXBException(javax.xml.bind.JAXBException) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) IOException(java.io.IOException) Document(org.jdom2.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) MCRSolrInputDocumentList(org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList) MCRXSL2JAXBTransformer(org.mycore.common.content.transformer.MCRXSL2JAXBTransformer) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 10 with MCRParameterCollector

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);
    }
}
Also used : MCRParameterCollector(org.mycore.common.xsl.MCRParameterCollector) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) MCRSolrInputDocumentList(org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MCRXSL2JAXBTransformer(org.mycore.common.content.transformer.MCRXSL2JAXBTransformer) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

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