001: /**********************************************************************************
002: *
003: * Copyright (c) 2003, 2004 The Regents of the University of Michigan, Trustees of Indiana University,
004: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
005: *
006: * Licensed under the Educational Community License Version 1.0 (the "License");
007: * By obtaining, using and/or copying this Original Work, you agree that you have read,
008: * understand, and will comply with the terms and conditions of the Educational Community License.
009: * You may obtain a copy of the License at:
010: *
011: * http://cvs.sakaiproject.org/licenses/license_1_0.html
012: *
013: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
014: * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
015: * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
016: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
017: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
018: *
019: **********************************************************************************/package edu.indiana.lib.twinpeaks.search;
020:
021: import edu.indiana.lib.twinpeaks.util.*;
022:
023: import java.util.*;
024: import javax.servlet.*;
025: import javax.servlet.http.*;
026:
027: import org.w3c.dom.*;
028:
029: /**
030: * This module provides a single, core implementation of QueryInterface.
031: * It provides "lowest common denominator" functionality.
032: *
033: * In reality, each search application should extend QueryBase
034: * and implement appropriate methods. See HttpTransactionQueryBase.java
035: * for an example.
036: */
037: public abstract class QueryBase implements QueryInterface {
038:
039: private static org.apache.commons.logging.Log _log = LogUtils
040: .getLog(QueryBase.class);
041: /*
042: * Request parameters
043: */
044: private Map _parameterMap = null;
045:
046: /*
047: * Abstract methods
048: */
049:
050: /**
051: * Fetch the current search URL
052: * @return The URL (as a String)
053: */
054: public abstract String getUrl();
055:
056: /**
057: * Fetch the current search text
058: * @return The search string
059: */
060: public abstract String getSearchString();
061:
062: /*
063: * Base implementations
064: */
065:
066: /**
067: * Populate user request parameters
068: * @param parameterMap Request details as a map (name=value pairs)
069: */
070: protected void populateRequestParameters(Map parameterMap) {
071: _parameterMap = parameterMap;
072: }
073:
074: /**
075: * Parse user request parameters. This base method supports only
076: * the standard, simple query format. Override if necessary.
077: * @param parameterMap Request details (name=value pairs)
078: */
079: public void parseRequest(Map parameterMap) {
080:
081: populateRequestParameters(parameterMap);
082:
083: if (getRequestParameter("database") == null) {
084: throw new IllegalArgumentException("Missing database name");
085: }
086:
087: if (getRequestParameter("searchString") == null) {
088: throw new IllegalArgumentException("Missing search text");
089: }
090: }
091:
092: /**
093: * Fetch a request parameter by name
094: * @param name Parameter name
095: * @return Parameter value
096: */
097: public String getRequestParameter(String name) {
098: return (String) _parameterMap.get(name);
099: }
100:
101: /**
102: * Fetch a request parameter by name
103: * @param name Parameter name
104: * @return Parameter value (an Integer)
105: */
106: public Integer getIntegerRequestParameter(String name) {
107: return (Integer) _parameterMap.get(name);
108: }
109:
110: /**
111: * Fetch the entire request parameter Map
112: * @return Parameter Map
113: */
114: public Map getRequestParameterMap() {
115: return _parameterMap;
116: }
117: }
|