API: cmis
Source:
cms/cmis.ts
API CMIS
- Note: This module is supported only with the Mozilla Rhino engine
- Provides static access to the CMIS (Content Management Interoperability Services) repository session and utility constants.
Usage
import { cmis } from "sdk/cms";
import { response } from "sdk/http";
import { streams } from "sdk/io";
let cmisSession = cmis.getSession();
let rootFolder = cmisSession.getRootFolder();
let children = rootFolder.getChildren();
response.println("Listing the children of the root folder:");
for (let i in children) {
response.println("Object ID: " + children[i].getId());
response.println("Object Name: " + children[i].getName());
}
const textFileName = "test.txt";
response.println("Creating a simple text file, " + textFileName);
const mimetype = "text/plain; charset=UTF-8";
let content = "This is some test content.";
let filename = textFileName;
let outputStream = streams.createByteArrayOutputStream();
outputStream.writeText(content);
let bytes = outputStream.getBytes();
let inputStream = streams.createByteArrayInputStream(bytes);
let contentStream = cmisSession.getObjectFactory().createContentStream(filename, bytes.length, mimetype, inputStream);
let properties = { "cmis:name": "", "cmis:objectTypeId": "" };
properties[cmis.OBJECT_TYPE_ID] = cmis.OBJECT_TYPE_DOCUMENT;
properties[cmis.NAME] = filename;
let newDocument;
try {
newDocument = rootFolder.createDocument(properties, contentStream, cmis.VERSIONING_STATE_MAJOR);
} catch (e) {
response.println("Error: " + e);
}
let documentId = newDocument?.getId();
response.println("Document ID: " + documentId);
children = rootFolder.getChildren();
response.println("Listing the children of the root folder again:");
for (let i in children) {
response.println("Object ID: " + children[i].getId());
response.println("Object Name: " + children[i].getName());
response.println("Object Type: " + JSON.stringify(children[i].getType().getId().toString()));
}
// Get the contents of the file
let doc;
if (documentId !== undefined) {
doc = cmisSession.getObject(documentId);
} else {
response.println("No content");
}
contentStream = doc?.getContentStream(); // returns null if the document has no content
if (contentStream !== null) {
content = contentStream.getStream().readText();
response.println("Contents of " + filename + " are: " + content);
} else {
response.println("No content.");
}
response.println("Deleting the newly created document");
if (newDocument) {
newDocument.delete();
}
response.flush();
response.close();Classes
Cmis
Methods
getSession
getSession ():SessionGets a new CMIS session instance to interact with the repository.
@returns A new {@link Session} instance.
getAccessDefinitions
getAccessDefinitions (path:string, method:string):AccessDefinition[]Retrieves access control definitions for a specific path and method.
@param path The path of the CMIS object.
@param method The operation method (e.g., {@link Cmis.METHOD_READ}, {@link Cmis.METHOD_WRITE}).
@returns A list of access definitions.
Session
Session object
* Represents an active connection to a CMIS repository, used as the main entry point for CMIS operations.
Methods
getRepositoryInfo
getRepositoryInfo ():RepositoryInfoGets information about the repository this session is connected to.
@returns Repository metadata.
getRootFolder
getRootFolder ():FolderGets the root folder of the repository.
@returns The root {@link Folder} object.
getObjectFactory
getObjectFactory ():ObjectFactoryGets the object factory for creating new CMIS objects like ContentStream.
@returns An {@link ObjectFactory} instance.
getObject
getObject (objectId:string):Folder|DocumentRetrieves a CMIS object (Document or Folder) by its unique ID.
@param objectId The unique ID of the object.
@returns A {@link Document} or {@link Folder} instance.
@throws Error if the object type is unsupported.
getObjectByPath
getObjectByPath (path:string):Folder|DocumentRetrieves a CMIS object (Document or Folder) by its path.
@param path The path of the object in the repository (e.g., "/path/to/object").
@returns A {@link Document} or {@link Folder} instance.
@throws Error if read access is not allowed or the object type is unsupported.
createFolder
createFolder (location:string):FolderCreates a folder structure recursively based on a path. This is a convenience method that
creates all non-existent parent folders.
Example:createFolder("/new/path/structure")
@param location The path of the folder to create.
@returns The newly created (or existing) innermost {@link Folder} object.
createDocument
createDocument (location:string, properties:{[key:string]:any}, contentStream:ContentStream, versioningState:string):DocumentCreates a new document at the specified location. This method ensures the parent folder structure exists.
@param location The path of the parent folder (e.g., "/path/to/folder").
@param properties A map of CMIS properties for the new document (must include {@link Cmis.NAME}).
@param contentStream The content stream containing the document's binary data.
@param versioningState The versioning state (e.g., {@link Cmis.VERSIONING_STATE_MAJOR}).
@returns The newly created {@link Document} object.
RepositoryInfo
RepositoryInfo object
* Provides basic information about the connected CMIS repository.
Methods
getId
getId ():stringGets the unique identifier of the repository.
@returns The repository ID.
getName
getName ():stringGets the name of the repository.
@returns The repository name.
Folder
Folder object
* Represents a CMIS folder object, allowing operations like creating children, deleting, and renaming.
Methods
getId
getId ():stringGets the unique identifier of the folder.
@returns The folder ID.
getName
getName ():stringGets the name of the folder.
@returns The folder name.
createFolder
createFolder (properties:{[key:string]:any}):FolderCreates a new folder within this folder.
@param properties A map of CMIS properties for the new folder (must include {@link Cmis.NAME}).
@returns The newly created {@link Folder} object.
@throws Error if write access is not allowed.
createDocument
createDocument (properties:{[key:string]:any}, contentStream:ContentStream, versioningState:string):DocumentCreates a new document within this folder.
@param properties A map of CMIS properties for the new document (must include {@link Cmis.NAME}).
@param contentStream The content stream containing the document's binary data.
@param versioningState The versioning state (e.g., {@link Cmis.VERSIONING_STATE_MAJOR}).
@returns The newly created {@link Document} object.
@throws Error if write access is not allowed.
getChildren
getChildren ():CmisObject[]Retrieves the children of this folder.
@returns A list of generic {@link CmisObject} wrappers for the children.
@throws Error if read access is not allowed.
getPath
getPath ():stringGets the path of the folder.
@returns The folder path.
isRootFolder
isRootFolder ():booleanChecks if this folder is the root folder of the repository.
@returns True if it is the root folder, false otherwise.
getFolderParent
getFolderParent ():FolderGets the parent folder of this folder.
@returns The parent {@link Folder} object.
delete
delete ():voidDeletes this folder (must be empty to succeed).
@throws Error if write access is not allowed.
rename
rename (newName:string):voidRenames this folder.
@param newName The new name for the folder.
@throws Error if write access is not allowed.
deleteTree
deleteTree ():voidDeletes this folder and all its contents recursively.
@throws Error if write access is not allowed.
getType
getType ():TypeDefinitionGets the type definition of the folder.
@returns The folder's {@link TypeDefinition}.
CmisObject
CmisObject object
* A generic wrapper for CMIS objects, used primarily for children lists.
Methods
getId
getId ():stringGets the unique identifier of the object.
@returns The object ID.
getName
getName ():stringGets the name of the object.
@returns The object name.
getPath
getPath ():stringGets the path of the CMIS object. Handles differences in native CMIS implementations.
@returns The object path.
@throws Error if the path cannot be determined.
getType
getType ():TypeDefinitionGets the type definition of the object.
@returns The object's {@link TypeDefinition}.
delete
delete ():voidDeletes the CMIS object.
rename
rename (newName:string):voidRenames the CMIS object.
@param newName The new name for the object.
ObjectFactory
ObjectFactory object
* Provides methods to create content streams.
Methods
createContentStream
createContentStream (filename:string, length:number, mimetype:string, inputStream:streams.InputStream):ContentStreamCreates a new content stream instance that can be used to create or update document content.
@param filename The name of the file.
@param length The size of the content stream in bytes.
@param mimetype The MIME type of the content.
@param inputStream The input stream containing the data.
@returns A new {@link ContentStream} object.
ContentStream
ContentStream object
* Represents the binary content stream of a CMIS Document.
Methods
getStream
getStream ():streams.InputStreamGets the Java-backed input stream for reading the content.
@returns An {@link streams.InputStream} wrapper.
getMimeType
getMimeType ():stringGets the MIME type of the content stream.
@returns The MIME type string.
Document
Document object
* Represents a CMIS document object, allowing operations like reading content, deleting, and renaming.
Methods
getId
getId ():stringGets the unique identifier of the document.
@returns The document ID.
getName
getName ():stringGets the name of the document.
@returns The document name.
getType
getType ():TypeDefinitionGets the type definition of the document.
@returns The document's {@link TypeDefinition}.
getPath
getPath ():stringGets the path of the document.
@returns The document path.
delete
delete ():voidDeletes this document.
@throws Error if write access is not allowed.
getContentStream
getContentStream ():ContentStream|nullGets the binary content stream of the document.
@returns The {@link ContentStream} object, ornullif the document has no content.
getSize
getSize ():numberGets the size of the document's content stream in bytes.
@returns The size in bytes.
rename
rename (newName:string):voidRenames this document.
@param newName The new name for the document.
@throws Error if write access is not allowed.
TypeDefinition
Represents the definition of a CMIS object type (e.g., cmis:document, cmis:folder).
Methods
getId
getId ():stringGets the unique ID of the object type (e.g., 'cmis:document').
@returns The type ID.