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 *     narcis
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.ec.notification.email;
021
022import java.io.StringWriter;
023import java.io.Writer;
024
025import org.nuxeo.ecm.platform.rendering.RenderingContext;
026import org.nuxeo.ecm.platform.rendering.RenderingResult;
027import org.nuxeo.ecm.platform.rendering.impl.DefaultRenderingResult;
028import org.nuxeo.ecm.platform.rendering.template.DocumentRenderingEngine;
029import org.nuxeo.ecm.platform.rendering.template.FreemarkerRenderingJob;
030import freemarker.template.Configuration;
031
032/**
033 * @author <a href="mailto:npaslaru@nuxeo.com">Narcis Paslaru</a>
034 */
035public class NotificationsRenderingEngine extends DocumentRenderingEngine {
036
037    private final String template;
038
039    public NotificationsRenderingEngine(String template) {
040        this.template = template;
041    }
042
043    @Override
044    public Configuration createConfiguration() {
045        Configuration cfg = super.createConfiguration();
046        cfg.setSharedVariable("htmlEscape", new HtmlEscapeMethod());
047        return cfg;
048    }
049
050    @Override
051    protected FreemarkerRenderingJob createJob(RenderingContext ctx) {
052        return new NotifsRenderingJob("ftl");
053    }
054
055    public String getFormatName() {
056        // TODO Auto-generated method stub
057        return null;
058    }
059
060    class NotifsRenderingJob extends DefaultRenderingResult implements FreemarkerRenderingJob {
061
062        private static final long serialVersionUID = -7133062841713259967L;
063
064        final Writer strWriter = new StringWriter();
065
066        NotifsRenderingJob(String formatName) {
067            super(formatName);
068        }
069
070        @Override
071        public Object getOutcome() {
072            return strWriter.toString();
073        }
074
075        public RenderingResult getResult() {
076            return this;
077        }
078
079        public String getTemplate() {
080            return template;
081        }
082
083        public Writer getWriter() {
084            return strWriter;
085        }
086    }
087
088}