001package org.nuxeo.template.jaxrs; 002 003import java.util.List; 004 005import javax.servlet.http.HttpServletRequest; 006import javax.ws.rs.GET; 007import javax.ws.rs.Path; 008import javax.ws.rs.Produces; 009import javax.ws.rs.core.Context; 010import javax.ws.rs.core.MediaType; 011 012import org.nuxeo.ecm.core.api.CoreSession; 013import org.nuxeo.runtime.api.Framework; 014import org.nuxeo.template.api.TemplateProcessorService; 015import org.nuxeo.template.api.adapters.TemplateSourceDocument; 016 017/** 018 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 019 */ 020public class ResourceService extends AbstractResourceService { 021 022 public ResourceService(CoreSession session) { 023 super(session); 024 } 025 026 @GET 027 @Path("name") 028 @Produces(MediaType.TEXT_PLAIN) 029 public String getName() { 030 return super.getName(); 031 } 032 033 @Context 034 protected HttpServletRequest request; 035 036 public String getRoot() { 037 CoreSession session = getCoreSession(); 038 TemplateProcessorService tps = Framework.getLocalService(TemplateProcessorService.class); 039 List<TemplateSourceDocument> templates = tps.getAvailableTemplates(session, null); 040 StringBuffer sb = new StringBuffer(); 041 042 sb.append("["); 043 for (TemplateSourceDocument t : templates) { 044 sb.append("{"); 045 sb.append("\"label\":" + "\"" + t.getLabel() + "\","); 046 sb.append("\"name\":" + "\"" + t.getName() + "\","); 047 sb.append("\"id\":" + "\"" + t.getId() + "\""); 048 sb.append("},"); 049 } 050 051 String result = sb.toString(); 052 result = result.substring(0, result.length() - 2) + "]"; 053 054 return result; 055 } 056}