001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.html.ui; 016 017import java.util.HashMap; 018import java.util.Map; 019 020import org.nuxeo.theme.html.Utils; 021 022public class Panel { 023 024 public static String render(Map<String, String> params) { 025 StringBuilder sb = new StringBuilder(); 026 027 String identifier = params.get("identifier"); 028 String url = params.get("url"); 029 String loading = params.get("loading"); 030 String stylesheet = params.get("stylesheet"); 031 String javascript = params.get("javascript"); 032 String subviews = params.get("subviews"); 033 String visibleInPerspectives = params.get("visibleInPerspectives"); 034 String controlledBy = params.get("controlledBy"); 035 String filter = params.get("filter"); 036 037 // model 038 Map<String, Object> model = new HashMap<String, Object>(); 039 model.put("id", identifier); 040 Map<String, Object> data = new HashMap<String, Object>(); 041 042 Map<String, Object> form = new HashMap<String, Object>(); 043 if (url != null) { 044 String[] query = url.split("\\?"); 045 if (query.length > 1) { 046 for (String param : query[1].split("&")) { 047 String[] kv = param.split("="); 048 form.put(kv[0], kv[1]); 049 } 050 url = query[0]; 051 } 052 } 053 // add context information 054 form.put("org.nuxeo.theme.application.path", params.get("org.nuxeo.theme.application.path")); 055 form.put("org.nuxeo.theme.application.name", params.get("org.nuxeo.theme.application.name")); 056 057 data.put("form", form); 058 data.put("url", url); 059 060 if (null != loading) { 061 data.put("loading", loading); 062 } 063 if (null != stylesheet) { 064 data.put("css", stylesheet); 065 } 066 if (null != javascript) { 067 data.put("script", javascript); 068 } 069 model.put("data", data); 070 071 // model 072 sb.append(String.format("<ins class=\"model\">%s</ins>", Utils.toJson(model))); 073 074 // view 075 Map<String, Object> view = new HashMap<String, Object>(); 076 view.put("id", identifier); 077 Map<String, Object> widget = new HashMap<String, Object>(); 078 widget.put("type", "panel"); 079 view.put("widget", widget); 080 view.put("model", identifier); 081 if (null != visibleInPerspectives) { 082 view.put("perspectives", visibleInPerspectives.split(",")); 083 } 084 if (null != subviews) { 085 view.put("subviews", subviews.split(",")); 086 } 087 if (null != controlledBy) { 088 view.put("controllers", controlledBy.split(",")); 089 } 090 if (null != filter) { 091 view.put("filter", filter); 092 } 093 094 sb.append(String.format("<ins class=\"view\">%s</ins>", Utils.toJson(view))); 095 return sb.toString(); 096 } 097 098}