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.gwt.shared;
029
030import org.opencms.util.CmsStringUtil;
031
032import java.util.LinkedHashMap;
033import java.util.Map;
034
035import com.google.gwt.user.client.rpc.IsSerializable;
036
037/**
038 * Info needed to preview a resource.<p>
039 */
040public class CmsPreviewInfo implements IsSerializable {
041
042    /** The required height. */
043    private int m_height;
044
045    /** The preview locale. */
046    private String m_locale;
047
048    /** The available preview locales. */
049    private LinkedHashMap<String, String> m_locales;
050
051    /** Flag indicating that the preview should be opened in a new window. */
052    private boolean m_newWindowRequired;
053
054    /** The preview content. */
055    private String m_previewContent;
056
057    /** The URL to call for the preview. */
058    private String m_previewUrl;
059
060    /** The site path. */
061    private String m_sitePath;
062
063    /** The title. */
064    private String m_title;
065
066    /** The required width. */
067    private int m_width;
068
069    /**
070     * Constructor.<p>
071     *
072     * @param content the preview content
073     * @param url the preview URL
074     * @param newWindowRequired flag indicating that the preview should be opened in a new window
075     * @param title the title
076     * @param sitePath the site path
077     * @param locale the preview locale
078     */
079    public CmsPreviewInfo(
080        String content,
081        String url,
082        boolean newWindowRequired,
083        String title,
084        String sitePath,
085        String locale) {
086
087        m_previewContent = content;
088        m_previewUrl = url;
089        m_newWindowRequired = newWindowRequired;
090        m_title = title;
091        m_sitePath = sitePath;
092        m_locale = locale;
093    }
094
095    /**
096     * Constructor. For serialization only.<p>
097     */
098    protected CmsPreviewInfo() {
099
100        // nothing to do
101    }
102
103    /**
104     * Returns the required height.<p>
105     *
106     * @return the required height
107     */
108    public int getHeight() {
109
110        return m_height;
111    }
112
113    /**
114     * Returns the locale.<p>
115     *
116     * @return the locale
117     */
118    public String getLocale() {
119
120        return m_locale;
121    }
122
123    /**
124     * Returns the locales.<p>
125     *
126     * @return the locales
127     */
128    public Map<String, String> getLocales() {
129
130        return m_locales;
131    }
132
133    /**
134     * Returns the preview content.<p>
135     *
136     * @return the preview content
137     */
138    public String getPreviewContent() {
139
140        return m_previewContent;
141    }
142
143    /**
144     * Returns the preview URL.<p>
145     *
146     * @return the preview URL
147     */
148    public String getPreviewUrl() {
149
150        return m_previewUrl;
151    }
152
153    /**
154     * Returns the site path.<p>
155     *
156     * @return the site path
157     */
158    public String getSitePath() {
159
160        return m_sitePath;
161    }
162
163    /**
164     * Returns the title.<p>
165     *
166     * @return the title
167     */
168    public String getTitle() {
169
170        return m_title;
171    }
172
173    /**
174     * Returns the required width.<p>
175     *
176     * @return the required width
177     */
178    public int getWidth() {
179
180        return m_width;
181    }
182
183    /**
184     * Returns if the given preview content has additional locales.<p>
185     *
186     * @return <code>true</code> if the given preview content has additional locales
187     */
188    public boolean hasAdditionalLocales() {
189
190        return (m_locales != null) && (m_locales.size() > 1);
191    }
192
193    /**
194     * Returns if the preview requires specific dimensions.<p>
195     *
196     * @return <code>true</code> if the dialog requires dimensions
197     */
198    public boolean hasDimensions() {
199
200        return (m_height > 0) && (m_width > 0);
201    }
202
203    /**
204     * Returns if preview HTML content is available to display directly.<p>
205     *
206     * @return if preview HTML content is available to display directly
207     */
208    public boolean hasPreviewContent() {
209
210        return CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_previewContent);
211    }
212
213    /**
214     * Returns if there a URL available to call for the preview.<p>
215     *
216     * @return if there a URL available to call for the preview
217     */
218    public boolean hasPreviewUrl() {
219
220        return CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_previewUrl);
221    }
222
223    /**
224     * Returns if it is required to open the preview in a new window.<p>
225     *
226     * @return <code>true</code> if it is required to open the preview in a new window
227     */
228    public boolean isNewWindowRequired() {
229
230        return m_newWindowRequired;
231    }
232
233    /**
234     * Sets the required height.<p>
235     *
236     * @param height the required height to set
237     */
238    public void setHeight(int height) {
239
240        m_height = height;
241    }
242
243    /**
244     * Sets the locales.<p>
245     *
246     * @param locales the locales to set
247     */
248    public void setLocales(LinkedHashMap<String, String> locales) {
249
250        m_locales = locales;
251    }
252
253    /**
254     * Sets the required width.<p>
255     *
256     * @param width the required width to set
257     */
258    public void setWidth(int width) {
259
260        m_width = width;
261    }
262
263}