import{cmis}from"sdk/cms";import{response}from"sdk/http";import{streams}from"sdk/io";letcmisSession=cmis.getSession();letrootFolder=cmisSession.getRootFolder();letchildren=rootFolder.getChildren();response.println("Listing the children of the root folder:");for(letiinchildren){response.println("Object ID: "+children[i].getId());response.println("Object Name: "+children[i].getName());}consttextFileName="test.txt";response.println("Creating a simple text file, "+textFileName);constmimetype="text/plain; charset=UTF-8";letcontent="This is some test content.";letfilename=textFileName;letoutputStream=streams.createByteArrayOutputStream();outputStream.writeText(content);letbytes=outputStream.getBytes();letinputStream=streams.createByteArrayInputStream(bytes);letcontentStream=cmisSession.getObjectFactory().createContentStream(filename,bytes.length,mimetype,inputStream);letproperties={"cmis:name":"","cmis:objectTypeId":""};properties[cmis.OBJECT_TYPE_ID]=cmis.OBJECT_TYPE_DOCUMENT;properties[cmis.NAME]=filename;letnewDocument;try{newDocument=rootFolder.createDocument(properties,contentStream,cmis.VERSIONING_STATE_MAJOR);}catch(e){response.println("Error: "+e);}letdocumentId=newDocument?.getId();response.println("Document ID: "+documentId);children=rootFolder.getChildren();response.println("Listing the children of the root folder again:");for(letiinchildren){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 fileletdoc;if(documentId!==undefined){doc=cmisSession.getObject(documentId);}else{response.println("No content");}contentStream=doc?.getContentStream();// returns null if the document has no contentif(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();
Functions
Function
Description
Returns
getSession()
Returns the CMIS connection session to the CMS system
Session
getAccessDefinitions(path, method)
Returns array of CMIS access constraints for the specified path and method
array of objects
Objects
Session
Function
Description
Returns
getRepositoryInfo()
Returns the information about the CMIS repository
RepositoryInfo
getObjectFactory()
Returns the ObjectFactory utility
ObjectFactory
getRootFolder()
Returns the root folder of this repository
Folder
getObject()
Returns a CMIS Object by name
CmisObject
getObjectByPath()
Returns a CMIS Object by path
CmisObject
RepositoryInfo
Function
Description
Returns
getId()
Returns the ID of the CMIS repository
string
getName()
Returns the Name of the CMIS repository
string
ObjectFactory
Function
Description
Returns
createContentStream()
Returns a newly created ContentStream object
ContentStream
ContentStream
Function
Description
Returns
getStream()
Returns the InputStream of this ContentStream object