001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (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 *     bstefanescu
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.core.rest;
021
022import javax.ws.rs.Path;
023import javax.ws.rs.PathParam;
024
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.api.IdRef;
027import org.nuxeo.ecm.core.api.NuxeoException;
028import org.nuxeo.ecm.webengine.WebException;
029import org.nuxeo.ecm.webengine.model.WebAdapter;
030import org.nuxeo.ecm.webengine.model.impl.DefaultAdapter;
031
032/**
033 * Resolves a document URL given its ID
034 * <p>
035 * Accepts the following methods:
036 * <ul>
037 * <li>GET - get the document index view
038 * </ul>
039 *
040 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
041 */
042@WebAdapter(name = "nxdoc", type = "DocumentResolverService")
043public class DocumentResolverService extends DefaultAdapter {
044
045    @Path("{id}")
046    public DocumentObject doGet(@PathParam("id") String id) {
047        try {
048            DocumentModel doc = ctx.getCoreSession().getDocument(new IdRef(id));
049            return DocumentFactory.newDocument(ctx, doc);
050        } catch (NuxeoException e) {
051            throw WebException.wrap("Failed to get lock on document", e);
052        }
053    }
054
055}