001/*
002 * (C) Copyright 2016 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 */
019
020package org.nuxeo.ecm.platform.actions.facelets;
021
022import javax.faces.view.facelets.TagConfig;
023
024import org.nuxeo.ecm.platform.forms.layout.api.Widget;
025import org.nuxeo.ecm.platform.forms.layout.facelets.plugins.TemplateWidgetTypeHandler;
026import org.nuxeo.runtime.api.Framework;
027import org.nuxeo.runtime.services.config.ConfigurationService;
028
029/**
030 * Action widget type, allowing definition of a compat template.
031 *
032 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
033 */
034public class ActionWidgetTypeHandler extends TemplateWidgetTypeHandler {
035
036    public static final String COMPAT_TEMPLATE_PROPERTY_NAME = "compat_template";
037
038    public ActionWidgetTypeHandler(TagConfig config) {
039        super(config);
040    }
041
042    @Override
043    protected String getTemplateValue(Widget widget) {
044        ConfigurationService cs = Framework.getService(ConfigurationService.class);
045        boolean useCompat = cs.isBooleanPropertyTrue("nuxeo.jsf.actions.removeActionOptims");
046        if (useCompat) {
047            String compatTemplate = lookupProperty(COMPAT_TEMPLATE_PROPERTY_NAME, widget);
048            if (compatTemplate != null) {
049                return compatTemplate;
050            }
051        }
052        return super.getTemplateValue(widget);
053    }
054
055}