@Override public InputStream getStream() { ContentStream cs = doc.getContentStream(); return cs.getStream(); } }, name, getApplication());
document.setSize(doc.getContentStreamLength()); document.addAttribute("location", getFolderName(doc.getParents()) + getPathAsString(doc.getPaths())); if (doc.getContentStream() != null && contentUrl == null) { ContentStream stream = doc.getContentStream(); document.setContent(IOUtils.toByteArray(stream.getStream())); document.addAttribute("updated", "false");
/** * Downloads the contentStream for the given doc to the specified path. * * @param doc * the document * @param destinationPath * the destination path * * @throws IOException * if the download fails because of an IO problem * @throws CmisBaseException * if something go wrong, for example the document doesn't exist */ public static void download(Document doc, String destinationPath) throws IOException { if (doc == null) { return; } ContentStreamUtils.writeContentStreamToFile(doc.getContentStream(), new File(destinationPath)); }
/** * Downloads the contentStream for the given doc to the specified path. * * @param doc * the document * @param destinationPath * the destination path * * @throws IOException * if the download fails because of an IO problem * @throws CmisBaseException * if something go wrong, for example the document doesn't exist */ public static void download(Document doc, String destinationPath) throws IOException { if (doc == null) { return; } ContentStreamUtils.writeContentStreamToFile(doc.getContentStream(), new File(destinationPath)); }
StringBuilder strb = new StringBuilder(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(document.getContentStream().getStream())); try { String line = bufferedReader.readLine();
@Override public InputStream getDocumentContent(String id) { Session session = getSession(); if (session != null) { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("No id provided"); } Document document = (Document) session.getObject(id); if (document == null) { throw new IllegalArgumentException( "Document with this id does not exist"); } return document.getContentStream().getStream(); } return null; }
public ContentStream getContentStream(CmisObject cmisObject, String objectId) { validateObjectOrId(cmisObject, objectId); validateRedundantIdentifier(cmisObject, objectId); CmisObject target = getCmisObject(cmisObject, objectId); if (target != null && target instanceof Document) { return ((Document) target).getContentStream(); } else { logger.error("Unable to obtain the object reference in order to obtain the content of the object."); } return null; }
@Override public ContentStream getContentStream(String assetId) { // Get the request thread's session Session session = CmisSessionHelper.getSession(); // Fetch the Document object for this asset CmisObject object = session.getObject(new ObjectIdImpl(assetId)); if (!(object instanceof Document)) { throw new IllegalArgumentException("Object referenced by the uuid is not a document"); } Document doc = (Document) object; if (doc == null) return null; // Return the content as a stream return new ContentStreamCmisImpl(doc.getContentStream()); } }
@Override public ExternalBinaryValue getBinaryValue(String id) { org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document)session.getObject(id); if (doc == null) { return null; } ContentStream contentStream = doc.getContentStream(); if (contentStream == null) { return null; } return new CmisConnectorBinary(contentStream, getSourceName(), id, getMimeTypeDetector()); }
@Override public Stream getDocumentStream(final Path path) throws IOException { sessionExistsPreCondition(); // throws illegalStateException if no session String pathAsString = path2absoluteSlashSeparatedString(path); Document document = getDocument(pathAsString); return createStream(document.getContentStream()); }
public static ContentStream createContentStream(String filename, String mimeType, Object content) { ContentStreamImpl ret; if (content instanceof String) { ret = new ContentStreamImpl(filename, mimeType, (String) content); } else { ret = new ContentStreamImpl(); ret.setFileName(filename); ret.setMimeType(mimeType); if (content instanceof InputStream) { ret.setStream((InputStream) content); } else if (content instanceof byte[]) { ret.setStream(new ByteArrayInputStream((byte[]) content)); } else if (content instanceof Document) { ret = (ContentStreamImpl) ((Document) content).getContentStream(); } else { throw new IllegalArgumentException( "The content must be one of the following: Document, InputStream or Byte array. The received type is not a valid one for generating a content stream: " + content.getClass()); } } return ret; }
public Object read(ObjectInputStream os) throws IOException, ClassNotFoundException { String objectId = os.readUTF(); String canonicalName = os.readUTF(); Session session = getRepositorySession(user, password, url, repository); try { org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document) findObjectForId(session, objectId); Document document = (Document) Class.forName(canonicalName).newInstance(); document.setIdentifier(objectId); document.setName(doc.getName()); document.addAttribute("location", getFolderName(doc.getParents()) + getPathAsString(doc.getPaths())); if (doc.getContentStream() != null) { ContentStream stream = doc.getContentStream(); document.setContent(IOUtils.toByteArray(stream.getStream())); document.addAttribute("updated", "false"); document.addAttribute("type", stream.getMimeType()); } return document; } catch(Exception e) { throw new RuntimeException("Cannot read document from CMIS", e); } finally { session.clear(); } }
public InputStream getProcessImage(String processDefinitionId) { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(WORKFLOW_DEFINITION_FOLDER); Document imageDocument = (Document) cmisSession.getObjectByPath(workflowDefinitionFolder.getPath() + "/" + processDefinitionIdToProcessImage(processDefinitionId)); return imageDocument.getContentStream().getStream(); }
public void testDownloadEvent() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); String docname = "mydoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, docname); } // content byte[] byteContent = "Hello from Download testing class".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream); Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); ContentStream content = doc1.getContentStream(); assertNotNull(content); //range request content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4)); assertNotNull(content); }
@Override public T retrieve(String path, String documentName, Session session) throws Exception { // Disable cache session.getDefaultContext().setCacheEnabled(false); Document object = (Document)FileUtils.getObject(path + documentName, session); ContentStream contentStream = object.getContentStream(); Class<T> classP = getClassP(); T document = classP.newInstance(); document.setContentStream(IOUtils.toByteArray(contentStream.getStream())); document.setContentStreamFilename(documentName); document.setContentStreamLenght(contentStream.getLength()); document.setContentStreamMimeType(contentStream.getMimeType()); // Enable cache session.getDefaultContext().setCacheEnabled(true); return document; }
ContentStream contentStream = allPropsDoc.getContentStream(); try { return getSession().createDocument(newProperties, targetFolderId, contentStream, versioningState, policies,
ContentStream contentStream = allPropsDoc.getContentStream(); try { return getSession().createDocument(newProperties, targetFolderId, contentStream, versioningState, policies,
Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session); ContentStream content = document.getContentStream(); assertNotNull(content); content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4)); assertNotNull(content);
addResult(assertEquals(doc1.getContentStream(), doc2.getContentStream(), null, f));
/** * Converts binary content into JCR node. * * @param id the id of the CMIS document. * @return JCR node representation. */ private Document cmisContent( String id ) { DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.CONTENT, id)); org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document)session.getObject(id); writer.setPrimaryType(NodeType.NT_RESOURCE); writer.setParent(id); ContentStream contentStream = doc.getContentStream(); if (contentStream != null) { BinaryValue content = new CmisConnectorBinary(contentStream, getSourceName(), id, getMimeTypeDetector()); writer.addProperty(JcrConstants.JCR_DATA, content); writer.addProperty(JcrConstants.JCR_MIME_TYPE, contentStream.getMimeType()); } Property<Object> lastModified = doc.getProperty(PropertyIds.LAST_MODIFICATION_DATE); Property<Object> lastModifiedBy = doc.getProperty(PropertyIds.LAST_MODIFIED_BY); writer.addProperty(JcrLexicon.LAST_MODIFIED, properties.jcrValues(lastModified)); writer.addProperty(JcrLexicon.LAST_MODIFIED_BY, properties.jcrValues(lastModifiedBy)); return writer.document(); }