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.jsp.search.config.I_CmsSearchConfigurationSortOption; 031import org.opencms.util.CmsCollectionsGenericWrapper; 032 033import java.util.Map; 034 035import org.apache.commons.collections.Transformer; 036 037/** Class for keeping the state of the sorting options. */ 038public class CmsSearchStateSorting implements I_CmsSearchStateSorting { 039 040 /** The selected sort option. */ 041 I_CmsSearchConfigurationSortOption m_selected; 042 /** Lazy map, to check, if a sort option is selected. */ 043 Map<I_CmsSearchConfigurationSortOption, Boolean> m_selectedMap; 044 045 /** 046 * @see org.opencms.jsp.search.state.I_CmsSearchStateSorting#getCheckSelected() 047 */ 048 @Override 049 public Map<I_CmsSearchConfigurationSortOption, Boolean> getCheckSelected() { 050 051 if (m_selectedMap == null) { 052 m_selectedMap = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() { 053 054 @Override 055 public Object transform(final Object option) { 056 057 return Boolean.valueOf(((I_CmsSearchConfigurationSortOption)option).equals(m_selected)); 058 } 059 }); 060 } 061 return m_selectedMap; 062 } 063 064 /** 065 * @see org.opencms.jsp.search.state.I_CmsSearchStateSorting#getSelected() 066 */ 067 @Override 068 public I_CmsSearchConfigurationSortOption getSelected() { 069 070 return m_selected; 071 } 072 073 /** 074 * @see org.opencms.jsp.search.state.I_CmsSearchStateSorting#setSelectedOption(org.opencms.jsp.search.config.I_CmsSearchConfigurationSortOption) 075 */ 076 @Override 077 public void setSelectedOption(final I_CmsSearchConfigurationSortOption option) { 078 079 m_selected = option; 080 081 } 082 083}