001/*
002 * (C) Copyright 2006-2007 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 *     Jean-Marc Orliaguet, Chalmers
018 *
019 * $Id$
020 */
021
022package org.nuxeo.theme.html.ui;
023
024import java.util.HashMap;
025import java.util.Map;
026
027import org.nuxeo.theme.html.Utils;
028
029public class Button {
030
031    public static String render(Map<String, String> params) {
032        StringBuilder sb = new StringBuilder();
033
034        String identifier = params.get("identifier");
035        String controlledBy = params.get("controlledBy");
036        String switchTo = params.get("switchTo");
037        String link = params.get("link");
038        String menu = params.get("menu");
039        String label = params.get("label");
040        String classNames = params.get("classNames");
041        String icon = params.get("icon");
042
043        // view
044        Map<String, Object> view = new HashMap<String, Object>();
045        view.put("id", identifier);
046        Map<String, Object> widget = new HashMap<String, Object>();
047        widget.put("type", "button");
048        view.put("widget", widget);
049        if (null != switchTo) {
050            String[] p = switchTo.split("/");
051            if (p.length > 1) {
052                view.put("perspectiveController", p[0]);
053                view.put("toPerspective", p[1]);
054            }
055        }
056        if (null != controlledBy) {
057            view.put("controllers", controlledBy.split(","));
058        }
059        if (null != link) {
060            view.put("link", link);
061        }
062        if (null != menu) {
063            view.put("menu", menu);
064        }
065        if (null != classNames) {
066            view.put("classNames", classNames);
067        }
068        if (null != icon) {
069            view.put("icon", icon);
070        }
071        view.put("label", label);
072
073        sb.append(String.format("<ins class=\"view\">%s</ins>", Utils.toJson(view)));
074        return sb.toString();
075    }
076
077}