001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (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.ade.galleries.client; 029 030import org.opencms.ade.galleries.shared.CmsGalleryTabConfiguration; 031import org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration; 032import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants; 033import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryMode; 034import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryTabId; 035import org.opencms.gwt.client.util.CmsDomUtil; 036import org.opencms.util.CmsStringUtil; 037 038import java.util.Arrays; 039import java.util.List; 040 041import com.google.gwt.core.client.JavaScriptObject; 042 043/** 044 * Gallery configuration java-script overlay object.<p> 045 */ 046public final class CmsGalleryConfigurationJSO extends JavaScriptObject implements I_CmsGalleryConfiguration { 047 048 /** 049 * Hiding constructor.<p> 050 */ 051 protected CmsGalleryConfigurationJSO() { 052 053 // nothing to do 054 } 055 056 /** 057 * Parses the given JSON configuration string.<p> 058 * 059 * @param conf the JSON configuration string 060 * 061 * @return the gallery configuration object 062 */ 063 public static CmsGalleryConfigurationJSO parseConfiguration(String conf) { 064 065 if (CmsStringUtil.isEmptyOrWhitespaceOnly(conf)) { 066 conf = "{}"; 067 } 068 return (CmsGalleryConfigurationJSO)CmsDomUtil.parseJSON(conf); 069 } 070 071 /** 072 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getCurrentElement() 073 */ 074 public String getCurrentElement() { 075 076 return getString(I_CmsGalleryProviderConstants.CONFIG_CURRENT_ELEMENT); 077 } 078 079 /** 080 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getGalleryMode() 081 */ 082 public GalleryMode getGalleryMode() { 083 084 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetGalleryMode())) { 085 return Enum.valueOf(GalleryMode.class, internalGetGalleryMode()); 086 } 087 return null; 088 } 089 090 /** 091 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getGalleryPath() 092 */ 093 public String getGalleryPath() { 094 095 return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_PATH); 096 } 097 098 /** 099 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getGalleryStoragePrefix() 100 */ 101 public String getGalleryStoragePrefix() { 102 103 return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_STORAGE_PREFIX); 104 } 105 106 /** 107 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getGalleryTypeName() 108 */ 109 public String getGalleryTypeName() { 110 111 return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_NAME); 112 } 113 114 /** 115 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getGalleryTypes() 116 */ 117 public String[] getGalleryTypes() { 118 119 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetGalleryTypes())) { 120 return internalGetGalleryTypes().split(","); 121 } 122 return null; 123 } 124 125 /** 126 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getImageFormatNames() 127 */ 128 public native String getImageFormatNames()/*-{ 129 if (typeof this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_IMAGE_FORMAT_NAMES] != 'undefined') { 130 return this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_IMAGE_FORMAT_NAMES] 131 .toString(); 132 } 133 return null; 134 }-*/; 135 136 /** 137 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getImageFormats() 138 */ 139 public native String getImageFormats()/*-{ 140 if (typeof this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_IMAGE_FORMATS] != 'undefined') { 141 return this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_IMAGE_FORMATS] 142 .toString(); 143 } 144 return null; 145 }-*/; 146 147 /** 148 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getLocale() 149 */ 150 public String getLocale() { 151 152 return getString(I_CmsGalleryProviderConstants.CONFIG_LOCALE); 153 } 154 155 /** 156 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getReferencePath() 157 */ 158 public String getReferencePath() { 159 160 return getString(I_CmsGalleryProviderConstants.CONFIG_REFERENCE_PATH); 161 } 162 163 /** 164 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getResourceTypes() 165 */ 166 public List<String> getResourceTypes() { 167 168 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetResourceTypes())) { 169 return Arrays.asList(internalGetResourceTypes().split(",")); 170 } 171 return null; 172 } 173 174 /** 175 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getSearchTypes() 176 */ 177 public List<String> getSearchTypes() { 178 179 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetSearchTypes())) { 180 return Arrays.asList(internalGetSearchTypes().split(",")); 181 } 182 return null; 183 } 184 185 /** 186 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getStartFolder() 187 */ 188 public String getStartFolder() { 189 190 return getString(I_CmsGalleryProviderConstants.CONFIG_START_FOLDER); 191 } 192 193 /** 194 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getStartSite() 195 */ 196 public native String getStartSite()/*-{ 197 if (typeof this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_SITE] != 'undefined') { 198 return this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_SITE]; 199 } 200 return null; 201 }-*/; 202 203 /** 204 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getTabConfiguration() 205 */ 206 public CmsGalleryTabConfiguration getTabConfiguration() { 207 208 return CmsGalleryTabConfiguration.resolve(getTabConfigString()); 209 210 } 211 212 /** 213 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getTreeToken() 214 */ 215 public String getTreeToken() { 216 217 return getString(I_CmsGalleryProviderConstants.CONFIG_TREE_TOKEN); 218 } 219 220 /** 221 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getUploadFolder() 222 */ 223 public String getUploadFolder() { 224 225 return getString(I_CmsGalleryProviderConstants.CONFIG_UPLOAD_FOLDER); 226 } 227 228 /** 229 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isGalleriesSelectable() 230 */ 231 public boolean isGalleriesSelectable() { 232 233 return Boolean.valueOf(getString(I_CmsGalleryProviderConstants.CONFIG_GALLERIES_SELECTABLE)).booleanValue(); 234 } 235 236 /** 237 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isIncludeFiles() 238 */ 239 public boolean isIncludeFiles() { 240 241 return getTabConfiguration().getTabs().contains(GalleryTabId.cms_tab_results); 242 } 243 244 /** 245 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isResultsSelectable() 246 */ 247 public boolean isResultsSelectable() { 248 249 String resultsSelectable = getString(I_CmsGalleryProviderConstants.CONFIG_RESULTS_SELECTABLE); 250 if (resultsSelectable == null) { 251 return true; 252 } 253 return Boolean.valueOf(resultsSelectable).booleanValue(); 254 } 255 256 /** 257 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isShowSiteSelector() 258 */ 259 public native boolean isShowSiteSelector()/*-{ 260 // defaults to true 261 return 'false' != '' 262 + this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_SHOW_SITE_SELECTOR] 263 }-*/; 264 265 /** 266 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isUseFormats() 267 */ 268 public native boolean isUseFormats()/*-{ 269 // defaults to false 270 return 'true' == '' 271 + this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_USE_FORMATS] 272 }-*/; 273 274 /** 275 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#setCurrentElement(java.lang.String) 276 */ 277 public native void setCurrentElement(String currentElement)/*-{ 278 this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_CURRENT_ELEMENT] = currentElement; 279 }-*/; 280 281 /** 282 * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#setStartFolder(java.lang.String) 283 */ 284 public native void setStartFolder(String startFolder)/*-{ 285 286 this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_FOLDER] = startFolder; 287 }-*/; 288 289 /** 290 * Gets a string-valued attribute.<p> 291 * 292 * @param key the name of the attribute 293 * 294 * @return the value of the attribute 295 */ 296 private native String getString(String key) /*-{ 297 if (typeof this[key] != 'undefined') { 298 return this[key]; 299 } 300 return null; 301 }-*/; 302 303 /** 304 * Gets the tab configuration string.<p> 305 * 306 * @return the tab configuration string 307 */ 308 private String getTabConfigString() { 309 310 return getString(I_CmsGalleryProviderConstants.CONFIG_TAB_CONFIG); 311 } 312 313 /** 314 * Returns the gallery mode name.<p> 315 * 316 * @return the gallery mode name 317 */ 318 private String internalGetGalleryMode() { 319 320 return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_MODE); 321 } 322 323 /** 324 * Returns the gallery types in a comma separated list.<p> 325 * 326 * @return the gallery types in a comma separated list 327 */ 328 private String internalGetGalleryTypes() { 329 330 return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_TYPES); 331 } 332 333 /** 334 * Returns the resource types in a comma separated list.<p> 335 * 336 * @return the resource types in a comma separated list 337 */ 338 private String internalGetResourceTypes() { 339 340 return getString(I_CmsGalleryProviderConstants.CONFIG_RESOURCE_TYPES); 341 } 342 343 /** 344 * Returns the search types in a comma separated list.<p> 345 * 346 * @return the search types in a comma separated list 347 */ 348 private String internalGetSearchTypes() { 349 350 return getString(I_CmsGalleryProviderConstants.CONFIG_SEARCH_TYPES); 351 } 352 353}