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