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.portlet.journal.search;
016    
017    import com.liferay.portal.kernel.dao.search.SearchContainer;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portlet.journal.model.JournalTemplate;
020    
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    import javax.portlet.PortletRequest;
025    import javax.portlet.PortletURL;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class TemplateSearch extends SearchContainer<JournalTemplate> {
031    
032            static List<String> headerNames = new ArrayList<String>();
033    
034            static {
035                    headerNames.add("id");
036                    headerNames.add("name");
037                    headerNames.add("description");
038            }
039    
040            public static final String EMPTY_RESULTS_MESSAGE =
041                    "no-templates-were-found";
042    
043            public TemplateSearch(
044                    PortletRequest portletRequest, int delta, PortletURL iteratorURL) {
045    
046                    super(
047                            portletRequest, new TemplateDisplayTerms(portletRequest),
048                            new TemplateSearchTerms(portletRequest), DEFAULT_CUR_PARAM, delta,
049                            iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);
050    
051                    TemplateDisplayTerms displayTerms =
052                            (TemplateDisplayTerms)getDisplayTerms();
053    
054                    iteratorURL.setParameter(
055                            TemplateDisplayTerms.DESCRIPTION, displayTerms.getDescription());
056                    iteratorURL.setParameter(
057                            TemplateDisplayTerms.GROUP_IDS,
058                            StringUtil.merge(displayTerms.getGroupIds()));
059                    iteratorURL.setParameter(
060                            TemplateDisplayTerms.NAME, displayTerms.getName());
061                    iteratorURL.setParameter(
062                            TemplateDisplayTerms.STRUCTURE_ID, displayTerms.getStructureId());
063                    iteratorURL.setParameter(
064                            TemplateDisplayTerms.TEMPLATE_ID, displayTerms.getTemplateId());
065            }
066    
067            public TemplateSearch(
068                    PortletRequest portletRequest, PortletURL iteratorURL) {
069    
070                    this(portletRequest, DEFAULT_DELTA, iteratorURL);
071            }
072    
073    }