Search in sources :

Example 1 with MCRSolrInputDocumentList

use of org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList in project mycore by MyCoRe-Org.

the class MCRSolrInputDocumentGenerator method getSolrInputDocument.

public static List<SolrInputDocument> getSolrInputDocument(MCRContent source) throws JAXBException, IOException {
    if (source instanceof MCRJAXBContent) {
        @SuppressWarnings("unchecked") MCRJAXBContent<MCRSolrInputDocumentList> jaxbContent = (MCRJAXBContent<MCRSolrInputDocumentList>) source;
        return getSolrInputDocuments(jaxbContent.getObject().getDoc());
    }
    Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
    MCRSolrInputDocumentList solrDocuments = (MCRSolrInputDocumentList) unmarshaller.unmarshal(source.getSource());
    return getSolrInputDocuments(solrDocuments.getDoc());
}
Also used : MCRJAXBContent(org.mycore.common.content.MCRJAXBContent) MCRSolrInputDocumentList(org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 2 with MCRSolrInputDocumentList

use of org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList 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 3 with MCRSolrInputDocumentList

use of org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList 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

MCRSolrInputDocumentList (org.mycore.solr.index.document.jaxb.MCRSolrInputDocumentList)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 MCRXSL2JAXBTransformer (org.mycore.common.content.transformer.MCRXSL2JAXBTransformer)2 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)2 Unmarshaller (javax.xml.bind.Unmarshaller)1 Document (org.jdom2.Document)1 MCRJAXBContent (org.mycore.common.content.MCRJAXBContent)1 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)1