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.widgets;
029
030import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants;
031import org.opencms.file.CmsObject;
032import org.opencms.file.types.CmsResourceTypeImage;
033import org.opencms.i18n.CmsMessages;
034import org.opencms.json.JSONArray;
035import org.opencms.json.JSONException;
036import org.opencms.json.JSONObject;
037import org.opencms.main.OpenCms;
038import org.opencms.util.CmsStringUtil;
039
040/**
041 * ADE image gallery widget implementations.<p>
042 *
043 * @since 8.0.0
044 */
045public class CmsAdeImageGalleryWidget extends A_CmsAdeGalleryWidget {
046
047    /** The gallery name. */
048    private static final String GALLERY_NAME = "image";
049
050    /** The widget configuration. */
051    private CmsVfsImageWidgetConfiguration m_widgetConfiguration;
052
053    /**
054     * Constructor.<p>
055     */
056    public CmsAdeImageGalleryWidget() {
057
058        this("");
059    }
060
061    /**
062     * Creates a new gallery widget with the given configuration.<p>
063     *
064     * @param configuration the configuration to use
065     */
066    protected CmsAdeImageGalleryWidget(String configuration) {
067
068        super(configuration);
069    }
070
071    /**
072     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getGalleryName()
073     */
074    @Override
075    public String getGalleryName() {
076
077        return GALLERY_NAME;
078    }
079
080    /**
081     * @see org.opencms.widgets.I_CmsADEWidget#getWidgetName()
082     */
083    @Override
084    public String getWidgetName() {
085
086        return CmsAdeImageGalleryWidget.class.getName();
087    }
088
089    /**
090     * @see org.opencms.widgets.I_CmsWidget#newInstance()
091     */
092    public I_CmsWidget newInstance() {
093
094        return new CmsAdeImageGalleryWidget(getConfiguration());
095    }
096
097    /**
098     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getAdditionalGalleryInfo(org.opencms.file.CmsObject, java.lang.String, org.opencms.i18n.CmsMessages, org.opencms.widgets.I_CmsWidgetParameter)
099     */
100    @Override
101    protected JSONObject getAdditionalGalleryInfo(
102        CmsObject cms,
103        String resource,
104        CmsMessages messages,
105        I_CmsWidgetParameter param) throws JSONException {
106
107        CmsVfsImageWidgetConfiguration config = getWidgetConfiguration(cms, messages, param);
108        JSONObject result = new JSONObject();
109        result.put(I_CmsGalleryProviderConstants.CONFIG_USE_FORMATS, config.isShowFormat());
110        result.put(I_CmsGalleryProviderConstants.CONFIG_IMAGE_FORMATS, new JSONArray(config.getFormatValues()));
111        String temp = config.getSelectFormatString();
112        String[] formatNames = new String[0];
113        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(temp)) {
114            formatNames = config.getSelectFormatString().split("\\|");
115        }
116        result.put(I_CmsGalleryProviderConstants.CONFIG_IMAGE_FORMAT_NAMES, new JSONArray(formatNames));
117        result.put(I_CmsGalleryProviderConstants.CONFIG_TAB_CONFIG, "selectDoc");
118        String uploadFolder = OpenCms.getWorkplaceManager().getRepositoryFolderHandler().getRepositoryFolder(
119            cms,
120            resource,
121            GALLERY_NAME + "gallery");
122        if (uploadFolder != null) {
123            result.put(I_CmsGalleryProviderConstants.CONFIG_UPLOAD_FOLDER, uploadFolder);
124        }
125        return result;
126    }
127
128    /**
129     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getGalleryStoragePrefix()
130     */
131    @Override
132    protected String getGalleryStoragePrefix() {
133
134        return "image";
135    }
136
137    /**
138     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getGalleryTypes()
139     */
140    @Override
141    protected String getGalleryTypes() {
142
143        return CmsResourceTypeImage.getStaticTypeName();
144    }
145
146    /**
147     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getOpenPreviewCall(org.opencms.widgets.I_CmsWidgetDialog, java.lang.String)
148     */
149    @Override
150    protected String getOpenPreviewCall(I_CmsWidgetDialog widgetDialog, String id) {
151
152        // using the 'cmsOpenImagePreview' function instead of 'cmsOpenPreview'
153        StringBuffer sb = new StringBuffer(64);
154        // using the 'cmsOpenImagePreview' function instead of 'cmsOpenPreview'
155        sb.append("javascript:cmsOpenImagePreview('").append(
156            widgetDialog.getMessages().key(Messages.GUI_BUTTON_PREVIEW_0));
157        sb.append("', '").append(OpenCms.getSystemInfo().getOpenCmsContext());
158        sb.append("', '").append(id);
159        sb.append("'); return false;");
160        return sb.toString();
161    }
162
163    /**
164     * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getWidgetConfiguration(org.opencms.file.CmsObject, org.opencms.i18n.CmsMessages, org.opencms.widgets.I_CmsWidgetParameter)
165     */
166    @Override
167    protected CmsVfsImageWidgetConfiguration getWidgetConfiguration(
168        CmsObject cms,
169        CmsMessages messages,
170        I_CmsWidgetParameter param) {
171
172        if (m_widgetConfiguration == null) {
173            m_widgetConfiguration = new CmsVfsImageWidgetConfiguration(cms, messages, param, getConfiguration());
174        }
175        return m_widgetConfiguration;
176    }
177}