001/* 002 * (C) Copyright 2012 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 * bjalon 018 */ 019package org.nuxeo.ecm.mobile.webengine.adapter; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.POST; 023import javax.ws.rs.QueryParam; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.api.DocumentModel; 029import org.nuxeo.ecm.core.api.NuxeoException; 030import org.nuxeo.ecm.webengine.WebException; 031import org.nuxeo.ecm.webengine.model.WebAdapter; 032 033/** 034 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 035 * @since 5.5 036 */ 037@WebAdapter(name = "newDocument", type = "NewDocument", targetType = "MobileDocument") 038public class NewDocumentAdapter extends DefaultMobileAdapter { 039 040 private static final Log log = LogFactory.getLog(NewDocumentAdapter.class); 041 042 @GET 043 public Object doGet(@QueryParam("type") String docType) { 044 CoreSession session = ctx.getCoreSession(); 045 046 DocumentModel doc; 047 try { 048 doc = session.createDocumentModel(docType); 049 } catch (NuxeoException e) { 050 log.error(e, e); 051 throw new WebException(e.getMessage()); 052 } 053 return getView("index").arg("doc", doc); 054 } 055 056 @POST 057 public Object doPost() { 058 return getView("index"); 059 } 060 061}