Package org.apache.chemistry.opencmis.commons.data

Examples of org.apache.chemistry.opencmis.commons.data.ContentStream


        return getObject().getAllowableActions().getAllowableActions().contains(Action.CAN_CHECK_IN);
    }

    @Override
    public boolean doAction() throws Exception {
        ContentStream content = getClientModel().createContentStream(filenameField.getText());
        ((Document) getObject()).checkIn(majorBox.isSelected(), null, content, null, null, null, null);
        return false;
    }
View Full Code Here


                mimeType = overridden;
            long length = f.length();
           
            is = new FileInputStream(fileName);

            ContentStream contentStream = session.getObjectFactory().createContentStream(fileName,
                    length, mimeType, is);
            if (!properties.containsKey(PropertyIds.NAME))
                properties.put(PropertyIds.NAME, f.getName());
            Document doc = parentFolder.createDocument(properties, contentStream, VersioningState.NONE);
            id = doc.getId();
View Full Code Here

        assertNull(aep.getProperties());
    }

    private static byte[] parse(byte[] entry) throws Exception {
        AtomEntryParser aep = new AtomEntryParser(new ByteArrayInputStream(entry), null, THRESHOLD);
        ContentStream contentStream = aep.getContentStream();

        assertNotNull(contentStream);
        assertNotNull(contentStream.getStream());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buffer = new byte[4096];
        int b;

        while ((b = contentStream.getStream().read(buffer)) > -1) {
            baos.write(buffer, 0, b);
        }

        return baos.toByteArray();
    }
