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