Working with document content
To work with the content of documents, you can use the ECMContentStream data type to wrap a content stream and return information about the stream. A content stream is a stream of data that contains the content of a document, such as a word processing document or an image.
The ECMContentStream data type is used in the following four
Enterprise Content Management (ECM) operations:
- Check in document
- Create document
- Get document content
- Set document content
Information about these operations is found in the topic Data mapping in Enterprise Content Management operations.
The properties for the ECMContentStream data type are described in the following table:
| Property name | Description |
|---|---|
| contentLength | The length of the original (non-encoded) content length in bytes. If the property is set, the length must be a positive number. If the length is unknown, the property must not be set. |
| mimeType | The MIME media type of the content stream. For the primary content of a document, the MIME media type should match the value of the property cmis:contentStreamMimeType. For example, application/pdf. |
| fileName | The file name of the content stream. For the primary content of a document, the file name should match the value of the property cmis:contentStreamFileName. |
| content | The value of the document. It must be of type String Base64 and encoded in UTF-8. |
The following example code fragments can be used in a script
activity to get and set values:
// Script sample code to set and encode the document content
var value = "abc";
var bytesValue = new Packages.java.lang.String(value).getBytes("UTF-8");
var content64 = Packages.org.apache.commons.codec.binary.Base64.encodeBase64(bytesValue);
tw.local.contentStream = new tw.object.ECMContentStream();
tw.local.contentStream.contentLength = value.length;
tw.local.contentStream.mimeType = "text/plain";
tw.local.contentStream.content = new Packages.java.lang.String(content64, "UTF-8");
// Script sample code to get and decode the document content
var byteValue = Packages.java.lang.String(tw.local.contentStream.content).getBytes();
var content64 = Packages.org.apache.commons.codec.binary.Base64.decodeBase64(byteValue);
var value = new java.lang.String(content64, "UTF-8");