| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| QueryFactoryImpl |
|
| 0.0;0 |
| 1 | /* Copyright (2006-2008) Schibsted Søk AS | |
| 2 | * This file is part of SESAT. | |
| 3 | * | |
| 4 | * SESAT is free software: you can redistribute it and/or modify | |
| 5 | * it under the terms of the GNU Affero General Public License as published by | |
| 6 | * the Free Software Foundation, either version 3 of the License, or | |
| 7 | * (at your option) any later version. | |
| 8 | * | |
| 9 | * SESAT is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | * GNU Affero General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Affero General Public License | |
| 15 | * along with SESAT. If not, see <http://www.gnu.org/licenses/>. | |
| 16 | ||
| 17 | */ | |
| 18 | package no.sesat.search.run; | |
| 19 | ||
| 20 | ||
| 21 | import no.sesat.search.datamodel.DataModel; | |
| 22 | import no.sesat.search.datamodel.request.ParametersDataObject; | |
| 23 | import no.sesat.search.site.SiteKeyedFactoryInstantiationException; | |
| 24 | import org.apache.log4j.Logger; | |
| 25 | ||
| 26 | import javax.servlet.http.Cookie; | |
| 27 | import javax.servlet.http.HttpServletRequest; | |
| 28 | import javax.servlet.http.HttpServletResponse; | |
| 29 | ||
| 30 | ||
| 31 | /** | |
| 32 | * QueryFactoryImpl is part of no.sesat.search.query. | |
| 33 | * Use this class to create an instance of a RunningQuery. | |
| 34 | * | |
| 35 | * <p/> | |
| 36 | * TODO Instantiate a RunningQuery specified in the mode. With default as RunningQueryImpl. | |
| 37 | * | |
| 38 | * @version $Id: QueryFactoryImpl.java 6637 2008-05-26 12:07:21Z ssmiweve $ | |
| 39 | */ | |
| 40 | 0 | public final class QueryFactoryImpl extends QueryFactory { |
| 41 | ||
| 42 | 0 | private static final Logger LOG = Logger.getLogger(QueryFactoryImpl.class); |
| 43 | ||
| 44 | /** | |
| 45 | * Create a new instance of running query. The implementation can | |
| 46 | * be RunningWebQuery for example. | |
| 47 | * | |
| 48 | * @param cxt | |
| 49 | * @param request with parameters populated with search params | |
| 50 | * @return instance of RunningQuery | |
| 51 | * @throws SiteKeyedFactoryInstantiationException | |
| 52 | */ | |
| 53 | public RunningQuery createQuery( | |
| 54 | final RunningQuery.Context cxt, | |
| 55 | final HttpServletRequest request, | |
| 56 | final HttpServletResponse response) throws SiteKeyedFactoryInstantiationException { | |
| 57 | ||
| 58 | 0 | final DataModel datamodel = (DataModel) request.getSession().getAttribute(DataModel.KEY); |
| 59 | 0 | final ParametersDataObject parametersDO = datamodel.getParameters(); |
| 60 | ||
| 61 | 0 | final String qParam = null != parametersDO.getValue("q") ? parametersDO.getValue("q").getString() : ""; |
| 62 | ||
| 63 | 0 | final RunningQueryImpl query = new RunningWebQuery(cxt, qParam, request, response); |
| 64 | ||
| 65 | 0 | final String cParam = cxt.getSearchTab().getKey(); |
| 66 | ||
| 67 | ||
| 68 | /** TODO Replace the code in createQuery with a RunningQueryTransformer sub-module that is | |
| 69 | * configured per mode and permits manipulation of the datamodel before the RunningQuery is constructed. | |
| 70 | **/ | |
| 71 | 0 | if ("nm".equals(cParam)) { |
| 72 | 0 | final Cookie[] cookies = request.getCookies(); |
| 73 | 0 | if (cookies != null) { |
| 74 | 0 | for (Cookie cookie : cookies) { |
| 75 | 0 | if ("myNews".equals(cookie.getName().trim())) { |
| 76 | 0 | LOG.debug("Adding cookie: " + cookie.getName() + "=" + cookie.getValue()); |
| 77 | 0 | datamodel.getJunkYard().getValues().put("myNews", cookie.getValue()); |
| 78 | } | |
| 79 | } | |
| 80 | } | |
| 81 | } | |
| 82 | 0 | return query; |
| 83 | } | |
| 84 | } |