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