001/*
002 * (C) Copyright 2006-2007 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: SecretWidgetTypeHandler.java 30416 2008-02-21 19:10:37Z atchertchian $
018 */
019
020package org.nuxeo.ecm.platform.forms.layout.facelets.plugins;
021
022import javax.faces.component.html.HtmlInputSecret;
023import javax.faces.view.facelets.ComponentHandler;
024import javax.faces.view.facelets.CompositeFaceletHandler;
025import javax.faces.view.facelets.FaceletContext;
026import javax.faces.view.facelets.FaceletHandler;
027import javax.faces.view.facelets.TagAttributes;
028import javax.faces.view.facelets.TagConfig;
029
030import org.nuxeo.ecm.platform.forms.layout.api.BuiltinWidgetModes;
031import org.nuxeo.ecm.platform.forms.layout.api.Widget;
032import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException;
033import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper;
034
035/**
036 * Secret widget
037 *
038 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
039 */
040public class SecretWidgetTypeHandler extends AbstractWidgetTypeHandler {
041
042    private static final long serialVersionUID = 1495841177711755669L;
043
044    @Override
045    public FaceletHandler getFaceletHandler(FaceletContext ctx, TagConfig tagConfig, Widget widget,
046            FaceletHandler[] subHandlers) throws WidgetException {
047        FaceletHandlerHelper helper = new FaceletHandlerHelper(ctx, tagConfig);
048        String mode = widget.getMode();
049        String widgetId = widget.getId();
050        String widgetName = widget.getName();
051        String widgetTagConfigId = widget.getTagConfigId();
052        TagAttributes attributes = helper.getTagAttributes(widgetId, widget);
053        FaceletHandler leaf = getNextHandler(ctx, tagConfig, widget, subHandlers, helper);
054        if (BuiltinWidgetModes.EDIT.equals(mode)) {
055            ComponentHandler input = helper.getHtmlComponentHandler(widgetTagConfigId, attributes, leaf,
056                    HtmlInputSecret.COMPONENT_TYPE, null);
057            String msgId = helper.generateMessageId(widgetName);
058            ComponentHandler message = helper.getMessageComponentHandler(widgetTagConfigId, msgId, widgetId, null);
059            FaceletHandler[] handlers = { input, message };
060            return new CompositeFaceletHandler(handlers);
061        }
062        // do not render anything for other modes
063        return leaf;
064    }
065}