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 * dragos 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.rendering.impl; 021 022import org.nuxeo.ecm.core.api.DocumentModel; 023 024/** 025 * Abstract RenderingContext subclass that adds capabilities of storing a DocumentModel and retrieve RenderingConfig 026 * associated with the current set DocumentModel. 027 * 028 * @author <a href="mailto:dm@nuxeo.com">Dragos Mihalache</a> 029 */ 030public class DocumentRenderingContext extends DefaultRenderingContext { 031 032 private static final long serialVersionUID = 1626664478541223492L; 033 034 public static final String CTX_PARAM_DOCUMENT = "doc"; 035 036 @Override 037 public <T> T getAdapter(Class<T> adapter) { 038 if (adapter.isAssignableFrom(getClass())) { 039 return adapter.cast(this); 040 } else if (adapter.isAssignableFrom(DocumentModel.class)) { 041 return adapter.cast(getDocument()); 042 } 043 return null; 044 } 045 046 public void setDocument(DocumentModel doc) { 047 put(CTX_PARAM_DOCUMENT, doc); 048 } 049 050 public DocumentModel getDocument() { 051 return (DocumentModel) get(CTX_PARAM_DOCUMENT); 052 } 053 054}