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.config;
029
030import org.opencms.util.CmsGeoUtil;
031
032/**
033 * Search configuration for the Geo filter.
034 */
035public class CmsSearchConfigurationGeoFilter implements I_CmsSearchConfigurationGeoFilter {
036
037    /** The coordinates. */
038    private String m_coordinates;
039
040    /** The name of the coordinates parameter. */
041    private String m_coordinatesParam;
042
043    /** The name of the field that stores the coordinates. */
044    private String m_fieldName;
045
046    /** The radius. */
047    private String m_radius;
048
049    /** The name of the radius parameter. */
050    private String m_radiusParam;
051
052    /** The units of the radius. */
053    private String m_units;
054
055    /** The name of the units parameter. */
056    private String m_unitsParam;
057
058    /**
059     * Constructor for the Geo filter configuration.
060     */
061    public CmsSearchConfigurationGeoFilter() {}
062
063    /**
064     * Constructor for the Geo filter configuration.
065     * @param coordinates the coordinates
066     * @param coordinatesParam the name of the coordinates parameter used by the search form
067     * @param fieldName the Solr field where coordinates are stored
068     * @param radius the radius
069     * @param radiusParam the name of the radius parameter used by the search form
070     * @param units the units of the radius
071     * @param unitsParam the name of the units parameter used by the search form
072     */
073    public CmsSearchConfigurationGeoFilter(
074        String coordinates,
075        String coordinatesParam,
076        String fieldName,
077        String radius,
078        String radiusParam,
079        String units,
080        String unitsParam) {
081
082        m_coordinates = CmsGeoUtil.validateCoordinates(coordinates) ? coordinates : null;
083        m_coordinatesParam = coordinatesParam;
084        m_fieldName = fieldName;
085        m_radius = CmsGeoUtil.validateRadius(radius) ? radius : null;
086        m_radiusParam = radiusParam;
087        m_units = CmsGeoUtil.validateUnits(units) ? units : null;
088        m_unitsParam = unitsParam;
089    }
090
091    /**
092     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getCoordinates()
093     */
094    @Override
095    public String getCoordinates() {
096
097        return m_coordinates;
098    }
099
100    /**
101     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getCoordinatesParam()
102     */
103    @Override
104    public String getCoordinatesParam() {
105
106        return m_coordinatesParam != null ? m_coordinatesParam : DEFAULT_COORDINATES_PARAM;
107    }
108
109    /**
110     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getFieldName()
111     */
112    @Override
113    public String getFieldName() {
114
115        return m_fieldName != null ? m_fieldName : DEFAULT_FIELD_NAME;
116    }
117
118    /**
119     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getRadius()
120     */
121    @Override
122    public String getRadius() {
123
124        return m_radius;
125    }
126
127    /**
128     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getRadiusParam()
129     */
130    @Override
131    public String getRadiusParam() {
132
133        return m_radiusParam != null ? m_radiusParam : DEFAULT_RADIUS_PARAM;
134    }
135
136    /**
137     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getUnits()
138     */
139    @Override
140    public String getUnits() {
141
142        return m_units != null ? m_units : DEFAULT_UNITS;
143    }
144
145    /**
146     * @see org.opencms.jsp.search.config.I_CmsSearchConfigurationGeoFilter#getUnitsParam()
147     */
148    @Override
149    public String getUnitsParam() {
150
151        return m_unitsParam != null ? m_unitsParam : DEFAULT_UNITS_PARAM;
152    }
153
154}