001/* 002 * (C) Copyright 2013 Nuxeo SA (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-2.1.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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.forms.layout.facelets.dev; 018 019import java.io.IOException; 020 021import javax.el.ELException; 022import javax.faces.FacesException; 023import javax.faces.component.UIComponent; 024import javax.faces.view.facelets.FaceletContext; 025import javax.faces.view.facelets.FaceletException; 026import javax.faces.view.facelets.TagAttribute; 027import javax.faces.view.facelets.TagAttributes; 028import javax.faces.view.facelets.TagConfig; 029import javax.faces.view.facelets.TagHandler; 030 031import org.nuxeo.ecm.platform.forms.layout.api.BuiltinModes; 032import org.nuxeo.ecm.platform.forms.layout.api.Layout; 033import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; 034import org.nuxeo.ecm.platform.ui.web.tag.handler.TagConfigFactory; 035 036import com.sun.faces.facelets.tag.ui.DecorateHandler; 037 038/** 039 * Dev tag handler for layouts, retrieving the template on the layout definition (or its type definition) using the 040 * template defined in mode {@link BuiltinModes#DEV}. 041 * <p> 042 * When no template is defined, this handler is skipped. 043 * 044 * @since 6.0 045 */ 046public class LayoutDevTagHandler extends TagHandler { 047 048 protected final TagConfig config; 049 050 protected final TagAttribute layout; 051 052 public LayoutDevTagHandler(TagConfig config) { 053 super(config); 054 this.config = config; 055 this.layout = getRequiredAttribute("layout"); 056 } 057 058 @Override 059 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, 060 ELException { 061 Layout layoutInstance = (Layout) layout.getObject(ctx, Layout.class); 062 FaceletHandlerHelper helper = new FaceletHandlerHelper(ctx, config); 063 TagAttribute templateAttr = helper.createAttribute("template", layoutInstance.getDevTemplate()); 064 TagAttributes attributes = FaceletHandlerHelper.getTagAttributes(templateAttr); 065 String widgetTagConfigId = layoutInstance.getTagConfigId(); 066 TagConfig config = TagConfigFactory.createTagConfig(this.config, widgetTagConfigId, attributes, nextHandler); 067 DecorateHandler includeHandler = new DecorateHandler(config); 068 includeHandler.apply(ctx, parent); 069 } 070 071}