001/* 002 * (C) Copyright 2006-2008 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 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.theme.migration.tag.handler; 021 022import java.io.IOException; 023 024import javax.faces.component.UIComponent; 025import javax.faces.view.facelets.FaceletContext; 026import javax.faces.view.facelets.TagAttribute; 027import javax.faces.view.facelets.TagConfig; 028 029import org.nuxeo.ecm.platform.ui.web.tag.handler.TagConfigFactory; 030import org.nuxeo.runtime.api.Framework; 031import org.nuxeo.runtime.logging.DeprecationLogger; 032import org.nuxeo.theme.styling.service.ThemeStylingService; 033 034import com.sun.faces.facelets.tag.TagAttributeImpl; 035import com.sun.faces.facelets.tag.TagAttributesImpl; 036import com.sun.faces.facelets.tag.TagHandlerImpl; 037import com.sun.faces.facelets.tag.ui.CompositionHandler; 038 039/** 040 * Theme composition migration handler. 041 * <p> 042 * Includes the new page template for compat and issues a warning in dev mode. 043 * 044 * @author Anahide Tchertchian 045 */ 046public class ThemeMigrationCompositionHandler extends TagHandlerImpl { 047 048 protected static final String NEG_PROP = "jsfThemeCompatTemplate"; 049 050 protected static final String TEMPLATE = "/pages/workspace_page.xhtml"; 051 052 protected final TagConfig config; 053 054 public ThemeMigrationCompositionHandler(TagConfig config) { 055 super(config); 056 this.config = config; 057 } 058 059 @Override 060 public void apply(FaceletContext ctx, UIComponent parent) throws IOException { 061 String template = TEMPLATE; 062 ThemeStylingService s = Framework.getService(ThemeStylingService.class); 063 if (s != null) { 064 template = s.negotiate(NEG_PROP, ctx.getFacesContext()); 065 } 066 DeprecationLogger.log(String.format( 067 "Tag nxthemes:composition is deprecated, will use a composition of template at %s for %s", template, 068 tag.getLocation()), "7.4"); 069 TagAttributeImpl tAttr = getTagAttribute("template", template); 070 TagAttributesImpl attributes = new TagAttributesImpl(new TagAttribute[] { tAttr }); 071 TagConfig cconfig = TagConfigFactory.createTagConfig(config, tagId, attributes, nextHandler); 072 new CompositionHandler(cconfig).apply(ctx, parent); 073 } 074 075 protected TagAttributeImpl getTagAttribute(String name, String value) { 076 return new TagAttributeImpl(tag.getLocation(), "", name, name, value); 077 } 078 079}