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