001/* 002 * (C) Copyright 2006-2007 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 * Nuxeo - initial API and implementation 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.restAPI; 021 022import java.io.Serializable; 023 024import static org.jboss.seam.ScopeType.EVENT; 025 026import org.jboss.seam.annotations.In; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.nuxeo.ecm.core.api.CoreSession; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.core.api.IdRef; 032import org.nuxeo.ecm.core.api.NuxeoException; 033import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 034import org.nuxeo.ecm.platform.util.RepositoryLocation; 035import org.restlet.Restlet; 036import org.restlet.data.MediaType; 037import org.restlet.data.Request; 038import org.restlet.data.Response; 039 040/** 041 * Sample code for a Seam-aware restlet. 042 * 043 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 044 */ 045@Name("testSeamRestlet") 046@Scope(EVENT) 047public class SimpleRestletWithSeam extends Restlet implements Serializable { 048 049 private static final long serialVersionUID = -5264946092445282305L; 050 051 @In(create = true) 052 transient NavigationContext navigationContext; 053 054 CoreSession documentManager; 055 056 @Override 057 public void handle(Request req, Response res) { 058 String repo = (String) req.getAttributes().get("repo"); 059 String docid = (String) req.getAttributes().get("docid"); 060 061 try { 062 navigationContext.setCurrentServerLocation(new RepositoryLocation(repo)); 063 documentManager = navigationContext.getOrCreateDocumentManager(); 064 DocumentModel dm = documentManager.getDocument(new IdRef(docid)); 065 String title = (String) dm.getProperty("dublincore", "title"); 066 res.setEntity("doc =>" + title, MediaType.TEXT_PLAIN); 067 } catch (NuxeoException e) { 068 res.setEntity(e.getMessage(), MediaType.TEXT_PLAIN); 069 } 070 } 071 072}