Search This Blog

About Me

Highly experienced in implementation and customization of Alfresco. More than 11 years of experience working on Alfresco, versions ranging from 2.x to 5.x. Successfully processed innovative and tailored CMS solutions to meet ever-changing business requirements for multiple clients. Role Includes : Experience in Alfresco Upgrades, SOLR migration, Proposals, Team Handling, Delivery, Content Migration, POC's etc.. Extensive experience in client co ordination, working on offshore-onshore model and project take over. Technical Expertise Includes : Java, JSP, Servlet, JSF, JavaScript, AJAX, Spring, SQL, Hibernate, Web Services(REST). Specialities Includes : Content Migration, Product Customization, Business CMS Solutions, Workflow, Project Transition.

Wednesday, June 30, 2010

Code to apply Template using Alfresco Web Service Client


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);