Package org.apache.chemistry.opencmis.commons.impl.dataobjects

Examples of org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl


      objectId = result.getPropertyById("cmis:objectId").getFirstValue().toString();
    }

    byte[] newContentByteArray = newContent.getBytes();
    InputStream stream = new ByteArrayInputStream(newContentByteArray);
    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger(newContentByteArray), "text/plain", stream);
    Document documentToUpdate = (Document) session.getObject(objectId);
    documentToUpdate.setContentStream(contentStream, true);
  }
View Full Code Here


    }

    // content stream

    public ContentStream createContentStream(String filename, long length, String mimetype, InputStream stream) {
        return new ContentStreamImpl(filename, BigInteger.valueOf(length), mimetype, stream);
    }
View Full Code Here

        // wrap with input stream
        ByteArrayInputStream bin = new ByteArrayInputStream(content);
        bin.reset();

        // create content stream
        return new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), mimeType, bin);
    }
View Full Code Here

    public static ContentStream convert(CmisContentStreamType contentStream) {
        if (contentStream == null) {
            return null;
        }

        ContentStreamImpl result = new ContentStreamImpl();

        result.setFileName(contentStream.getFilename());
        result.setLength(contentStream.getLength());
        result.setMimeType(contentStream.getMimeType());
        if (contentStream.getStream() != null) {
            try {
                try {
                    if (contentStream.getStream() instanceof StreamingDataHandler) {
                        result.setStream(((StreamingDataHandler) contentStream.getStream()).readOnce());
                    } else {
                        result.setStream(contentStream.getStream().getInputStream());
                    }
                } catch (NoClassDefFoundError cnfe) {
                    // Fallback in case the JAX-WS RI is not available (optional
                    // resolution in OSGi)
                    result.setStream(contentStream.getStream().getInputStream());
                }
            } catch (IOException e) {
                throw new CmisRuntimeException("Could not get the stream: " + e.getMessage(), e);
            }
        }
View Full Code Here

    }

    // content stream

    public ContentStream createContentStream(String filename, long length, String mimetype, InputStream stream) {
        return new ContentStreamImpl(filename, (length < 0 ? null : BigInteger.valueOf(length)), mimetype, stream);
    }
View Full Code Here

        return allowableActions.getAllowableActions();
    }

    public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset,
            BigInteger length, ExtensionsData extension) {
        ContentStreamImpl result = new ContentStreamImpl();

        // find the link
        String link = null;
        if (streamId != null) {
            // use the alternate link per spec
            link = loadLink(repositoryId, objectId, Constants.REL_ALTERNATE, streamId);
            if (link != null) {
                streamId = null; // we have a full URL now
            }
        }
        if (link == null) {
            link = loadLink(repositoryId, objectId, AtomPubParser.LINK_REL_CONTENT, null);
        }

        if (link == null) {
            throw new CmisConstraintException("No content stream");
        }

        UrlBuilder url = new UrlBuilder(link);
        // using the content URL and adding a streamId param
        // is not spec-compliant
        url.addParameter(Constants.PARAM_STREAM_ID, streamId);

        // get the content
        Response resp = getHttpInvoker().invokeGET(url, getSession(), offset, length);

        // check response code
        if ((resp.getResponseCode() != 200) && (resp.getResponseCode() != 206)) {
            throw convertStatusCode(resp.getResponseCode(), resp.getResponseMessage(), resp.getErrorContent(), null);
        }

        result.setFileName(null);
        result.setLength(resp.getContentLength());
        result.setMimeType(resp.getContentTypeHeader());
        result.setStream(resp.getStream());

        return result;
    }
View Full Code Here

        return new AccessControlListImpl(aces);
    }

    public static ContentStream createContentStream(HttpServletRequest request) {
        ContentStreamImpl result = null;

        if (request instanceof POSTHttpServletRequestWrapper) {
            POSTHttpServletRequestWrapper post = (POSTHttpServletRequestWrapper) request;
            if (post.getStream() != null) {
                result = new ContentStreamImpl(post.getFilename(), post.getSize(), post.getContentType(),
                        post.getStream());
            }
        }

        return result;
View Full Code Here

        byte[] contentBytes = null;
        Document result = null;
        try {
            contentBytes = content.getBytes("UTF-8");
            ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length),
                    "text/plain", new ByteArrayInputStream(contentBytes));

            // create the document
            result = parent.createDocument(properties, contentStream, versioningState, null, null, null,
                    SELECT_ALL_NO_CACHE_OC);

            contentStream.getStream().close();
        } catch (Exception e) {
            addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(),
                    e, true));
            return null;
        }

        try {
            CmisTestResult f;

            // check document name
            f = createResult(FAILURE, "Document name does not match!", false);
            addResult(assertEquals(name, result.getName(), null, f));

            // check the new document
            addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));

            // check content
            try {
                ContentStream contentStream = result.getContentStream();

                f = createResult(WARNING, "Document filename does not match!", false);
                addResult(assertEquals(name, contentStream.getFileName(), null, f));

                f = createResult(WARNING,
                        "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
                addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));

                String fetchedContent = getStringFromContentStream(result.getContentStream());
                if (!content.equals(fetchedContent)) {
                    addResult(createResult(FAILURE,
                            "Content of newly created document doesn't match the orign content!"));
View Full Code Here

    /**
     * Extract the content stream.
     */
    private void parseAtomContent(XMLStreamReader parser) throws Exception {
        atomContentStream = new ContentStreamImpl();

        // read attributes
        String type = "text";
        for (int i = 0; i < parser.getAttributeCount(); i++) {
            QName attrName = parser.getAttributeName(i);
View Full Code Here

    /**
     * Extract the content stream.
     */
    private void parseCmisContent(XMLStreamReader parser) throws Exception {
        cmisContentStream = new ContentStreamImpl();

        next(parser);

        // walk through all tags in content
        while (true) {
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl

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.