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 Panel { 030 031 public static String render(Map<String, String> params) { 032 StringBuilder sb = new StringBuilder(); 033 034 String identifier = params.get("identifier"); 035 String url = params.get("url"); 036 String loading = params.get("loading"); 037 String stylesheet = params.get("stylesheet"); 038 String javascript = params.get("javascript"); 039 String subviews = params.get("subviews"); 040 String visibleInPerspectives = params.get("visibleInPerspectives"); 041 String controlledBy = params.get("controlledBy"); 042 String filter = params.get("filter"); 043 044 // model 045 Map<String, Object> model = new HashMap<String, Object>(); 046 model.put("id", identifier); 047 Map<String, Object> data = new HashMap<String, Object>(); 048 049 Map<String, Object> form = new HashMap<String, Object>(); 050 if (url != null) { 051 String[] query = url.split("\\?"); 052 if (query.length > 1) { 053 for (String param : query[1].split("&")) { 054 String[] kv = param.split("="); 055 form.put(kv[0], kv[1]); 056 } 057 url = query[0]; 058 } 059 } 060 // add context information 061 form.put("org.nuxeo.theme.application.path", params.get("org.nuxeo.theme.application.path")); 062 form.put("org.nuxeo.theme.application.name", params.get("org.nuxeo.theme.application.name")); 063 064 data.put("form", form); 065 data.put("url", url); 066 067 if (null != loading) { 068 data.put("loading", loading); 069 } 070 if (null != stylesheet) { 071 data.put("css", stylesheet); 072 } 073 if (null != javascript) { 074 data.put("script", javascript); 075 } 076 model.put("data", data); 077 078 // model 079 sb.append(String.format("<ins class=\"model\">%s</ins>", Utils.toJson(model))); 080 081 // view 082 Map<String, Object> view = new HashMap<String, Object>(); 083 view.put("id", identifier); 084 Map<String, Object> widget = new HashMap<String, Object>(); 085 widget.put("type", "panel"); 086 view.put("widget", widget); 087 view.put("model", identifier); 088 if (null != visibleInPerspectives) { 089 view.put("perspectives", visibleInPerspectives.split(",")); 090 } 091 if (null != subviews) { 092 view.put("subviews", subviews.split(",")); 093 } 094 if (null != controlledBy) { 095 view.put("controllers", controlledBy.split(",")); 096 } 097 if (null != filter) { 098 view.put("filter", filter); 099 } 100 101 sb.append(String.format("<ins class=\"view\">%s</ins>", Utils.toJson(view))); 102 return sb.toString(); 103 } 104 105}