com.sfs.whichdoctor.search.http.GroupBasicInputHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.whichdoctor.search.http.GroupBasicInputHandler.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.whichdoctor.search.http;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.sfs.DataFilter;
import com.sfs.beans.UserBean;
import com.sfs.whichdoctor.beans.GroupBean;
import com.sfs.whichdoctor.beans.SearchBean;
import com.sfs.whichdoctor.search.sql.GroupSqlHandler;

/**
 * The Class GroupBasicInputHandler.
 *
 * @author David Harrison
 */
public class GroupBasicInputHandler extends InputHandlerBase {

    /** The group sql handler. */
    @Resource
    private GroupSqlHandler groupSqlHandler;

    /**
     * Process the incoming HttpRequest for search parameters.
     *
     * @param request the request
     * @param user the user
     *
     * @return the search bean
     */
    public final SearchBean process(final HttpServletRequest request, final UserBean user) {

        SearchBean search = groupSqlHandler.initiate(user);

        String strBasicSearch = DataFilter.getHtml(request.getParameter("Search"));

        GroupBean searchCriteria = (GroupBean) search.getSearchCriteria();

        if (StringUtils.isNotBlank(strBasicSearch)) {
            // Replace ` with ' (` is given by dynamic searches in place of
            // ' due to Javascript issues
            searchCriteria.setBasicSearch(StringUtils.replace(strBasicSearch.trim(), "`", "'"));
        }
        search.setSearchCriteria(searchCriteria);

        return search;
    }

    /**
     * Return a standard search bean.
     *
     * @param user the user
     *
     * @return the search bean
     */
    public final SearchBean process(final UserBean user) {

        SearchBean search = groupSqlHandler.initiate(user);

        GroupBean searchCriteria = (GroupBean) search.getSearchCriteria();

        search.setSearchCriteria(searchCriteria);

        return search;
    }
}