001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.platform.forms.layout.export; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.QueryParam; 024import javax.ws.rs.core.Context; 025import javax.ws.rs.core.UriInfo; 026 027import org.apache.commons.lang3.StringUtils; 028import org.nuxeo.ecm.platform.forms.layout.api.service.LayoutStore; 029import org.nuxeo.ecm.webengine.model.view.TemplateView; 030import org.nuxeo.runtime.api.Framework; 031 032@Path("layout-manager") 033public class RootResource { 034 035 protected TemplateView getTemplate(String name, UriInfo uriInfo) { 036 String baseURL = uriInfo.getAbsolutePath().toString(); 037 if (!baseURL.endsWith("/")) { 038 baseURL += "/"; 039 } 040 return new TemplateView(this, name).arg("baseURL", baseURL); 041 } 042 043 @GET 044 public Object doGet(@Context UriInfo uriInfo) { 045 LayoutStore service = Framework.getService(LayoutStore.class); 046 // XXX: use hard coded "jsf" category for now 047 int nbWidgetTypes = service.getWidgetTypeDefinitions("jsf").size(); 048 int nbLayoutTypes = service.getLayoutTypeDefinitions("jsf").size(); 049 int nbLayouts = service.getLayoutDefinitionNames("jsf").size(); 050 return getTemplate("index.ftl", uriInfo).arg("nbWidgetTypes", Integer.valueOf(nbWidgetTypes)).arg("nbLayouts", 051 Integer.valueOf(nbLayouts)).arg("nbLayoutTypes", Integer.valueOf(nbLayoutTypes)); 052 } 053 054 @Path("layouts") 055 public Object getLayouts() { 056 // XXX: use hard coded "jsf" category for now 057 return new LayoutResource("jsf"); 058 } 059 060 @Path("widget-types") 061 public Object getWidgetTypes(@QueryParam("widgetTypeCategory") String widgetTypeCategory) { 062 if (StringUtils.isBlank(widgetTypeCategory)) { 063 widgetTypeCategory = "jsf"; 064 } 065 return new WidgetTypeResource(widgetTypeCategory); 066 } 067 068 @Path("layout-types") 069 public Object getLayoutTypes(@QueryParam("layoutTypeCategory") String layoutTypeCategory) { 070 if (StringUtils.isBlank(layoutTypeCategory)) { 071 layoutTypeCategory = "jsf"; 072 } 073 return new LayoutTypeResource(layoutTypeCategory); 074 } 075 076}