001/*
002 * (C) Copyright 2006-2009 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 *     Jean-Marc Orliaguet, Chalmers
016 *
017 * $Id$
018 */
019
020package org.nuxeo.theme.webengine.fm.extensions;
021
022import java.io.IOException;
023import java.io.Writer;
024import java.util.Map;
025
026import org.nuxeo.theme.html.ui.Button;
027
028import freemarker.core.Environment;
029import freemarker.template.TemplateDirectiveBody;
030import freemarker.template.TemplateDirectiveModel;
031import freemarker.template.TemplateException;
032import freemarker.template.TemplateModel;
033import freemarker.template.TemplateModelException;
034
035/**
036 * @author <a href="mailto:jmo@chalmers.se">Jean-Marc Orliaguet</a>
037 */
038public class NXThemesButtonDirective implements TemplateDirectiveModel {
039
040    @SuppressWarnings("unchecked")
041    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
042            throws TemplateException, IOException {
043
044        if (loopVars.length != 0) {
045            throw new TemplateModelException("This directive doesn't allow loop variables.");
046        }
047        if (body != null) {
048            throw new TemplateModelException("Didn't expect a body");
049        }
050
051        Writer writer = env.getOut();
052        writer.write(Button.render(Utils.getTemplateDirectiveParameters(params)));
053    }
054}