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 * Alexandre Russel 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.mail.action; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.platform.url.DocumentViewImpl; 026import org.nuxeo.ecm.platform.url.api.DocumentView; 027import org.nuxeo.ecm.platform.url.api.DocumentViewCodecManager; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * Computes the URL of a document. 032 * <p> 033 * It expects the document to be in the context under the key "document" and the baseUrl at baseUrl. It puts the URL at 034 * key "url". 035 * 036 * @author Alexandre Russel 037 */ 038public class DocumentURLAction implements MessageAction { 039 040 private static final Log log = LogFactory.getLog(DocumentURLAction.class); 041 042 protected DocumentViewCodecManager documentViewCodecManager; 043 044 protected final String baseUrl; 045 046 public DocumentURLAction(String baseUrl) { 047 this.baseUrl = baseUrl; 048 } 049 050 public boolean execute(ExecutionContext context) { 051 DocumentModel documentModel = (DocumentModel) context.get("document"); 052 if (log.isDebugEnabled()) { 053 log.debug("Document url computing for doc: " + documentModel); 054 } 055 documentViewCodecManager = Framework.getService(DocumentViewCodecManager.class); 056 DocumentView docView = new DocumentViewImpl(documentModel); 057 String url = documentViewCodecManager.getUrlFromDocumentView(docView, true, baseUrl); 058 context.put("url", url); 059 return true; 060 } 061 062 public void reset(ExecutionContext context) { 063 // do nothing 064 } 065 066}