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.jsp.search.state;
029
030import org.opencms.util.CmsCollectionsGenericWrapper;
031
032import java.util.LinkedList;
033import java.util.List;
034import java.util.Map;
035
036import org.apache.commons.collections.Transformer;
037
038/** Class for keeping the state common for all facet types. */
039public class CmsSearchStateFacet implements I_CmsSearchStateFacet {
040
041    /** The checked facet entries. */
042    List<String> m_checked;
043    /** Map with "facet entry" - "isChecked" pairs. */
044    private Map<String, Boolean> m_checkedMap;
045    /** Indicator if the configured limit for the maximal number of facet entries should be used. */
046    private boolean m_useLimit;
047    /** Indicator if checked facet entries should be ignored (when building the Solr query). */
048    private boolean m_ignoreChecked;
049
050    /** Default constructor. */
051    public CmsSearchStateFacet() {
052
053        m_checked = new LinkedList<String>();
054        m_useLimit = true;
055        m_ignoreChecked = false;
056    }
057
058    /**
059     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#addChecked(java.lang.String)
060     */
061    @Override
062    public void addChecked(final String entry) {
063
064        m_checked.add(entry);
065
066    }
067
068    /**
069     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#clearChecked()
070     */
071    @Override
072    public void clearChecked() {
073
074        m_checked.clear();
075
076    }
077
078    /**
079     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#getCheckedEntries()
080     */
081    @Override
082    public List<String> getCheckedEntries() {
083
084        return m_checked;
085    }
086
087    /**
088     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#getIgnoreChecked()
089     */
090    @Override
091    public boolean getIgnoreChecked() {
092
093        return m_ignoreChecked;
094    }
095
096    /**
097     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#getIsChecked()
098     */
099    @Override
100    public Map<String, Boolean> getIsChecked() {
101
102        if (m_checkedMap == null) {
103            m_checkedMap = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {
104
105                @Override
106                public Object transform(final Object option) {
107
108                    return Boolean.valueOf(m_checked.contains(option));
109                }
110            });
111        }
112        return m_checkedMap;
113    }
114
115    /**
116     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#getUseLimit()
117     */
118    @Override
119    public boolean getUseLimit() {
120
121        return m_useLimit;
122    }
123
124    /**
125     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#setIgnoreChecked(boolean)
126     */
127    @Override
128    public void setIgnoreChecked(final boolean ignore) {
129
130        m_ignoreChecked = ignore;
131    }
132
133    /**
134     * @see org.opencms.jsp.search.state.I_CmsSearchStateFacet#setUseLimit(boolean)
135     */
136    @Override
137    public void setUseLimit(final boolean useLimit) {
138
139        m_useLimit = useLimit;
140
141    }
142
143}