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.nuxeo.ecm.core.api.DocumentLocation; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.impl.DocumentLocationImpl; 026import org.nuxeo.ecm.platform.ec.notification.service.NotificationService; 027import org.nuxeo.ecm.platform.ec.notification.service.NotificationServiceHelper; 028import org.nuxeo.ecm.platform.url.DocumentViewImpl; 029import org.nuxeo.ecm.platform.url.api.DocumentView; 030import org.nuxeo.ecm.platform.url.api.DocumentViewCodecManager; 031import org.nuxeo.runtime.api.Framework; 032 033/** 034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 035 */ 036public class MailTemplateHelper { 037 038 private MailTemplateHelper() { 039 } 040 041 public static String getDocumentUrl(DocumentModel doc, String viewId) { 042 if (viewId == null) { 043 viewId = "view_documents"; 044 } 045 DocumentLocation docLoc = new DocumentLocationImpl(doc); 046 DocumentView docView = new DocumentViewImpl(docLoc); 047 docView.setViewId(viewId); 048 DocumentViewCodecManager codecMgr = Framework.getService(DocumentViewCodecManager.class); 049 NotificationService notifMgr = NotificationServiceHelper.getNotificationService(); 050 if (codecMgr == null) { 051 throw new RuntimeException("Service 'DocumentViewCodecManager' not available"); 052 } 053 if (notifMgr == null) { 054 throw new RuntimeException("Service 'NotificationService' not available"); 055 } 056 return codecMgr.getUrlFromDocumentView(docView, true, notifMgr.getServerUrlPrefix()); 057 } 058 059 public static URL getTemplate(String name) { 060 return NotificationService.getTemplateURL(name); 061 } 062 063}