org.sakaiproject.tool.search
Class ResultPageBase

java.lang.Object
  extended byorg.sakaiproject.tool.search.ResultPageBase
All Implemented Interfaces:
ResultPageInterface
Direct Known Subclasses:
Result

public class ResultPageBase
extends Object
implements ResultPageInterface

Result rendering - base class and helpers


Field Summary
protected  String _css
           
protected  String _database
           
protected  HTMLDocument _renderedResultDocument
           
protected  String _searchQuery
           
protected  String _searchResponseString
           
protected  SearchResultBase _searchResult
           
static String COMMONCSS
          default css file for results
static String FORMNAME
          Search form name
static String IMAGES_PER_PAGE
          Default image count (we'd like to place this many on a page)
 
Constructor Summary
ResultPageBase()
          Constructor
 
Method Summary
 Element addAndSelectOption(Element select, String name, String value, String selectedValue)
          Add an OPTION element, set selected attribute if desired
 Element addOption(Element select, String visibleText, String value)
          Format an Element
 HTMLDocument createRenderedResultDocument()
          Create an empty HTML rendered response document
 Element doCitationTable(Element parent, int number, MatchItem item)
          Render citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL
 Element doCitationTable(Element parent, int number, MatchItem item, String alternateText)
          Render the citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL.
 Element doCitationTable(Element parent, int number, MatchItem item, String alternateText, String saveLinkText, String saveLinkTitle)
          Render the citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL
 Element doImageTable(Element parent, int recordCount, MatchItem item)
          Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL.
 Element doImageTable(Element parent, int recordCount, MatchItem item, int maxHeight, int maxWidth)
          Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL.
 Element doImageTable(Element parent, int recordCount, MatchItem item, int maxHeight, int maxWidth, String backgroundColor)
          Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL.
 Element doInitialQueryBody()
          Render the HTML BODY and FORM for the initial query page
 Element doJavaScript(Element parent, String javaScript)
          Add a populated JavaScript segment
 Element doJavaScriptElement(Element parent)
          Add a JavaScript SCRIPT Element
 Element doNextFormLink(Element td)
          Render a link to another search page
 void doNoResultForQuery(Element table, String text)
          Render the "No results for query" table block Table The table Element we're to update
 void doNoResultForQuery(Element table, String label, String text)
          Render a "no results" table block Table The table Element we're to update
 void doPersistentLink(Element parent, String url, String urlParams, String urlText, String urlParamsForEscape)
          Render a link to add a persistent URL into the edited text document, adding default anchor and tooltip text
 void doPersistentLink(Element parent, String url, String urlParams, String urlText, String urlParamsForEscape, String anchorText, String anchorTitle)
          Render a link to add a persistent URL into the edited text document
 Element doResultPageBody()
          Render the HTML BODY portion of our response
 Element doResultPageErrorBody(String text)
          Render the HTML BODY portion of an error response
 void doResultPageFooter()
          Render the HTML BODY portion of our response
 Element doResultPageHeader()
          Render the HTML HEAD portion of our response
 Element doSearchForm(Element body)
          Render the search form
 void doSearchHeading(Element parent)
          Render page heading
 void doSearchHeading(Element parent, String heading)
          Render page heading
 void doSearchParagraph(Element parent)
          Render page heading
 void doSearchParagraph(Element parent, String paragraph)
          Render page heading
 void doSearchSourcePulldown(Element parent, String selected)
          Render the "search source" pulldown list
 Element doStandardTableSetup(Element body)
          Set up the standard HTML result table
 String getDatabase()
          Fetch the database name
 String getImageAttribute(Element parent, String name)
          Locate select attribute of the first matching image
 String getQuery()
          Fetch the search query
 HTMLDocument getRenderedResponseDocument()
          Get our rendered response Document
 String getSearchResponseString()
          Fetch the search response text
 SearchResultBase getSearchResult()
          Get search results for this query (mathing items and convenience methods)
 void initialize(QueryBase query, SearchResultBase searchResult)
          Save various attributes of the general search request
 void initialize(String database, String cssFile)
          Save attributes for initial query and error formatting (in some cases our caller won't have search results to fetch the attributes from)
 String normalizeJS(String text)
          "Normalize" text for use as a Javascript argument (eg return xxx('text');)
 String normalizeText(String text)
          "Normalize" text for display
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMONCSS

public static final String COMMONCSS
default css file for results

See Also:
Constant Field Values

IMAGES_PER_PAGE

public static final String IMAGES_PER_PAGE
Default image count (we'd like to place this many on a page)

See Also:
Constant Field Values

FORMNAME

public static final String FORMNAME
Search form name

See Also:
Constant Field Values

_css

protected String _css

_database

protected String _database

_searchQuery

protected String _searchQuery

_searchResponseString

protected String _searchResponseString

_renderedResultDocument

protected HTMLDocument _renderedResultDocument

_searchResult

protected SearchResultBase _searchResult
Constructor Detail

ResultPageBase

public ResultPageBase()
Constructor

Method Detail

initialize

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

Specified by:
initialize in interface ResultPageInterface
Parameters:
query - The QueryBase extension that sent the search request
searchResult - Search results

initialize

public void initialize(String database,
                       String cssFile)
Save attributes for initial query and error formatting (in some cases our caller won't have search results to fetch the attributes from)

Specified by:
initialize in interface ResultPageInterface
Parameters:
database - Query format
cssFile - The CSS file

getSearchResponseString

public String getSearchResponseString()
Fetch the search response text

Returns:
Search engine response

getSearchResult

public SearchResultBase getSearchResult()
Get search results for this query (mathing items and convenience methods)

Returns:
The encapsulated search result object

createRenderedResultDocument

public HTMLDocument createRenderedResultDocument()
Create an empty HTML rendered response document

Returns:
an HTML Document

getRenderedResponseDocument

public HTMLDocument getRenderedResponseDocument()
Get our rendered response Document

Returns:
Rendered HTML Document

getQuery

public String getQuery()
Fetch the search query

Returns:
Query text

getDatabase

public String getDatabase()
Fetch the database name

Returns:
DB name

doResultPageHeader

public Element doResultPageHeader()
Render the HTML HEAD portion of our response

Specified by:
doResultPageHeader in interface ResultPageInterface

doResultPageBody

public Element doResultPageBody()
Render the HTML BODY portion of our response

Specified by:
doResultPageBody in interface ResultPageInterface

doResultPageErrorBody

public Element doResultPageErrorBody(String text)
Render the HTML BODY portion of an error response

Specified by:
doResultPageErrorBody in interface ResultPageInterface
Parameters:
text - Error text

doInitialQueryBody

public Element doInitialQueryBody()
Render the HTML BODY and FORM for the initial query page

Specified by:
doInitialQueryBody in interface ResultPageInterface

doSearchHeading

public void doSearchHeading(Element parent)
Render page heading

Parameters:
parent - Add heading to this HTML element

doSearchParagraph

public void doSearchParagraph(Element parent)
Render page heading

Parameters:
parent - Add heading to this HTML element

doSearchHeading

public void doSearchHeading(Element parent,
                            String heading)
Render page heading

Parameters:
parent - Add heading to this HTML element
heading - Heading text

doSearchParagraph

public void doSearchParagraph(Element parent,
                              String paragraph)
Render page heading

Parameters:
parent - Add heading to this HTML element

doResultPageFooter

public void doResultPageFooter()
Render the HTML BODY portion of our response

Specified by:
doResultPageFooter in interface ResultPageInterface

doSearchForm

public Element doSearchForm(Element body)
Render the search form

Parameters:
body - The HTML BODY element

doNextFormLink

public Element doNextFormLink(Element td)
Render a link to another search page

Parameters:
td - Table cell we're to render to
Returns:
Anchor element (null if nothing was rendered)

doPersistentLink

public void doPersistentLink(Element parent,
                             String url,
                             String urlParams,
                             String urlText,
                             String urlParamsForEscape)
Render a link to add a persistent URL into the edited text document, adding default anchor and tooltip text

Parameters:
parent - HTML "parent" element (the link is attached here)
url - Persistent URL (link to save)
urlParams - URL parameters
urlText - Anchor text for the saved link
urlParamsForEscape - URL parameters which require escape() encoding

doPersistentLink

public void doPersistentLink(Element parent,
                             String url,
                             String urlParams,
                             String urlText,
                             String urlParamsForEscape,
                             String anchorText,
                             String anchorTitle)
Render a link to add a persistent URL into the edited text document

Parameters:
parent - HTML "parent" element (the link is attached here)
url - Persistent URL (link to save)
urlParams - URL parameters
urlText - Anchor text for the saved link
urlParamsForEscape - URL parameters which require escape() encoding
anchorText - Text for the "save this URL" link
anchorTitle - Tooltip text for the "save URL" link

doSearchSourcePulldown

public void doSearchSourcePulldown(Element parent,
                                   String selected)
Render the "search source" pulldown list

Parameters:
parent - Attach the SELECT list here
selected - Search source selected by our user (null for none)

doCitationTable

public Element doCitationTable(Element parent,
                               int number,
                               MatchItem item)
Render citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL

Parameters:
parent - Parent HTML element
number - Item number (one based, just a count)
item - Search result: one matching item

doCitationTable

public Element doCitationTable(Element parent,
                               int number,
                               MatchItem item,
                               String alternateText)
Render the citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL. Default values are supplied for the "add" persistent link text and tooltip.

Parameters:
parent - Parent HTML element
number - Item number (one based, just a count)
item - Search result: one matching item
alternateText - Alternate text for the persisted URL - this overrides MatchItem.getPersistentText()

doCitationTable

public Element doCitationTable(Element parent,
                               int number,
                               MatchItem item,
                               String alternateText,
                               String saveLinkText,
                               String saveLinkTitle)
Render the citation table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL

Parameters:
parent - Parent HTML element
number - Item number (one based, just a count)
item - Search result: one matching item
alternateText - Alternate text for the persisted URL - this overrides MatchItem.getPersistentText()
saveLinkText - Text label for the "add this link" anchor
saveLinkTitle - Tool tip for the "add this link" anchor

doImageTable

public Element doImageTable(Element parent,
                            int recordCount,
                            MatchItem item)
Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL. Images are rendered three across; each is placed in a table using a default size and background color.

Parameters:
parent - Parent HTML element
recordCount - Image count
item - Search results: one matching item

doImageTable

public Element doImageTable(Element parent,
                            int recordCount,
                            MatchItem item,
                            int maxHeight,
                            int maxWidth)
Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL. Images are rendered three across; each is placed in a table of specified size with the default background color.

Parameters:
parent - Parent HTML element
recordCount - Image count
item - Search results: one matching item
maxHeight - Maximum image height
maxWidth - Maximum image width (this may interact with the table width specified in doStandardTableSetup()

doImageTable

public Element doImageTable(Element parent,
                            int recordCount,
                            MatchItem item,
                            int maxHeight,
                            int maxWidth,
                            String backgroundColor)
Render image table HTML (a small table containing the both the original anchor (for preview) and an "Add" link used to save the persistent URL. Images are rendered three across; each is placed in a table of specified size and background color.

Parameters:
parent - Parent HTML element
recordCount - Image count (caller should start at one and increment)
item - Search results: one matching item
maxHeight - Maximum image height
maxWidth - Maximum image width (this may interact with the table width specified in doStandardTableSetup()
backgroundColor - Color for image table-cell ("#ffffff") - specify null for none

doStandardTableSetup

public Element doStandardTableSetup(Element body)
Set up the standard HTML result table

Parameters:
body - The HTML body element

doJavaScriptElement

public Element doJavaScriptElement(Element parent)
Add a JavaScript SCRIPT Element

Parameters:
parent - Add the SCRIPT here
Returns:
The new SCRIPT element

doJavaScript

public Element doJavaScript(Element parent,
                            String javaScript)
Add a populated JavaScript segment

Parameters:
parent - Add the SCRIPT here
javaScript - javaScript The JavaScript text
Returns:
The new SCRIPT element

doNoResultForQuery

public void doNoResultForQuery(Element table,
                               String text)
Render the "No results for query" table block Table The table Element we're to update

Parameters:
text - Optional query text (null for none)

doNoResultForQuery

public void doNoResultForQuery(Element table,
                               String label,
                               String text)
Render a "no results" table block Table The table Element we're to update

Parameters:
label - Core message (eg "Error encountered", "No match", etc)
text - Additional text (null for none)

normalizeText

public String normalizeText(String text)
"Normalize" text for display

Returns:
Trimmed original text, with " replacing "

normalizeJS

public String normalizeJS(String text)
"Normalize" text for use as a Javascript argument (eg return xxx('text');)

Returns:
Trimmed original text, with " replacing '"', \' replacing ', %27

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)

addOption

public Element addOption(Element select,
                         String visibleText,
                         String value)
Format an Element

Parameters:
select - The select element we're to update
value - The option value
visibleText - Display text for this option
Returns:
The option Element

addAndSelectOption

public Element addAndSelectOption(Element select,
                                  String name,
                                  String value,
                                  String selectedValue)
Add an OPTION element, set selected attribute if desired

Parameters:
select - SELECT element
name - Option name
value - Option value
Returns:
The option Element