org.sakaiproject.tool.search
Class SearchResultBase

java.lang.Object
  extended byorg.sakaiproject.tool.search.SearchResultBase
All Implemented Interfaces:
SearchResultInterface
Direct Known Subclasses:
Response

public abstract class SearchResultBase
extends Object
implements SearchResultInterface

Result rendering - base class and helpers


Field Summary
protected  String _searchQuery
           
protected  Document _searchResponseDocument
           
protected  String _searchResponseString
           
 
Constructor Summary
SearchResultBase()
          Constructor
 
Method Summary
 void addItem(MatchItem item)
          Add a MatchItem object
abstract  void doParse(String database)
          Populate the search result list (each subclass should implement this)
 boolean expectedNodeCount(NodeList nodeList, int expected)
          Verify we have the expected number of Elements in a Node list
 String getFullUrl(String urlFragment)
          Form a full URL (protocol, server, arguments) from a provided URL and a previously provided base URL
 String getFullUrl(String baseUrl, String urlFragment)
          Form a full URL (protocol, server, arguments) from a base URL and provided parameters
 String getImageAttribute(Element parent, String name)
          Locate select attribute of the first matching image
 int getMatchCount()
          Return the count of matching items returned
 String getQuery()
          Fetch the original query text
 Document getSearchResponseDocument()
          Return search results as a Document
 String getSearchResponseString()
          Return search results as a String
 int getSearchStart()
          Return the starting item number for this search (one based)
 void initialize(QueryBase query)
          Save various attributes of the general search request
 Iterator iterator()
          Get an iterator to the result list
 Document parseResponseString()
          Parse the search engine response as HTML.
 void saveBaseUrl(String url)
          Save the request URL base (the server portion only)
 MatchItem[] toArray()
          Return the MatchItem list as a simple array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_searchQuery

protected String _searchQuery

_searchResponseString

protected String _searchResponseString

_searchResponseDocument

protected Document _searchResponseDocument
Constructor Detail

SearchResultBase

public SearchResultBase()
Constructor

Method Detail

doParse

public abstract void doParse(String database)
Populate the search result list (each subclass should implement this)


initialize

public void initialize(QueryBase query)
Save various attributes of the general search request

Specified by:
initialize in interface SearchResultInterface
Parameters:
query - The QueryBase extension that sent the search request

addItem

public void addItem(MatchItem item)
Add a MatchItem object

Specified by:
addItem in interface SearchResultInterface
Parameters:
item - MatchItem to add

getQuery

public String getQuery()
Fetch the original query text

Specified by:
getQuery in interface SearchResultInterface
Returns:
Search string

getSearchStart

public int getSearchStart()
Return the starting item number for this search (one based)

Specified by:
getSearchStart in interface SearchResultInterface
Returns:
Starting item number

getMatchCount

public int getMatchCount()
Return the count of matching items returned

Specified by:
getMatchCount in interface SearchResultInterface
Returns:
Item count

iterator

public Iterator iterator()
Get an iterator to the result list

Specified by:
iterator in interface SearchResultInterface
Returns:
SearchResult Iterator

toArray

public MatchItem[] toArray()
Return the MatchItem list as a simple array

Specified by:
toArray in interface SearchResultInterface
Returns:
MatchItem array

getSearchResponseString

public String getSearchResponseString()
Return search results as a String

Specified by:
getSearchResponseString in interface SearchResultInterface
Returns:
Result Document

getSearchResponseDocument

public Document getSearchResponseDocument()
Return search results as a Document

Returns:
Result Document

parseResponseString

public Document parseResponseString()
                             throws SearchException
Parse the search engine response as HTML. See initialize() (override as reqired)

Returns:
Response as a DOM Document
Throws:
SearchException

saveBaseUrl

public void saveBaseUrl(String url)
Save the request URL base (the server portion only)

Parameters:
url - Request URL (with or without parameters)

getFullUrl

public String getFullUrl(String baseUrl,
                         String urlFragment)
Form a full URL (protocol, server, arguments) from a base URL and provided parameters

Parameters:
baseUrl - The base (or template) URL
urlFragment - The (possibly) relative URL to be combined with the base
Returns:
A full URL (as a String)

getFullUrl

public String getFullUrl(String urlFragment)
Form a full URL (protocol, server, arguments) from a provided URL and a previously provided base URL

Parameters:
urlFragment - The (possibly) relative URL to be combined with the base
Returns:
A full URL (as a String)

expectedNodeCount

public boolean expectedNodeCount(NodeList nodeList,
                                 int expected)
Verify we have the expected number of Elements in a Node list

Parameters:
nodeList - List of collected Elements
expected - Number of Elements we expect to see
Returns:
true If we have the expected number Elements

getImageAttribute

public String getImageAttribute(Element parent,
                                String name)
Locate select attribute of the first matching image

Parameters:
parent - Parent element (look here for IMG tag)
name - Attribute name (src, alt, etc)
Returns:
Image name value (null if none)