001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     bstefanescu
011 */
012package org.nuxeo.ecm.automation.core.operations.notification;
013
014import java.net.URL;
015
016import org.nuxeo.ecm.core.api.DocumentLocation;
017import org.nuxeo.ecm.core.api.DocumentModel;
018import org.nuxeo.ecm.core.api.impl.DocumentLocationImpl;
019import org.nuxeo.ecm.platform.ec.notification.service.NotificationService;
020import org.nuxeo.ecm.platform.ec.notification.service.NotificationServiceHelper;
021import org.nuxeo.ecm.platform.url.DocumentViewImpl;
022import org.nuxeo.ecm.platform.url.api.DocumentView;
023import org.nuxeo.ecm.platform.url.api.DocumentViewCodecManager;
024import org.nuxeo.runtime.api.Framework;
025
026/**
027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
028 */
029public class MailTemplateHelper {
030
031    private MailTemplateHelper() {
032    }
033
034    public static String getDocumentUrl(DocumentModel doc, String viewId) {
035        if (viewId == null) {
036            viewId = "view_documents";
037        }
038        DocumentLocation docLoc = new DocumentLocationImpl(doc);
039        DocumentView docView = new DocumentViewImpl(docLoc);
040        docView.setViewId(viewId);
041        DocumentViewCodecManager codecMgr = Framework.getService(DocumentViewCodecManager.class);
042        NotificationService notifMgr = NotificationServiceHelper.getNotificationService();
043        if (codecMgr == null) {
044            throw new RuntimeException("Service 'DocumentViewCodecManager' not available");
045        }
046        if (notifMgr == null) {
047            throw new RuntimeException("Service 'NotificationService' not available");
048        }
049        return codecMgr.getUrlFromDocumentView(docView, true, notifMgr.getServerUrlPrefix());
050    }
051
052    public static URL getTemplate(String name) {
053        return NotificationService.getTemplateURL(name);
054    }
055
056}