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.");
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations