@Override public String getContentType() { return contentStream.getMimeType(); } }));
public String getMimeType() { return cmisContentStream.getMimeType(); }
private String parseMimeType(ContentStream contentStream) { String mimeType = null; String tmp = contentStream.getMimeType(); if(tmp != null) { int idx = tmp.indexOf(";"); if(idx != -1) { mimeType = tmp.substring(0, idx).trim(); } else { mimeType = tmp; } } return mimeType; }
private String parseMimeType(ContentStream contentStream) { String mimeType = null; String tmp = contentStream.getMimeType(); if(tmp != null) { int idx = tmp.indexOf(";"); if(idx != -1) { mimeType = tmp.substring(0, idx).trim(); } else { mimeType = tmp; } } return mimeType; }
static Stream createStream(final ContentStream contentStream) { return ECMHelper.createStream(contentStream.getStream(), contentStream.getMimeType(), contentStream.getLength()); }
@Override public ContentStream convertContentStream(ContentStream contentStream) { if (contentStream == null) { return null; } BigInteger length = (contentStream.getLength() < 0 ? null : BigInteger.valueOf(contentStream.getLength())); return getBindingsObjectFactory().createContentStream(contentStream.getFileName(), length, contentStream.getMimeType(), contentStream.getStream()); }
@Override public ContentStream convertContentStream(ContentStream contentStream) { if (contentStream == null) { return null; } BigInteger length = (contentStream.getLength() < 0 ? null : BigInteger.valueOf(contentStream.getLength())); return getBindingsObjectFactory().createContentStream(contentStream.getFileName(), length, contentStream.getMimeType(), contentStream.getStream()); }
/** * Constructor for objects. */ public AtomEntryWriter(ObjectData object, CmisVersion cmisVersion, ContentStream contentStream) { if ((object == null) || (object.getProperties() == null)) { throw new CmisInvalidArgumentException("Object and properties must not be null!"); } if ((contentStream != null) && (contentStream.getMimeType() == null)) { throw new CmisInvalidArgumentException("Media type must be set if a stream is present!"); } this.object = object; this.cmisVersion = cmisVersion; this.contentStream = contentStream; if (contentStream != null && contentStream.getStream() != null) { InputStream in = contentStream.getStream(); // avoid double buffering if (!(in instanceof BufferedInputStream) && !(in instanceof ByteArrayInputStream)) { stream = new BufferedInputStream(in, BUFFER_SIZE); } else { stream = in; } } else { stream = null; } this.typeDef = null; this.bulkUpdate = null; }
/** * Constructor for objects. */ public AtomEntryWriter(ObjectData object, CmisVersion cmisVersion, ContentStream contentStream) { if (object == null || object.getProperties() == null) { throw new CmisInvalidArgumentException("Object and properties must not be null!"); } if (contentStream != null && contentStream.getMimeType() == null) { throw new CmisInvalidArgumentException("Media type must be set if a stream is present!"); } this.object = object; this.cmisVersion = cmisVersion; this.contentStream = contentStream; if (contentStream != null && contentStream.getStream() != null) { InputStream in = contentStream.getStream(); // avoid double buffering if (!(in instanceof BufferedInputStream) && !(in instanceof ByteArrayInputStream)) { stream = new BufferedInputStream(in, BUFFER_SIZE); } else { stream = in; } } else { stream = null; } this.typeDef = null; this.bulkUpdate = null; }
String mediaType = contentStream.getMimeType(); if (mediaType == null || mediaType.indexOf('/') < 1 || mediaType.indexOf('\n') > -1 || mediaType.indexOf('\r') > -1) {
public ReusableContentStream(ContentStream contentStream) throws Exception { setLength(contentStream.getBigLength()); setMimeType(contentStream.getMimeType()); setFileName(contentStream.getFileName()); file = TempFileProvider.createTempFile(contentStream.getStream(), "cmis", "contentStream"); }
public ReusableContentStream(ContentStream contentStream) throws Exception { setLength(contentStream.getBigLength()); setMimeType(contentStream.getMimeType()); setFileName(contentStream.getFileName()); file = TempFileProvider.createTempFile(contentStream.getStream(), "cmis", "contentStream"); }
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(); } }
@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; }
@Override public ContentStream getContentStream(String streamId, BigInteger offset, BigInteger length) { // get the stream ContentStream contentStream = getSession().getContentStream(this, streamId, offset, length); if (contentStream == null) { return null; } // the AtomPub binding doesn't return a file name // -> get the file name from properties, if present String filename = contentStream.getFileName(); if (filename == null) { filename = getContentStreamFileName(); } long lengthLong = (contentStream.getBigLength() == null ? -1 : contentStream.getBigLength().longValue()); // convert and return stream object return getSession().getObjectFactory().createContentStream(filename, lengthLong, contentStream.getMimeType(), contentStream.getStream(), contentStream instanceof PartialContentStream); }
@Override public ContentStream getContentStream(String streamId, BigInteger offset, BigInteger length) { // get the stream ContentStream contentStream = getSession().getContentStream(this, streamId, offset, length); if (contentStream == null) { return null; } // the AtomPub binding doesn't return a file name // -> get the file name from properties, if present String filename = contentStream.getFileName(); if (filename == null) { filename = getContentStreamFileName(); } long lengthLong = (contentStream.getBigLength() == null ? -1 : contentStream.getBigLength().longValue()); // convert and return stream object return getSession().getObjectFactory().createContentStream(filename, lengthLong, contentStream.getMimeType(), contentStream.getStream(), contentStream instanceof PartialContentStream); }
document.setContent(IOUtils.toByteArray(stream.getStream())); document.addAttribute("updated", "false"); document.addAttribute("type", stream.getMimeType()); } else { document.setLink(contentUrl + document.getIdentifier());
@Override public ContentStream getContentStream() { if (objectId == null || getStreamId() == null) { return null; } ContentStream contentStream; try { contentStream = session.getBinding().getObjectService() .getContentStream(session.getRepositoryInfo().getId(), objectId, getStreamId(), null, null, null); } catch (CmisConstraintException e) { // no content stream return null; } if (contentStream == null) { return null; } String filename = contentStream.getFileName(); if (filename == null) { filename = getTitle(); } BigInteger bigLength = contentStream.getBigLength(); if (bigLength == null) { bigLength = getBigLength(); } long length = bigLength == null ? -1 : bigLength.longValue(); return session.getObjectFactory().createContentStream(filename, length, contentStream.getMimeType(), contentStream.getStream()); }
@Override public ContentStream getContentStream() { if (objectId == null || getStreamId() == null) { return null; } ContentStream contentStream; try { contentStream = session.getBinding().getObjectService() .getContentStream(session.getRepositoryInfo().getId(), objectId, getStreamId(), null, null, null); } catch (CmisConstraintException e) { // no content stream return null; } if (contentStream == null) { return null; } String filename = contentStream.getFileName(); if (filename == null) { filename = getTitle(); } BigInteger bigLength = contentStream.getBigLength(); if (bigLength == null) { bigLength = getBigLength(); } long length = bigLength == null ? -1 : bigLength.longValue(); return session.getObjectFactory().createContentStream(filename, length, contentStream.getMimeType(), contentStream.getStream()); }
/** * 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(); }