001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.shared; 029 030import org.opencms.util.CmsDefaultSet; 031import org.opencms.xml.content.CmsXmlContentProperty; 032 033import java.util.LinkedHashMap; 034import java.util.Map; 035 036import com.google.gwt.user.client.rpc.IsSerializable; 037 038/** 039 * Client-compatible bean with information about the current template context.<p> 040 */ 041public class CmsTemplateContextInfo implements IsSerializable { 042 043 /** Dummy element marker class. */ 044 public static final String DUMMY_ELEMENT_MARKER = "cmsTemplateContextDummyMarker"; 045 046 /** The constant used for empty setting. */ 047 public static final String EMPTY_VALUE = "none"; 048 049 /** The setting name used for storing the compatible template contexts. */ 050 public static final String SETTING = "templateContexts"; 051 052 /** The map of allowed contexts for each type. */ 053 private Map<String, CmsDefaultSet<String>> m_allowedContextMap; 054 055 /** Client variant information. */ 056 private Map<String, Map<String, CmsClientVariantInfo>> m_clientVariantInfo = new LinkedHashMap<String, Map<String, CmsClientVariantInfo>>(); 057 058 /** A map from the names of all available template contexts to their localized names. */ 059 private Map<String, String> m_contextLabels = new LinkedHashMap<String, String>(); 060 061 /** The context provider class. */ 062 private String m_contextProvider; 063 064 /** The name of the cookie used for overriding the template context. */ 065 private String m_cookieName; 066 067 /** The key of the currently active context. */ 068 private String m_currentContext; 069 070 /** The name of the selected context (using the cookie) .*/ 071 private String m_selectedContext; 072 073 /** The setting definition for the templateContexts setting. */ 074 private CmsXmlContentProperty m_settingDefinition; 075 076 /** 077 * Default constructor.<p> 078 */ 079 public CmsTemplateContextInfo() { 080 081 // default constructor 082 } 083 084 /** 085 * Gets the map of forbidden contexts for resource types.<p> 086 * 087 * @return the map of forbidden contexts for resource types 088 */ 089 public Map<String, CmsDefaultSet<String>> getAllowedContexts() { 090 091 return m_allowedContextMap; 092 093 } 094 095 /** 096 * Gets the client variant information for a specific context.<p> 097 * 098 * @param context the context name 099 * 100 * @return the client variant information for that context 101 */ 102 public Map<String, CmsClientVariantInfo> getClientVariants(String context) { 103 104 return m_clientVariantInfo.get(context); 105 } 106 107 /** 108 * Gets the map of labels for the different template contexts.<p> 109 * 110 * @return the map of template context labels 111 */ 112 public Map<String, String> getContextLabels() { 113 114 return m_contextLabels; 115 } 116 117 /** 118 * Gets the name of the context provider class.<p> 119 * 120 * @return the name of the context provider class 121 */ 122 public String getContextProvider() { 123 124 return m_contextProvider; 125 } 126 127 /** 128 * Gets the name of the cookie used for overriding the template context.<p> 129 * 130 * @return the cookie name 131 */ 132 public String getCookieName() { 133 134 return m_cookieName; 135 } 136 137 /** 138 * Gets the key of the currently active template context.<p> 139 * 140 * @return the key of the currently active template context 141 */ 142 public String getCurrentContext() { 143 144 return m_currentContext; 145 } 146 147 /** 148 * Gets the key of the currently selected template context, using the cookie.<p> 149 * 150 * @return the name of the currently selected template context 151 */ 152 public String getSelectedContext() { 153 154 return m_selectedContext; 155 } 156 157 /** 158 * Gets the property definition for the templateContexts setting.<p> 159 * 160 * @return the property definition for the templateContexts setting 161 */ 162 public CmsXmlContentProperty getSettingDefinition() { 163 164 return m_settingDefinition; 165 } 166 167 /** 168 * Checks if client variants for the given context are present.<p> 169 * 170 * @param context a context name 171 * @return true if there are client variants for the context 172 */ 173 public boolean hasClientVariants(String context) { 174 175 return m_clientVariantInfo.containsKey(context); 176 } 177 178 /** 179 * Sets the allowed contexts.<p> 180 * 181 * @param allowedContextMap the map of allowed contexts 182 */ 183 public void setAllowedContexts(Map<String, CmsDefaultSet<String>> allowedContextMap) { 184 185 m_allowedContextMap = allowedContextMap; 186 } 187 188 /** 189 * Adds a client variant.<p> 190 * 191 * @param context a context name 192 * @param variant the variant name 193 * @param info the bean with the variant information 194 */ 195 public void setClientVariant(String context, String variant, CmsClientVariantInfo info) { 196 197 if (!m_clientVariantInfo.containsKey(context)) { 198 Map<String, CmsClientVariantInfo> variants = new LinkedHashMap<String, CmsClientVariantInfo>(); 199 m_clientVariantInfo.put(context, variants); 200 } 201 m_clientVariantInfo.get(context).put(variant, info); 202 } 203 204 /** 205 * Sets the map of labels for the contexts.<p> 206 * 207 * @param contextLabels the map of context labels 208 */ 209 public void setContextLabels(Map<String, String> contextLabels) { 210 211 m_contextLabels = contextLabels; 212 } 213 214 /** 215 * Sets the context provider class name.<p> 216 * 217 * @param contextProvider the context provider class name 218 */ 219 public void setContextProvider(String contextProvider) { 220 221 m_contextProvider = contextProvider; 222 } 223 224 /** 225 * Sets the name of the cookie used for overriding the template context.<p> 226 * 227 * @param cookieName the name of the cookie used for overriding the template context 228 */ 229 public void setCookieName(String cookieName) { 230 231 m_cookieName = cookieName; 232 } 233 234 /** 235 * Sets the active context.<p> 236 * 237 * @param context the active context 238 */ 239 public void setCurrentContext(String context) { 240 241 m_currentContext = context; 242 } 243 244 /** 245 * Sets the selected context.<p> 246 * 247 * @param selectedContext the selected context 248 */ 249 public void setSelectedContext(String selectedContext) { 250 251 m_selectedContext = selectedContext; 252 } 253 254 /** 255 * Sets the property definition for the templateContexts setting.<p> 256 * 257 * @param definition the property definition 258 */ 259 public void setSettingDefinition(CmsXmlContentProperty definition) { 260 261 m_settingDefinition = definition; 262 } 263 264 /** 265 * Returns true if the template context selection should be shown for container elements.<p> 266 * 267 * @return true if the template context selection for elements should be shown 268 */ 269 public boolean shouldShowElementTemplateContextSelection() { 270 271 return hasMoreThanOneOption(); 272 } 273 274 /** 275 * Returns true if the template context selection context menu entry should be shown.<p> 276 * 277 * @return true if the template context selection context menu entry should be shown 278 */ 279 public boolean shouldShowTemplateContextContextMenuEntry() { 280 281 return hasMoreThanOneOption(); 282 283 } 284 285 /** 286 * Returns true if there is more than one template context to choose from.<p> 287 * 288 * @return true if there is more than one template context 289 */ 290 private boolean hasMoreThanOneOption() { 291 292 return (m_currentContext != null) && (m_contextLabels.size() > 1); 293 } 294}