Below is a small code for applying a template to a content using web service API
Note – For applying a template, you need to set the template node ref as a template property
I have taken reference of alfresco out of the box document template.
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String rootHome="/app:company_home";
String filename = "test.txt";
String templateID = "workspace://SpacesStore/a4d6ab23-989a-46c6-9c13-3ea2be97d208";
ParentReference contentReference = new ParentReference(storeRef, null, rootHome, Constants.ASSOC_CONTAINS, filename);
contentReference.setChildName("cm:" + filename);
NamedValue[] properties = new NamedValue[]
{
Utils.createNamedValue(Constants.PROP_NAME, filename),
Utils.createNamedValue(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "template"), templateID)
};
create = new CMLCreate("1", contentReference, null, null,null, Constants.TYPE_CONTENT, properties);
cml = new CML();
cml.setCreate(new CMLCreate[] { create }); // Content Created
result = WebServiceFactory.getRepositoryService().update(cml);
1 comment:
Dear Anuj: I have tested your code with a Space Store template and I can not create a new Space based into a Space template. I am using 'Alfrescco3.3' and 'webservice-client2.1.jar'.
Do you know what can be the problem?
Post a Comment