Below statements are used to get the extensions
associated with cmis object.
Ex
CmisObject cmisObject =
session.getObject("134");
List<CmisExtensionElement> extensions =
cmisObject.getExtensions(ExtensionLevel.OBJECT);
Find below working application.
Test.java
package cmis_client.cmis_client; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.chemistry.opencmis.client.api.Session; import org.apache.chemistry.opencmis.client.api.SessionFactory; import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl; import org.apache.chemistry.opencmis.commons.SessionParameter; import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement; import org.apache.chemistry.opencmis.commons.enums.BindingType; import org.apache.chemistry.opencmis.commons.enums.ExtensionLevel; public class Test { private static String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser"; private static String repositoryId = "A1"; public static Session getSession() { Map<String, String> parameters = new HashMap<>(); parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value()); parameters.put(SessionParameter.USER, ""); parameters.put(SessionParameter.PASSWORD, ""); parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); parameters.put(SessionParameter.BROWSER_URL, serverURL); SessionFactory sessionFactory = SessionFactoryImpl.newInstance(); return sessionFactory.createSession(parameters); } private static void printExtensions(List<CmisExtensionElement> extensions, String space) { for (CmisExtensionElement extension : extensions) { List<CmisExtensionElement> extensionChildren = extension.getChildren(); if (extensionChildren == null || extensionChildren.isEmpty()) { String name = extension.getName(); String value = extension.getValue(); System.out.println(name + " : " + value); } else { printExtensions(extensionChildren, space + " "); } } } public static void main(String args[]) { Session session = getSession(); CmisObject cmisObject = session.getObject("134"); List<CmisExtensionElement> extensions = cmisObject.getExtensions(ExtensionLevel.OBJECT); if (extensions == null) { System.out.println("Document do not have extensions"); return; } printExtensions(extensions, " "); } }
Output
objectId : 134
name : My_Document-0-1
No comments:
Post a Comment