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#getPageId()
157     */
158    public String getPageId() {
159
160        return getString(I_CmsGalleryProviderConstants.CONFIG_PAGE_ID);
161    }
162
163    /**
164     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getReferencePath()
165     */
166    public String getReferencePath() {
167
168        return getString(I_CmsGalleryProviderConstants.CONFIG_REFERENCE_PATH);
169    }
170
171    /**
172     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getResourceTypes()
173     */
174    public List<String> getResourceTypes() {
175
176        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetResourceTypes())) {
177            return Arrays.asList(internalGetResourceTypes().split(","));
178        }
179        return null;
180    }
181
182    /**
183     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getSearchTypes()
184     */
185    public List<String> getSearchTypes() {
186
187        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(internalGetSearchTypes())) {
188            return Arrays.asList(internalGetSearchTypes().split(","));
189        }
190        return null;
191    }
192
193    /**
194     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getStartFolder()
195     */
196    public String getStartFolder() {
197
198        return getString(I_CmsGalleryProviderConstants.CONFIG_START_FOLDER);
199    }
200
201    /**
202     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getStartSite()
203     */
204    public native String getStartSite()/*-{
205                if (typeof this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_SITE] != 'undefined') {
206                        return this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_SITE];
207                }
208                return null;
209    }-*/;
210
211    /**
212     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getTabConfiguration()
213     */
214    public CmsGalleryTabConfiguration getTabConfiguration() {
215
216        return CmsGalleryTabConfiguration.resolve(getTabConfigString());
217
218    }
219
220    /**
221     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getTreeToken()
222     */
223    public String getTreeToken() {
224
225        return getString(I_CmsGalleryProviderConstants.CONFIG_TREE_TOKEN);
226    }
227
228    /**
229     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#getUploadFolder()
230     */
231    public String getUploadFolder() {
232
233        return getString(I_CmsGalleryProviderConstants.CONFIG_UPLOAD_FOLDER);
234    }
235
236    /**
237     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isGalleriesSelectable()
238     */
239    public boolean isGalleriesSelectable() {
240
241        return Boolean.valueOf(getString(I_CmsGalleryProviderConstants.CONFIG_GALLERIES_SELECTABLE)).booleanValue();
242    }
243
244    /**
245     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isIncludeFiles()
246     */
247    public boolean isIncludeFiles() {
248
249        return getTabConfiguration().getTabs().contains(GalleryTabId.cms_tab_results);
250    }
251
252    /**
253     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isResultsSelectable()
254     */
255    public boolean isResultsSelectable() {
256
257        String resultsSelectable = getString(I_CmsGalleryProviderConstants.CONFIG_RESULTS_SELECTABLE);
258        if (resultsSelectable == null) {
259            return true;
260        }
261        return Boolean.valueOf(resultsSelectable).booleanValue();
262    }
263
264    /**
265     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isShowSiteSelector()
266     */
267    public native boolean isShowSiteSelector()/*-{
268                // defaults to true
269                return 'false' != ''
270                                + this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_SHOW_SITE_SELECTOR]
271    }-*/;
272
273    /**
274     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#isUseFormats()
275     */
276    public native boolean isUseFormats()/*-{
277                // defaults to false
278                return 'true' == ''
279                                + this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_USE_FORMATS]
280    }-*/;
281
282    /**
283     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#setCurrentElement(java.lang.String)
284     */
285    public native void setCurrentElement(String currentElement)/*-{
286                this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_CURRENT_ELEMENT] = currentElement;
287    }-*/;
288
289    /**
290     * @see org.opencms.ade.galleries.shared.I_CmsGalleryConfiguration#setStartFolder(java.lang.String)
291     */
292    public native void setStartFolder(String startFolder)/*-{
293
294                this[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::CONFIG_START_FOLDER] = startFolder;
295    }-*/;
296
297    /**
298     * Gets a string-valued attribute.<p>
299     *
300     * @param key the name of the attribute
301     *
302     * @return the value of the attribute
303     */
304    private native String getString(String key) /*-{
305                if (typeof this[key] != 'undefined') {
306                        return this[key];
307                }
308                return null;
309    }-*/;
310
311    /**
312     * Gets the tab configuration string.<p>
313     *
314     * @return the tab configuration string
315     */
316    private String getTabConfigString() {
317
318        return getString(I_CmsGalleryProviderConstants.CONFIG_TAB_CONFIG);
319    }
320
321    /**
322     * Returns the gallery mode name.<p>
323     *
324     * @return the gallery mode name
325     */
326    private String internalGetGalleryMode() {
327
328        return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_MODE);
329    }
330
331    /**
332     * Returns the gallery types in a comma separated list.<p>
333     *
334     * @return the gallery types in a comma separated list
335     */
336    private String internalGetGalleryTypes() {
337
338        return getString(I_CmsGalleryProviderConstants.CONFIG_GALLERY_TYPES);
339    }
340
341    /**
342     * Returns the resource types in a comma separated list.<p>
343     *
344     * @return the resource types in a comma separated list
345     */
346    private String internalGetResourceTypes() {
347
348        return getString(I_CmsGalleryProviderConstants.CONFIG_RESOURCE_TYPES);
349    }
350
351    /**
352     * Returns the search types in a comma separated list.<p>
353     *
354     * @return the search types in a comma separated list
355     */
356    private String internalGetSearchTypes() {
357
358        return getString(I_CmsGalleryProviderConstants.CONFIG_SEARCH_TYPES);
359    }
360
361}