use of org.mycore.common.content.MCRStreamContent in project mycore by MyCoRe-Org.
the class MCRCStoreIFS2 method doStoreContent.
@Override
protected String doStoreContent(org.mycore.datamodel.ifs.MCRFile fr, MCRContentInputStream source) throws Exception {
int slotID = getSlotID(fr.getOwnerID());
String base = getBase(fr.getOwnerID());
MCRFileStore store = getStore(base);
MCRFileCollection slot = store.retrieve(slotID);
if (slot == null)
slot = store.create(slotID);
String path = fr.getAbsolutePath();
MCRDirectory dir = slot;
StringTokenizer steps = new StringTokenizer(path, "/");
while (steps.hasMoreTokens()) {
String step = steps.nextToken();
if (steps.hasMoreTokens()) {
MCRNode child = dir.getChild(step);
if (child == null)
dir = dir.createDir(step);
else
dir = (MCRDirectory) child;
} else {
MCRFile file = (MCRFile) (dir.getChild(step));
if (file == null)
file = dir.createFile(step);
file.setContent(new MCRStreamContent(source));
}
}
return fr.getOwnerID() + path;
}
use of org.mycore.common.content.MCRStreamContent in project mycore by MyCoRe-Org.
the class MCRClassificationUtils method fromStream.
/**
* Imports a classification from the given input stream. If the classification
* already exists, it will be replaced.
*
* @param inputStream the classification stream
* @throws MCRException xml parsing went wrong
* @throws SAXParseException xml parsing went wrong
* @throws URISyntaxException unable to transform the xml to a {@link MCRCategory}
* @throws MCRAccessException you are not allowed to import the classification
*/
public static void fromStream(InputStream inputStream) throws MCRException, SAXParseException, URISyntaxException, MCRAccessException {
MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();
Document jdom = MCRXMLParserFactory.getParser().parseXML(new MCRStreamContent(inputStream));
MCRCategory classification = MCRXMLTransformer.getCategory(jdom);
if (DAO.exist(classification.getId())) {
if (!MCRAccessManager.checkPermission(classification.getId().getRootID(), PERMISSION_WRITE)) {
throw MCRAccessException.missingPermission("update classification " + classification.getId().getRootID(), classification.getId().getRootID(), PERMISSION_WRITE);
}
DAO.replaceCategory(classification);
} else {
if (!MCRAccessManager.checkPermission(CREATE_CLASS_PERMISSION)) {
throw MCRAccessException.missingPermission("create classification " + classification.getId().getRootID(), classification.getId().getRootID(), CREATE_CLASS_PERMISSION);
}
DAO.addCategory(null, classification);
}
}
use of org.mycore.common.content.MCRStreamContent in project mycore by MyCoRe-Org.
the class MCRGoobiMetsPostUploadProcessor method processFile.
@Override
public Path processFile(String path, Path tempFile, Supplier<Path> tempFileSupplier) throws IOException {
try (InputStream in = Files.newInputStream(tempFile)) {
MCRStreamContent streamContent = new MCRStreamContent(in);
MCRContent transform = goobiMetsTransformer.transform(streamContent);
Path result = tempFileSupplier.get();
try (OutputStream out = Files.newOutputStream(result)) {
out.write(transform.asByteArray());
return result;
}
}
}
use of org.mycore.common.content.MCRStreamContent in project mycore by MyCoRe-Org.
the class MCRSolrProxyServlet method handleQuery.
private void handleQuery(String queryHandlerPath, HttpServletRequest request, HttpServletResponse resp) throws IOException, TransformerException, SAXException {
ModifiableSolrParams solrParameter = getSolrQueryParameter(request);
HttpGet solrHttpMethod = MCRSolrProxyServlet.getSolrHttpMethod(queryHandlerPath, solrParameter);
try {
LOGGER.info("Sending Request: {}", solrHttpMethod.getURI());
HttpResponse response = httpClient.execute(solrHost, solrHttpMethod);
int statusCode = response.getStatusLine().getStatusCode();
// set status code
resp.setStatus(statusCode);
boolean isXML = response.getFirstHeader(HTTP.CONTENT_TYPE).getValue().contains("/xml");
boolean justCopyInput = !isXML;
// set all headers
for (Header header : response.getAllHeaders()) {
if (!HTTP.TRANSFER_ENCODING.equals(header.getName())) {
resp.setHeader(header.getName(), header.getValue());
}
}
HttpEntity solrResponseEntity = response.getEntity();
if (solrResponseEntity != null) {
try (InputStream solrResponseStream = solrResponseEntity.getContent()) {
if (justCopyInput) {
// copy solr response to servlet outputstream
OutputStream servletOutput = resp.getOutputStream();
IOUtils.copy(solrResponseStream, servletOutput);
} else {
MCRStreamContent solrResponse = new MCRStreamContent(solrResponseStream, solrHttpMethod.getURI().toString(), "response");
MCRLayoutService.instance().doLayout(request, resp, solrResponse);
}
}
}
} catch (IOException ex) {
solrHttpMethod.abort();
throw ex;
}
solrHttpMethod.releaseConnection();
}
use of org.mycore.common.content.MCRStreamContent 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();
}
Aggregations