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.ecm.webengine.WebEngine; 027import org.nuxeo.ecm.webengine.model.WebContext; 028import org.nuxeo.theme.html.ui.Panel; 029 030import freemarker.core.Environment; 031import freemarker.template.TemplateDirectiveBody; 032import freemarker.template.TemplateDirectiveModel; 033import freemarker.template.TemplateException; 034import freemarker.template.TemplateModel; 035import freemarker.template.TemplateModelException; 036 037/** 038 * @author <a href="mailto:jmo@chalmers.se">Jean-Marc Orliaguet</a> 039 */ 040public class NXThemesPanelDirective implements TemplateDirectiveModel { 041 042 @SuppressWarnings("unchecked") 043 public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) 044 throws TemplateException, IOException { 045 046 if (loopVars.length != 0) { 047 throw new TemplateModelException("This directive doesn't allow loop variables."); 048 } 049 if (body != null) { 050 throw new TemplateModelException("Didn't expect a body"); 051 } 052 053 Writer writer = env.getOut(); 054 WebContext context = WebEngine.getActiveContext(); 055 056 Map<String, String> attributes = Utils.getTemplateDirectiveParameters(params); 057 String applicationPath = context.getRequest().getParameter("org.nuxeo.theme.application.path"); 058 if (applicationPath == null) { 059 applicationPath = context.getModulePath(); 060 } 061 attributes.put("org.nuxeo.theme.application.path", applicationPath); 062 063 String applicationName = context.getRequest().getParameter("org.nuxeo.theme.application.name"); 064 if (applicationName == null) { 065 applicationName = context.getModule().getName(); 066 } 067 attributes.put("org.nuxeo.theme.application.name", applicationName); 068 069 writer.write(Panel.render(attributes)); 070 } 071}