001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.search.facet;
016    
017    import com.liferay.portal.kernel.search.BooleanClause;
018    import com.liferay.portal.kernel.search.SearchContext;
019    import com.liferay.portal.kernel.search.facet.collector.FacetCollector;
020    import com.liferay.portal.kernel.search.facet.config.FacetConfiguration;
021    import com.liferay.portal.kernel.search.facet.util.BaseFacetValueValidator;
022    import com.liferay.portal.kernel.search.facet.util.FacetValueValidator;
023    
024    /**
025     * @author Raymond Aug??
026     */
027    public abstract class BaseFacet implements Facet {
028    
029            public BaseFacet(SearchContext searchContext) {
030                    _searchContext = searchContext;
031            }
032    
033            @Override
034            public BooleanClause getFacetClause() {
035                    return doGetFacetClause();
036            }
037    
038            @Override
039            public FacetCollector getFacetCollector() {
040                    return _facetCollector;
041            }
042    
043            @Override
044            public FacetConfiguration getFacetConfiguration() {
045                    return _facetConfiguration;
046            }
047    
048            @Override
049            public FacetValueValidator getFacetValueValidator() {
050                    if (_facetValueValidator == null) {
051                            _facetValueValidator = new BaseFacetValueValidator();
052                    }
053    
054                    return _facetValueValidator;
055            }
056    
057            @Override
058            public String getFieldName() {
059                    return _facetConfiguration.getFieldName();
060            }
061    
062            @Override
063            public SearchContext getSearchContext() {
064                    return _searchContext;
065            }
066    
067            @Override
068            public boolean isStatic() {
069                    return _facetConfiguration.isStatic();
070            }
071    
072            @Override
073            public void setFacetCollector(FacetCollector facetCollector) {
074                    _facetCollector = facetCollector;
075            }
076    
077            @Override
078            public void setFacetConfiguration(FacetConfiguration facetConfiguration) {
079                    _facetConfiguration = facetConfiguration;
080            }
081    
082            @Override
083            public void setFacetValueValidator(
084                    FacetValueValidator facetValueValidator) {
085    
086                    _facetValueValidator = facetValueValidator;
087            }
088    
089            @Override
090            public void setFieldName(String fieldName) {
091                    _facetConfiguration.setFieldName(fieldName);
092            }
093    
094            @Override
095            public void setStatic(boolean isStatic) {
096                    _facetConfiguration.setStatic(isStatic);
097            }
098    
099            protected abstract BooleanClause doGetFacetClause();
100    
101            private FacetCollector _facetCollector;
102            private FacetConfiguration _facetConfiguration = new FacetConfiguration();
103            private FacetValueValidator _facetValueValidator;
104            private SearchContext _searchContext;
105    
106    }