001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.facelets.dev; 020 021import java.io.IOException; 022 023import javax.el.ELException; 024import javax.faces.FacesException; 025import javax.faces.component.UIComponent; 026import javax.faces.view.facelets.ComponentHandler; 027import javax.faces.view.facelets.CompositeFaceletHandler; 028import javax.faces.view.facelets.FaceletContext; 029import javax.faces.view.facelets.FaceletException; 030import javax.faces.view.facelets.FaceletHandler; 031import javax.faces.view.facelets.TagAttributes; 032import javax.faces.view.facelets.TagConfig; 033import javax.faces.view.facelets.TagHandler; 034 035import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; 036 037/** 038 * Dev tag container, displaying a div and decorating the dev handler for dev mode rendering, and displaying the 039 * original handler (layout or widget handler) after that. 040 * 041 * @since 6.0 042 */ 043public class DevTagHandler extends TagHandler { 044 045 protected final TagConfig config; 046 047 protected final String refId; 048 049 protected final FaceletHandler originalHandler; 050 051 protected final FaceletHandler devHandler; 052 053 protected static final String PANEL_COMPONENT_TYPE = "org.richfaces.OutputPanel"; 054 055 public DevTagHandler(TagConfig config, String refId, FaceletHandler originalHandler, FaceletHandler devHandler) { 056 super(config); 057 this.refId = refId; 058 this.config = config; 059 this.originalHandler = originalHandler; 060 this.devHandler = devHandler; 061 } 062 063 @Override 064 public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, 065 ELException { 066 FaceletHandlerHelper helper = new FaceletHandlerHelper(config); 067 TagAttributes devAttrs = FaceletHandlerHelper.getTagAttributes( 068 helper.createAttribute("id", FaceletHandlerHelper.generateDevContainerId(ctx, refId)), 069 helper.createAttribute("styleClass", "displayN nxlDevContainer"), 070 helper.createAttribute("layout", "block")); 071 ComponentHandler dComp = helper.getHtmlComponentHandler(config.getTagId(), devAttrs, devHandler, 072 PANEL_COMPONENT_TYPE, null); 073 FaceletHandler nextHandler = new CompositeFaceletHandler(new FaceletHandler[] { 074 helper.getDisableDevModeTagHandler(config.getTagId(), dComp), originalHandler }); 075 TagAttributes cAttrs = FaceletHandlerHelper.getTagAttributes( 076 helper.createAttribute("id", FaceletHandlerHelper.generateDevRegionId(ctx, refId)), 077 helper.createAttribute("styleClass", "nxlDevRegion"), helper.createAttribute("layout", "block")); 078 ComponentHandler cComp = helper.getHtmlComponentHandler(config.getTagId(), cAttrs, nextHandler, 079 PANEL_COMPONENT_TYPE, null); 080 cComp.apply(ctx, parent); 081 } 082 083}