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

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


        String mimetype = "text/html; charset=UTF-8";
        String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";

        byte[] buf1 = content1.getBytes("UTF-8");
        ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
        ContentStream contentStream = session.getObjectFactory().createContentStream(filename, buf1.length, mimetype,
                in1);
        assertNotNull(contentStream);

        ObjectId id = session.createDocument(properties, parentId, null, VersioningState.NONE);
        assertNotNull(id);
View Full Code Here


        String mimetype = "text/html; charset=UTF-8";
        String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";

        byte[] buf1 = content1.getBytes("UTF-8");
        ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
        ContentStream contentStream1 = session.getObjectFactory().createContentStream(filename1, buf1.length, mimetype,
                in1);
        assertNotNull(contentStream1);

        ObjectId id = session.createDocument(properties, parentId, contentStream1, VersioningState.NONE);
        assertNotNull(id);

        // set and verify content
        String filename2 = UUID.randomUUID().toString();
        String content2 = "abc";

        byte[] buf2 = content2.getBytes("UTF-8");
        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = session.getObjectFactory().createContentStream(filename2, buf2.length, mimetype,
                in2);
        assertNotNull(contentStream2);

        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
View Full Code Here

        String mimetype = "text/html; charset=UTF-8";
        String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";

        byte[] buf1 = content1.getBytes("UTF-8");
        ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
        ContentStream contentStream1 = session.getObjectFactory().createContentStream(filename1, buf1.length, mimetype,
                in1);
        assertNotNull(contentStream1);

        ObjectId id = session.createDocument(properties, parentId, contentStream1, VersioningState.NONE);
        assertNotNull(id);

        // set and verify content
        String filename2 = UUID.randomUUID().toString();
        String content2 = "abc";

        byte[] buf2 = content2.getBytes("UTF-8");
        ByteArrayInputStream in2 = new ByteArrayInputStream(buf2);
        ContentStream contentStream2 = session.getObjectFactory().createContentStream(filename2, buf2.length, mimetype,
                in2);
        assertNotNull(contentStream2);

        Document doc = (Document) session.getObject(id);
        assertNotNull(doc);
View Full Code Here

        return createDocumentNoCatch(name, folderId, typeId, versioningState, withContent, null, null);
    }

    protected String createDocumentNoCatch(String name, String folderId, String typeId,
            VersioningState versioningState, boolean withContent, Acl addACEs, Acl removeACEs) {
        ContentStream contentStream = null;
        List<String> policies = null;
        ExtensionsData extension = null;

        Properties props = createDocumentProperties(name, typeId);
View Full Code Here

        checkIsVersionableObject(so);

        VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);

        ContentStream content = null;

        if (so instanceof DocumentVersion) {
            // get document the version is contained in to c
            content = ((DocumentVersion) so).getContent(0, -1);
        } else {
View Full Code Here

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZ");
        return sdf.format(cal.getTime());
    }

    public static void download(Component component, CmisObject object, String streamId) {
        ContentStream content = getContentStream(object, streamId);
        if (content == null) {
            return;
        }

        String filename = content.getFileName();
        if (filename == null) {
            if (object instanceof Document) {
                filename = ((Document) object).getContentStreamFileName();
            } else {
                filename = object.getName();
            }
        }

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setSelectedFile(new File(filename));

        int chooseResult = fileChooser.showDialog(component, "Download");
        if (chooseResult == JFileChooser.APPROVE_OPTION) {
            try {
                storeStream(content.getStream(), fileChooser.getSelectedFile());
            } catch (Exception e) {
                showError(component, e);
            }
        }
    }
View Full Code Here

        return tempFile;
    }

    public static File createTempFileFromDocument(CmisObject object, String streamId) throws Exception {
        ContentStream content = getContentStream(object, streamId);
        if (content == null) {
            throw new Exception("No content!");
        }

        String filename = content.getFileName();
        if ((filename == null) || (filename.length() == 0)) {
            if (object instanceof Document) {
                filename = ((Document) object).getContentStreamFileName();
            }
        }
        if ((filename == null) || (filename.length() == 0)) {
            filename = object.getName();
        }
        if ((filename == null) || (filename.length() == 0)) {
            filename = "content";
        }

        String ext = MimeTypes.getExtension(content.getMimeType());
        if (ext.length() > 0 && !filename.endsWith(ext)) {
            filename = filename + ext;
        }

        File tempFile = ClientHelper.createTempFile(filename);
        try {
            storeStream(content.getStream(), tempFile);
        } catch (CmisConstraintException e) {
            // there is no content - leave the temp file empty
        }

        return tempFile;
View Full Code Here

        LOG.debug("start createDocumentFromSource()");
        StoredObject so = validator.createDocumentFromSource(context, repositoryId, sourceId, folderId, extension);
        TypeDefinition td = getTypeDefinition(repositoryId, so)// typedefinition may be copied from source object

        ContentStream content = getContentStream(context, repositoryId, sourceId, null, BigInteger.valueOf(-1),
                BigInteger.valueOf(-1), null);

        if (so == null) {
            throw new CmisObjectNotFoundException("Unknown object id: " + sourceId);
        }
View Full Code Here

        if (!(so instanceof Content)) {
            throw new CmisConstraintException("Id" + objectId
                    + " does not refer to a document or version, but only those can have content");
        }

        ContentStream csd = getContentStream(so, streamId, offset, length);

        if (null == csd) {
            throw new CmisConstraintException("Object " + so.getId() + " does not have content.");
        }
View Full Code Here

        if (streamId != null) {
            return null;
        }
        long lOffset = offset == null ? 0 : offset.longValue();
        long lLength = length == null ? -1 : length.longValue();
        ContentStream csd = ((Content) so).getContent(lOffset, lLength);
        return csd;
    }
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.