Search in sources :

Example 51 with MCRContent

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

the class MCRContentServlet method render.

@Override
protected void render(final MCRServletJob job, final Exception ex) throws Exception {
    if (ex != null) {
        throw ex;
    }
    final HttpServletRequest request = job.getRequest();
    final HttpServletResponse response = job.getResponse();
    final MCRContent content = getContent(request, response);
    boolean serveContent = MCRServletContentHelper.isServeContent(request);
    try {
        MCRServletContentHelper.serveContent(content, request, response, getServletContext(), getConfig(), serveContent);
    } catch (NoSuchFileException | FileNotFoundException e) {
        LOGGER.info("Catched {}:", e.getClass().getSimpleName(), e);
        response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
        return;
    }
    LOGGER.info("Finished serving resource.");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) HttpServletResponse(javax.servlet.http.HttpServletResponse) MCRContent(org.mycore.common.content.MCRContent)

Example 52 with MCRContent

use of org.mycore.common.content.MCRContent 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 53 with MCRContent

use of org.mycore.common.content.MCRContent 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)

Example 54 with MCRContent

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

the class MCRWorksFetcher method fetchWorksXML.

private Element fetchWorksXML(WebTarget target) throws JDOMException, IOException, SAXException {
    LOGGER.info("get {}", target.getUri());
    Builder b = target.request().accept(MCRORCIDConstants.ORCID_XML_MEDIA_TYPE).header("Authorization", "Bearer " + MCRReadPublicTokenFactory.getToken());
    MCRContent response = new MCRStreamContent(b.get(InputStream.class));
    MCRContent transformed = T_WORK2MCR.transform(response);
    return transformed.asXML().detachRootElement();
}
Also used : InputStream(java.io.InputStream) Builder(javax.ws.rs.client.Invocation.Builder) MCRContent(org.mycore.common.content.MCRContent) MCRStreamContent(org.mycore.common.content.MCRStreamContent)

Example 55 with MCRContent

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

the class MCRWorksFetcher method bibTeX2MODS.

/**
 * Parses the bibTeX code that may be included in the work entry
 * and returns its transformation to MODS
 */
private Optional<Element> bibTeX2MODS(String bibTeX) {
    if ((bibTeX != null) && !bibTeX.isEmpty()) {
        try {
            MCRContent result = T_BIBTEX2MODS.transform(new MCRStringContent(bibTeX));
            Element modsCollection = result.asXML().getRootElement();
            Element modsFromBibTeX = modsCollection.getChild("mods", MCRConstants.MODS_NAMESPACE);
            // Remove mods:extension containing the original BibTeX:
            modsFromBibTeX.removeChildren("extension", MCRConstants.MODS_NAMESPACE);
            return Optional.of(modsFromBibTeX);
        } catch (Exception ex) {
            String msg = "Exception parsing BibTeX: " + bibTeX;
            LOGGER.warn("{} {}", msg, ex.getMessage());
        }
    }
    return Optional.empty();
}
Also used : MCRStringContent(org.mycore.common.content.MCRStringContent) Element(org.jdom2.Element) MCRContent(org.mycore.common.content.MCRContent) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3