View Full Code Here

        return id;
    }

    private String createDocumentIntern(String name, String typeId, String folderId, VersioningState versioningState) {
        ContentStream contentStream = null;
        List<String> policies = null;
        Acl addACEs = null;
        Acl removeACEs = null;
        ExtensionsData extension = null;
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);
View Full Code Here

                        createResult(FAILURE, "Content properties are not set but the document type demands content!"));
            }
        }

        // get the content stream
        ContentStream contentStream = doc.getContentStream();

        if (contentStream == null) {
            if (hasContentProperties && doc.getContentStreamLength() > 0) {
                addResult(results,
                        createResult(FAILURE, "Content properties have values but the document has no content!"));
            }

            if (type.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
                addResult(results,
                        createResult(FAILURE, "The document type demands content but the document has no content!"));
            }

            return;
        }

        if (type.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) {
            addResult(results, createResult(FAILURE, "Document type doesn't allow content but document has content!"));
        }

        // file name check
        f = createResult(FAILURE, "Content file names don't match!");
        addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f));

        if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) {
            f = createResult(FAILURE, "Content lengths don't match!");
            addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f));
        }

        // MIME type check
        String docMimeType = doc.getContentStreamMimeType();
        if (docMimeType != null) {
            int x = docMimeType.indexOf(';');
            if (x > -1) {
                docMimeType = docMimeType.substring(0, x);
            }
            docMimeType = docMimeType.trim();
        }

        String contentMimeType = contentStream.getMimeType();
        if (contentMimeType != null) {
            int x = contentMimeType.indexOf(';');
            if (x > -1) {
                contentMimeType = contentMimeType.substring(0, x);
            }
            contentMimeType = contentMimeType.trim();
        }

        f = createResult(FAILURE, "Content MIME types don't match!");
        addResult(results, assertEquals(docMimeType, contentMimeType, null, f));

        if (contentStream.getMimeType() != null) {
            if (contentMimeType.equals(docMimeType)) {
                f = createResult(WARNING, "Content MIME types don't match!");
                addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f));
            }

            f = createResult(FAILURE, "Content MIME types is invalid: " + contentStream.getMimeType());
            addResult(
                    results,
                    assertIsTrue(contentStream.getMimeType().length() > 2
                            && contentStream.getMimeType().indexOf('/') > 0, null, f));
        }

        // check stream
        InputStream stream = contentStream.getStream();
        if (stream == null) {
            addResult(results, createResult(FAILURE, "Docuemnt has no content stream!"));
            return;
        }

        try {
            long bytes = 0;
            byte[] buffer = new byte[64 * 1024];
            int b = stream.read(buffer);
            while (b > -1) {
                bytes += b;
                b = stream.read(buffer);
            }
            stream.close();

            // check content length
            if (doc.getContentStreamLength() > -1) {
                f = createResult(FAILURE,
                        "Content stream length property value doesn't match the actual content length!");
                addResult(results, assertEquals(doc.getContentStreamLength(), bytes, null, f));
            }

            if (contentStream.getLength() > -1) {
                f = createResult(FAILURE, "Content length value doesn't match the actual content length!");
                addResult(results, assertEquals(contentStream.getLength(), bytes, null, f));
            }
        } catch (Exception e) {
            addResult(results, createResult(FAILURE, "Reading content failed: " + e, e, false));
        } finally {
            try {
View Full Code Here

                                        + rend.getStreamId());
                        addResult(results, assertIsTrue(rend.getWidth() > 0, null, f));
                    }

                    // check the content
                    ContentStream contentStream = rend.getContentStream();
                    f = createResult(FAILURE, "A rendition has no content stream! Stream id: " + rend.getStreamId());
                    addResult(results, assertNotNull(contentStream, null, f));

                    if (contentStream != null) {
                        InputStream stream = contentStream.getStream();

                        f = createResult(FAILURE, "A rendition has no stream! Stream id: " + rend.getStreamId());
                        addResult(results, assertNotNull(stream, null, f));

                        if (stream != null) {
View Full Code Here

                        // create a document from a file
                        objectId = getClientModel().createDocument(name, type, filename, versioningState,
                                unfiledButton.isSelected());

                        if (verifyAfterUploadButton.isSelected()) {
                            ContentStream contentStream = getClientModel().createContentStream(filename);
                            verifyContentStreams(contentStream, objectId);
                        }
                    } else {
                        // create a document with random data
                        long seed = System.currentTimeMillis();
                        long length = ((Number) generateContentSizeField.getValue()).longValue();
                        if (length < 0) {
                            length = 0;
                        } else {
                            for (int i = 0; i < generateContentUnitField.getSelectedIndex(); i++) {
                                length = length * 1024;
                            }
                        }

                        objectId = getClientModel().createDocument(name, type, length, seed, versioningState,
                                unfiledButton.isSelected());

                        if (verifyAfterUploadButton.isSelected()) {
                            ContentStream contentStream = getClientModel().createContentStream("", length, seed);
                            verifyContentStreams(contentStream, objectId);
                        }
                    }

                    if (objectId != null) {
View Full Code Here

    private void verifyContentStreams(ContentStream sourceContentStream, ObjectId objectId) {
        // download content from repository
        ClientSession clientSession = getClientModel().getClientSession();
        Document doc = (Document) clientSession.getSession().getObject(objectId,
                clientSession.getObjectOperationContext());
        ContentStream docContentStream = doc.getContentStream();

        // compare
        if (docContentStream == null) {
            if (sourceContentStream.getLength() == 0) {
                JOptionPane.showMessageDialog(getOwner(), "Source file and document content are both empty.",
                        "Verification successful", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(getOwner(), "Document has no conent but the source file is not empty!",
                        "Verification failed", JOptionPane.ERROR_MESSAGE);
            }
            return;
        }

        InputStream sourceContent = null;
        InputStream docContent = null;
        try {
            sourceContent = new BufferedInputStream(sourceContentStream.getStream());
            docContent = new BufferedInputStream(docContentStream.getStream());

            int fb = 0;
            int db = 0;
            long pos = 0;
            while (fb > -1 && db > -1) {
View Full Code Here

        String id = createDocument(fRootFolderId, true);
        if (id != null) {
            log.info("createDocument succeeded with created id: " + id);
        }

        ContentStream sd = fObjSvc.getContentStream(fRepositoryId, id, null, BigInteger.valueOf(-1) /* offset */,
                BigInteger.valueOf(-1) /* length */, null);
        verifyContentResult(sd);

        // delete content again
        Holder<String> idHolder = new Holder<String>(id);
        Properties props = fObjSvc.getProperties(fRepositoryId, id, PropertyIds.CHANGE_TOKEN, null);
        String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
        Holder<String> tokenHolder = new Holder<String>(changeToken);
        fObjSvc.deleteContentStream(fRepositoryId, idHolder, tokenHolder, null);
       
        try {
            props = fObjSvc.getProperties(fRepositoryId, id, PropertyIds.CHANGE_TOKEN, null);
            changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
            tokenHolder = new Holder<String>(changeToken);
            sd = fObjSvc.getContentStream(fRepositoryId, id, null, BigInteger.valueOf(-1) /* offset */, BigInteger
                    .valueOf(-1) /* length */, null);
            fail("getContentStream with non existing content should raise a CmisConstraintException");
        } catch (Exception e) {
            assertTrue(e instanceof CmisConstraintException);
        }
       
        // create content again in a second call
        ContentStream contentStream = createContent();
        fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, contentStream, null);
        sd = fObjSvc.getContentStream(fRepositoryId, id, null, BigInteger.valueOf(-1) /* offset */, BigInteger
                .valueOf(-1) /* length */, null);
        verifyContentResult(sd);

View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.data.ContentStream

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.