Monday 29 April 2019

CMIS: CmisExtensionElement: Create cmis extensions


openCMIS provides CmisExtensionElement interface to define cmis extensions. CmisExtensionElementImpl class implements CmisExtensionElement interface.

CmisExtensionElementImpl class provide below constructors to define objects of CmisExtensionElement.

public CmisExtensionElementImpl(String namespace, String name, Map<String, String> attributes, String value)
public CmisExtensionElementImpl(String namespace, String name, Map<String, String> attributes,List<CmisExtensionElement> children)
public CmisExtensionElementImpl(CmisExtensionElement element)

Every cmis extension element has a name and optional attributes associated with it. Browser binding do not support name space and attributes of cmis extension (Since json do not have attributes and namespace concept).

A cmis extension element can have either children cmis extension elements (or) a value associated with it.

ExtensionDemo.java
package cmis_client.cmis_client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;

public class ExtensionDemo {

	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(space + name + " : " + value);

			} else {
				System.out.println(space + extension.getName());
				printExtensions(extensionChildren, space + " ");
			}
		}
	}

	public static void main(String args[]) {
		CmisExtensionElement leafExtension1 = new CmisExtensionElementImpl("", "confidentialLevel", null,
				"confidential");
		CmisExtensionElement leafExtension2 = new CmisExtensionElementImpl("", "rootFolderId", null, "folder_1234");
		CmisExtensionElement leafExtension3 = new CmisExtensionElementImpl("", "classification", null, "public");

		List<CmisExtensionElement> list = new ArrayList<>();
		list.add(leafExtension1);
		list.add(leafExtension2);
		list.add(leafExtension3);

		CmisExtensionElement parentExtension = new CmisExtensionElementImpl("", "parentExtension", null, list);

		List<CmisExtensionElement> extensions = Collections.singletonList(parentExtension);

		printExtensions(extensions, " ");
	}
}

Output
parentExtension
  confidentialLevel : confidential
  rootFolderId : folder_1234

  classification : public




Previous                                                 Next                                                 Home

No comments:

Post a Comment