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 GmbH & Co. KG, 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.workplace.search;
029
030import org.opencms.main.CmsIllegalArgumentException;
031import org.opencms.main.CmsIllegalStateException;
032import org.opencms.search.CmsSearchParameters;
033import org.opencms.util.CmsStringUtil;
034
035/**
036 * Bean to handle search parameters in the workplace.<p>
037 *
038 * @since 6.3.0
039 */
040public class CmsSearchWorkplaceBean {
041
042    /** The current folder. */
043    private String m_currentFolder;
044
045    /** The comma separated list of fields to search parameter value. */
046    private String m_fields;
047
048    /** The index name. */
049    private String m_indexName;
050
051    /** The creation date the resources have to have as maximum. */
052    private String m_maxDateCreated;
053
054    /** The last modification date the resources have to have as maximum. */
055    private String m_maxDateLastModified;
056
057    /** The creation date the resources have to have as minimum. */
058    private String m_minDateCreated;
059
060    /** The last modification date the resources have to have as minimum. */
061    private String m_minDateLastModified;
062
063    /** The query. */
064    private String m_query;
065
066    /** If set, will restrict the search to the current folder. */
067    private boolean m_restrictSearch;
068
069    /** The sort Order. */
070    private String m_sortOrder;
071
072    /**
073     * Default constructor.<p>
074     *
075     * @param currentFolder the current folder
076     */
077    public CmsSearchWorkplaceBean(String currentFolder) {
078
079        m_fields = CmsStringUtil.collectionAsString(new CmsSearchParameters().getFields(), ",");
080        m_sortOrder = CmsSearchParameters.SORT_NAMES[0];
081        m_currentFolder = currentFolder;
082    }
083
084    /**
085     * Returns the fields parameter value.<p>
086     *
087     * @return the fields parameter value
088     */
089    public String getFields() {
090
091        return m_fields;
092    }
093
094    /**
095     * Returns the index name.<p>
096     *
097     * @return the index name
098     */
099    public String getIndexName() {
100
101        return m_indexName;
102    }
103
104    /**
105     * Returns the creation date the resources have to have as maximum.<p>
106     *
107     * @return the creation date the resources have to have as maximum
108     */
109    public String getMaxDateCreated() {
110
111        return m_maxDateCreated;
112    }
113
114    /**
115     * Returns the last modification date the resources have to have as maximum.<p>
116     *
117     * @return the last modification date the resources have to have as maximum
118     */
119    public String getMaxDateLastModified() {
120
121        return m_maxDateLastModified;
122    }
123
124    /**
125     * Returns the creation date the resources have to have as minimum.<p>
126     *
127     * @return the creation date the resources have to have as minimum
128     */
129    public String getMinDateCreated() {
130
131        return m_minDateCreated;
132    }
133
134    /**
135     * Returns the last modification date the resources have to have as minimum.<p>
136     *
137     * @return the last modification date the resources have to have as minimum
138     */
139    public String getMinDateLastModified() {
140
141        return m_minDateLastModified;
142    }
143
144    /**
145     * Returns the query.<p>
146     *
147     * @return the query
148     */
149    public String getQuery() {
150
151        return m_query;
152    }
153
154    /**
155     * Returns the search path.<p>
156     *
157     * @return the search path
158     */
159    public String getSearchPath() {
160
161        if (isRestrictSearch()) {
162            return m_currentFolder;
163        } else {
164            return "/";
165        }
166    }
167
168    /**
169     * Returns the sort Order.<p>
170     *
171     * @return the sort Order
172     */
173    public String getSortOrder() {
174
175        return m_sortOrder;
176    }
177
178    /**
179     * Returns the restrict Search flag.<p>
180     *
181     * @return the restrict Search flag
182     */
183    public boolean isRestrictSearch() {
184
185        return m_restrictSearch;
186    }
187
188    /**
189     * Sets the fields parameter value.<p>
190     *
191     * @param fields the fields parameter value to set
192     */
193    public void setFields(String fields) {
194
195        if (CmsStringUtil.isEmptyOrWhitespaceOnly(fields)) {
196            throw new CmsIllegalStateException(Messages.get().container(Messages.ERR_VALIDATE_SEARCH_PARAMS_0));
197        }
198        m_fields = fields;
199    }
200
201    /**
202     * Sets the index name.<p>
203     *
204     * @param indexName the index name
205     */
206    public void setIndexName(String indexName) {
207
208        m_indexName = indexName;
209    }
210
211    /**
212     * Sets the creation date the resources have to have as maximum.<p>
213     *
214     * @param maxDateCreated the creation date the resources have to have as maximum to set
215     */
216    public void setMaxDateCreated(String maxDateCreated) {
217
218        m_maxDateCreated = maxDateCreated;
219    }
220
221    /**
222     * Sets the last modification date the resources have to have as maximum.<p>
223     *
224     * @param maxDateLastModified the last modification date the resources have to have as maximum to set
225     */
226    public void setMaxDateLastModified(String maxDateLastModified) {
227
228        m_maxDateLastModified = maxDateLastModified;
229    }
230
231    /**
232     * Sets the creation date the resources have to have as minimum.<p>
233     *
234     * @param dateCreatedFrom the creation date the resources have to have as minimum to set
235     */
236    public void setMinDateCreated(String dateCreatedFrom) {
237
238        m_minDateCreated = dateCreatedFrom;
239    }
240
241    /**
242     * Sets the last modification date the resources have to have as minimum.<p>
243     *
244     * @param minDateLastModified the last modification date the resources have to have as minimum to set
245     */
246    public void setMinDateLastModified(String minDateLastModified) {
247
248        m_minDateLastModified = minDateLastModified;
249    }
250
251    /**
252     * Sets the query.<p>
253     *
254     * @param query the query to set
255     */
256    public void setQuery(String query) {
257
258        if (CmsStringUtil.isEmptyOrWhitespaceOnly(query)) {
259            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_VALIDATE_SEARCH_QUERY_0));
260        }
261        m_query = query;
262    }
263
264    /**
265     * Sets the restrict Search flag.<p>
266     *
267     * @param restrictSearch the restrict Search flag to set
268     */
269    public void setRestrictSearch(boolean restrictSearch) {
270
271        m_restrictSearch = restrictSearch;
272    }
273
274    /**
275     * Sets the sort Order.<p>
276     *
277     * @param sortOrder the sort Order to set
278     */
279    public void setSortOrder(String sortOrder) {
280
281        m_sortOrder = sortOrder;
282    }
283}