Search in sources :

Example 1 with MCRXSL2JAXBTransformer

use of org.mycore.common.content.transformer.MCRXSL2JAXBTransformer 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 2 with MCRXSL2JAXBTransformer

use of org.mycore.common.content.transformer.MCRXSL2JAXBTransformer in project mycore by MyCoRe-Org.

the class MCRSolrTransformerInputDocumentFactory method getTransformer.

private static MCRContentTransformer getTransformer() {
    String property = CONFIG_PREFIX + "SolrInputDocument.Transformer";
    String transformerId = MCRConfiguration.instance().getString(property);
    MCRContentTransformer contentTransformer = MCRContentTransformerFactory.getTransformer(transformerId);
    isJAXBTransformer = contentTransformer instanceof MCRXSL2JAXBTransformer;
    return contentTransformer;
}
Also used : MCRXSL2JAXBTransformer(org.mycore.common.content.transformer.MCRXSL2JAXBTransformer) MCRContentTransformer(org.mycore.common.content.transformer.MCRContentTransformer)

Example 3 with MCRXSL2JAXBTransformer

use of org.mycore.common.content.transformer.MCRXSL2JAXBTransformer 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

MCRXSL2JAXBTransformer (org.mycore.common.content.transformer.MCRXSL2JAXBTransformer)3 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 JDOMException (org.jdom2.JDOMException)2 MCRContent (org.mycore.common.content.MCRContent)2 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)2 MCRSolrInputDocumentList (org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList)2 Document (org.jdom2.Document)1 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)1 MCRContentTransformer (org.mycore.common.content.transformer.MCRContentTransformer)1