001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bjalon 016 */ 017package org.nuxeo.ecm.mobile.webengine.adapter; 018 019import javax.ws.rs.GET; 020import javax.ws.rs.Path; 021import javax.ws.rs.Produces; 022import javax.ws.rs.QueryParam; 023 024import org.nuxeo.ecm.webengine.WebException; 025import org.nuxeo.ecm.webengine.model.WebAdapter; 026 027/** 028 * Adapter that expose a document according the DForm Jquery Framework structure. 029 * 030 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 031 * @since 5.5 032 */ 033@WebAdapter(name = "jsonExport", type = "JSONExport", targetType = "MobileDocument") 034@Produces("application/json;charset=UTF-8") 035public class JSonExportAdapter extends DefaultMobileAdapter { 036 037 /** 038 * Return the JSON export of document for dform layout manager 039 * 040 * @param action 041 * @param actionType 042 * @return 043 */ 044 @GET 045 @Path("dform") 046 public Object doGet(@QueryParam("action") String action, @QueryParam("actionType") String actionType) { 047 048 if (action == null && ctx == null) { 049 throw new WebException("No action given into parameters and no " 050 + "context found, can't generate json document export"); 051 } 052 053 if (action == null) { 054 action = ctx.getRequest().getRequestURI(); 055 } 056 057 if (actionType == null) { 058 actionType = "post"; 059 } 060 061 return getView("index").render(); 062 } 063 064}