001/* 002 * (C) Copyright 2006-2011 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 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.core.operations.notification; 020 021import java.net.URL; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.impl.DocumentLocationImpl; 027import org.nuxeo.ecm.platform.ec.notification.NotificationEventListener; 028import org.nuxeo.ecm.platform.ec.notification.service.NotificationService; 029import org.nuxeo.ecm.platform.ec.notification.service.NotificationServiceHelper; 030import org.nuxeo.ecm.platform.url.DocumentViewImpl; 031import org.nuxeo.ecm.platform.url.api.DocumentView; 032import org.nuxeo.ecm.platform.url.api.DocumentViewCodecManager; 033import org.nuxeo.ecm.platform.url.codec.api.DocumentViewCodec; 034import org.nuxeo.runtime.api.Framework; 035 036/** 037 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 038 */ 039public class MailTemplateHelper { 040 041 protected static final Log log = LogFactory.getLog(MailTemplateHelper.class); 042 043 private MailTemplateHelper() { 044 } 045 046 public static String getDocumentUrl(DocumentModel doc, String viewId) { 047 NotificationService notificationService = NotificationServiceHelper.getNotificationService(); 048 DocumentViewCodecManager codecService = Framework.getService(DocumentViewCodecManager.class); 049 DocumentViewCodec codec = codecService.getCodec(NotificationEventListener.NOTIFICATION_DOCUMENT_ID_CODEC_NAME); 050 boolean isNotificationCodec = codec != null; 051 052 String result = ""; 053 if (isNotificationCodec) { 054 DocumentView view; 055 if (viewId == null) { 056 view = new DocumentViewImpl(doc); 057 } else { 058 view = new DocumentViewImpl(new DocumentLocationImpl(doc), viewId); 059 } 060 result = codecService.getUrlFromDocumentView(NotificationEventListener.NOTIFICATION_DOCUMENT_ID_CODEC_NAME, 061 view, true, notificationService.getServerUrlPrefix()); 062 } else { 063 log.warn("No codec was found to notify document url. It is like that no UI is installed."); 064 } 065 return result; 066 } 067 068 public static URL getTemplate(String name) { 069 return NotificationService.getTemplateURL(name); 070 } 071 072}