Java Code Examples for org.apache.chemistry.opencmis.client.api.Document#getContentStream()
The following examples show how to use
org.apache.chemistry.opencmis.client.api.Document#getContentStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmisRead.java From cloud-espm-v2 with Apache License 2.0 | 6 votes |
/** * This is a custom implementation of the doGet method of the * {@link HttpServlet}. * <p> * Here, we expect an "objectId" to be passed as input parameter. This * objectId will be fetched to the {@link Session} to fetch the existing * document(if present). */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String objectId = request.getParameter("objectId"); try { if (openCmisSession != null) { Document doc = (Document) openCmisSession.getObject(objectId); ContentStream content = doc.getContentStream(); String type = content.getMimeType(); String name = content.getFileName(); int length = (int) content.getLength(); InputStream stream = content.getStream(); response.setContentType(type); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + name); response.setContentLength(length); ioCopy(stream, response.getOutputStream()); } else { response.setStatus(501); } } catch (Exception exception) { LOGGER.error(exception.getMessage()); } }
Example 2
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
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); }
Example 3
Source File: OpenCmisLocalTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testEncodingForCreateContentStream() { ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); FileFolderService ffs = serviceRegistry.getFileFolderService(); // Authenticate as system AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx .getBean(BEAN_NAME_AUTHENTICATION_COMPONENT); authenticationComponent.setSystemUserAsCurrentUser(); try { /* Create the document using openCmis services */ Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); 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); NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId()); FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef); Map<QName, Serializable> properties = fileInfo.getProperties(); ContentDataWithId contentData = (ContentDataWithId) properties .get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content")); String encoding = contentData.getEncoding(); assertEquals("ISO-8859-1", encoding); } finally { authenticationComponent.clearCurrentSecurityContext(); } }
Example 4
Source File: PublicApiClient.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public ContentData getContent(String objectId) throws IOException { CmisObject o = getObject(objectId); if(o instanceof Document) { Document d = (Document)o; ContentStream res = d.getContentStream(); ContentData c = new ContentData(res); return c; } else { throw new IllegalArgumentException("Object does not exist or is not a document"); } }