Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.ContentItem


        } else {
            uri = new UriRef(id);
        }
        log.debug("Created ContentItem with id:{} and uri:{}", id, uri);
        final MGraph g = new IndexedMGraph();
        ContentItem ci = null;
        try {
            ci = ciFactory.createContentItem(uri, new ByteArraySource(content, contentType), g);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", uri.getUnicodeString());
            throw new StoreException(String.format("Failed to create contentitem with uri: %s",
                uri.getUnicodeString()));
        }
        if (title != null && !title.trim().isEmpty()) {
            ci.addPart(TITLE_URI, title.trim());
        }
        return ci;
    }
View Full Code Here


            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
        }
        ContentItem ci = null;
        try {
            ci = ciFactory
                    .createContentItem(new UriRef(id), new ByteArraySource(content, mimeType), metadata);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", id);
View Full Code Here

                "ContentItem (that should never happen)!",e);
        }
    }

    public ContentItem get(String id) {
        ContentItem result;
        synchronized (data) {
            result = data.get(id);
        }
        return result;
    }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }

        // handle smart redirection to browser view
View Full Code Here

        }
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        if (type.equals("metadata")) {
            String fileName = URLEncoder.encode(uri, "utf-8") + "-metadata";
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            serializer.serialize(baos, ci.getMetadata(), format);
            InputStream is = new ByteArrayInputStream(baos.toByteArray());

            ResponseBuilder response = Response.ok((Object) is);
            response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            response.type("text/plain");
            addCORSOrigin(servletContext, response, headers);
            return response.build();
        } else if (type.equals("raw")) {
            String fileName = URLEncoder.encode(uri, "utf-8") + "-raw";
            ResponseBuilder response = Response.ok((Object) ci.getStream());
            response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            response.type(ci.getMimeType());
            addCORSOrigin(servletContext, response, headers);
            return response.build();
        } else {
            throw new WebApplicationException(404);
        }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, ci.getMetadata(), format);
        ResponseBuilder rb = Response.ok(out.toString(), "text/plain");
        addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        ResponseBuilder rb = Response.ok(ci.getStream(), ci.getMimeType());
        addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
View Full Code Here

                                              String chain,
                                              HttpHeaders headers) throws EngineException,
                                                                  URISyntaxException,
                                                                  StoreException {

        ContentItem ci = solrStore.create(content, uri, title, mediaType.toString());
        solrStore.enhanceAndPut(ci, indexName, chain);
        if (useExplicitRedirect) {
            // use an redirect to point browsers to newly created content
            ResponseBuilder rb = Response.seeOther(makeRedirectionURI(ci.getUri().getUnicodeString()));
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        } else {
            ResponseBuilder rb = Response.created(makeRedirectionURI(ci.getUri().getUnicodeString()));
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        }
    }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        solrStore.deleteById(uri, indexName);
        return RestUtil.createResponse(servletContext, Status.OK, null, headers);
View Full Code Here

    @Path("/page/{uri:.+}")
    @Produces(TEXT_HTML)
    public ContentItemResource getContentItemView(@PathParam(value = "uri") String uri) throws IOException,
                                                                                       StoreException {
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            throw new WebApplicationException(404);
        }
        return new ContentItemResource(uri, ci, uriInfo, "/contenthub/" + indexName + "/store/download",
                tcManager, serializer, servletContext);
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.ContentItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.