org.histpop.ohpr.frames
Class SearchFrame

java.lang.Object
  extended by org.histpop.ohpr.frames.SearchFrame
All Implemented Interfaces:
BasicFrame

public class SearchFrame
extends java.lang.Object
implements BasicFrame

A frame class for generating a dymamic view for listing search results. The view is created from a HTML template. The template contains some placeholders which are replaced by dynamically generated HTML-code for the final output.


Field Summary
static java.lang.String DATE
          URL argument name for the 'Date' parameter
static java.lang.String DEFAULT_SORTING
           
static java.lang.String EXPRESSION_KIND
          URL argument name for the 'expressionKind' parameter
static java.lang.String GEOGRAPHY
          URL argument name for the 'Geography' parameter
static java.lang.String RANGE
          URL argument name for the 'range' parameter
static java.lang.String RESOURCE_TYPE
          URL argument name for the 'ResourceType' parameter
static java.lang.String SEARCH
          URL argument name for the 'search' parameter
static java.lang.String SEARCH_CONTENT
          URL argument name for the 'SearchContent' parameter
static java.lang.String SEARCH_TERMS
          URL argument name for the 'SearchTerms' parameter
static java.lang.String SIMPLE
          URL argument name for the 'simple' parameter
static java.lang.String SORTING
          URL argument name for the 'Sorting' parameter
 
Constructor Summary
SearchFrame()
           
 
Method Summary
static java.lang.String[] adjustedGeography(java.lang.String[] geography)
          Adjust the submitted geographies.
static java.lang.String createBrowseTreeView(SearchNode node, SearchNode activeNode, ServerContext ctx)
          Create the XHTML browse tree starting starting from a given node.
static java.lang.String createBrowseTreeViewGraphical(SearchNode node, SearchNode activeNode, ServerContext ctx)
          Create the XHTML browse tree starting starting from a given node (Graphical version).
protected  java.lang.String createDocURL(BrowseNode treeNode, MasterNumber title, ServerContext ctx)
          Create a URL for the target document (Search version) viewer.
protected static java.lang.String createIndentationGraphical(BrowseNode node)
          Create an indentation according to the browse tree node's level
protected  java.lang.String createNavigatorView(TitleQueryState titlesState, ServerContext ctx)
          Create a titles navigator view.
protected static java.lang.String createPageURL(BrowseNode treeNode, MasterNumber title, java.lang.Integer firstHit, ServerContext ctx)
          Create a URL for the target page (Search version) viewer.
protected static java.lang.String createPageURL(BrowseNode treeNode, MasterNumber title, ServerContext ctx)
          Create a URL for the target page (Search version) viewer.
protected static java.lang.String createSectionTreeURL(SectionQueryNode sectionNode, java.lang.String tocState, ServerContext ctx)
          Create a URL for the search results list including the arguments for a specific master number and its section tree.
protected static java.lang.String createSectionTreeURL(TitleQueryNode titleNode, java.lang.String tocSeq, java.lang.String tocState, ServerContext ctx)
          Create a URL for the search results list including the arguments for a specific master number and its section tree.
protected  java.lang.String createTitlesView(TitleQueryState titlesState, ServerContext ctx)
          Create a view of the current block of titles.
protected  java.lang.String createTitlesViewGraphical(TitleQueryState titlesState, ServerContext ctx)
          Create a view of the current block of titles.
protected static java.lang.String createURL(BrowseNode node, boolean active, java.lang.String treestate, java.lang.Integer titlepos, ServerContext ctx)
          Create the URL to be used for a LH menu browse tree node.
 HTMLHandler display(java.lang.Object result, ServerContext ctx)
          Create an HTML view for search results requests.
protected static java.lang.String generateFilterExpr(java.lang.String[] resourceType, java.lang.String[] geography, java.lang.String date)
          generate a SQL filter expression from the submitted resource types, dates, and geographies.
protected static java.lang.String generateOrderExpr(java.lang.String sorting)
          Generate the SQL order list from the submitted sorting value.
protected static java.lang.String generateRange(java.lang.String url, int titlesCount, ServerContext ctx)
           
protected static java.lang.String generateRefineLink(java.lang.String url, ServerContext ctx)
           
protected static java.lang.String[] generateSearchExpr(java.lang.String searchTerms, java.lang.String searchContent, java.lang.String expressionKind, boolean simple)
          Generate SQL expressions from the submitted search terms, search content, and expression kind.
protected  java.lang.String generateSectionsView(TitleQueryNode titleNode, ServerContext ctx)
          Generate a sections tree view for a master number volume.
protected static java.lang.String removedArg(java.lang.String url, java.lang.String argName)
           
static void validate(java.lang.String[] resourceType, java.lang.String searchContent, java.lang.String expressionKind, java.lang.String[] geography, java.lang.String sorting)
          Validate some URL arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_TYPE

public static final java.lang.String RESOURCE_TYPE
URL argument name for the 'ResourceType' parameter

See Also:
Constant Field Values

SEARCH_TERMS

public static final java.lang.String SEARCH_TERMS
URL argument name for the 'SearchTerms' parameter

See Also:
Constant Field Values

SEARCH_CONTENT

public static final java.lang.String SEARCH_CONTENT
URL argument name for the 'SearchContent' parameter

See Also:
Constant Field Values

EXPRESSION_KIND

public static final java.lang.String EXPRESSION_KIND
URL argument name for the 'expressionKind' parameter

See Also:
Constant Field Values

DATE

public static final java.lang.String DATE
URL argument name for the 'Date' parameter

See Also:
Constant Field Values

GEOGRAPHY

public static final java.lang.String GEOGRAPHY
URL argument name for the 'Geography' parameter

See Also:
Constant Field Values

SORTING

public static final java.lang.String SORTING
URL argument name for the 'Sorting' parameter

See Also:
Constant Field Values

SIMPLE

public static final java.lang.String SIMPLE
URL argument name for the 'simple' parameter

See Also:
Constant Field Values

RANGE

public static final java.lang.String RANGE
URL argument name for the 'range' parameter

See Also:
Constant Field Values

SEARCH

public static final java.lang.String SEARCH
URL argument name for the 'search' parameter

See Also:
Constant Field Values

DEFAULT_SORTING

public static final java.lang.String DEFAULT_SORTING
See Also:
Constant Field Values
Constructor Detail

SearchFrame

public SearchFrame()
Method Detail

createURL

protected static java.lang.String createURL(BrowseNode node,
                                            boolean active,
                                            java.lang.String treestate,
                                            java.lang.Integer titlepos,
                                            ServerContext ctx)
Create the URL to be used for a LH menu browse tree node.

Parameters:
node - The browse tree node for which to create a URL.
active - TRUE if tree node is to become an active one
treestate - Only needed if active=TRUE. Values can be one of 'contract', 'expand', 'expandnew'.
titlepos - The cardinal position of the first title to be displayed in the main content pane. Default is zero.
ctx - The server context with HTTP request, URL arguments, and HTTP response

createIndentationGraphical

protected static java.lang.String createIndentationGraphical(BrowseNode node)
Create an indentation according to the browse tree node's level


createBrowseTreeViewGraphical

public static java.lang.String createBrowseTreeViewGraphical(SearchNode node,
                                                             SearchNode activeNode,
                                                             ServerContext ctx)
Create the XHTML browse tree starting starting from a given node (Graphical version).

Parameters:
node - The starting tree node
activeNode - The new active tree node
ctx - Server context with HTTP request, URL arguments, HTTP response etc.
Returns:
The XHTML tree view

createBrowseTreeView

public static java.lang.String createBrowseTreeView(SearchNode node,
                                                    SearchNode activeNode,
                                                    ServerContext ctx)
Create the XHTML browse tree starting starting from a given node.

Parameters:
node - The starting tree node
activeNode - The new active tree node
ctx - Server context with HTTP request, URL arguments, HTTP response etc.
Returns:
The XHTML tree view

validate

public static void validate(java.lang.String[] resourceType,
                            java.lang.String searchContent,
                            java.lang.String expressionKind,
                            java.lang.String[] geography,
                            java.lang.String sorting)
                     throws java.lang.Exception
Validate some URL arguments. Throw an exception with an error message if there is a wrong or missing URL argument.

Throws:
java.lang.Exception

generateSearchExpr

protected static java.lang.String[] generateSearchExpr(java.lang.String searchTerms,
                                                       java.lang.String searchContent,
                                                       java.lang.String expressionKind,
                                                       boolean simple)
                                                throws java.lang.Exception
Generate SQL expressions from the submitted search terms, search content, and expression kind.

Parameters:
searchTerms - The submitted search terms value.
searchContent - The submitted search content. Possible values are All or Metadata
expressionKind - The expression kind of the submitted search terms value. Possible values are All or Any or Boolean or Exact
simple - true if simple search, false if advanced search
Returns:
The generated SQL expressions and interpreted search expression.
Throws:
java.lang.Exception

generateFilterExpr

protected static java.lang.String generateFilterExpr(java.lang.String[] resourceType,
                                                     java.lang.String[] geography,
                                                     java.lang.String date)
                                              throws java.lang.Exception
generate a SQL filter expression from the submitted resource types, dates, and geographies.

Parameters:
resourceType - A validated array of resource type names.
date - A validated date expression.
geography - A validated array of geography codes.
Returns:
A combined SQL filter expression.
Throws:
java.lang.Exception

generateOrderExpr

protected static java.lang.String generateOrderExpr(java.lang.String sorting)
Generate the SQL order list from the submitted sorting value.

Parameters:
sorting - The submitted sorting value.
Returns:
SQL order list.

createNavigatorView

protected java.lang.String createNavigatorView(TitleQueryState titlesState,
                                               ServerContext ctx)
Create a titles navigator view. Only a limited number of titles can be displayed at a time, so it has to create links to the previous and next block of titles, as well as links to all the title blocks in between.

Parameters:
titlesState - All the titles associated with the owning tree node.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A XHTML titles navigator.

createPageURL

protected static java.lang.String createPageURL(BrowseNode treeNode,
                                                MasterNumber title,
                                                ServerContext ctx)
                                         throws ServerException
Create a URL for the target page (Search version) viewer.

Parameters:
treeNode - The browse tree node for which to create a URL.
title - The master number title.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A URL for the target page browser.
Throws:
ServerException

createPageURL

protected static java.lang.String createPageURL(BrowseNode treeNode,
                                                MasterNumber title,
                                                java.lang.Integer firstHit,
                                                ServerContext ctx)
                                         throws ServerException
Create a URL for the target page (Search version) viewer.

Parameters:
treeNode - The browse tree node for which to create a URL.
title - The master number title.
firstHit - The page sequence number for the first hit.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A URL for the target page browser.
Throws:
ServerException

createDocURL

protected java.lang.String createDocURL(BrowseNode treeNode,
                                        MasterNumber title,
                                        ServerContext ctx)
                                 throws ServerException
Create a URL for the target document (Search version) viewer.

Parameters:
treeNode - The browse tree node for which to create a URL.
title - The master number title.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A URL for the target page browser.
Throws:
ServerException

createSectionTreeURL

protected static java.lang.String createSectionTreeURL(SectionQueryNode sectionNode,
                                                       java.lang.String tocState,
                                                       ServerContext ctx)
                                                throws ServerException
Create a URL for the search results list including the arguments for a specific master number and its section tree.

Parameters:
sectionNode - A section tree node.
tocState - The type of update to be applied to the sections tree. Must be one of expand, expandnew, close, or expandall. If the value is expandnew or expandall than the the whole sections tree is reset to its default state or is fully expanded.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A URL for the target page browser.
Throws:
ServerException

createSectionTreeURL

protected static java.lang.String createSectionTreeURL(TitleQueryNode titleNode,
                                                       java.lang.String tocSeq,
                                                       java.lang.String tocState,
                                                       ServerContext ctx)
                                                throws ServerException
Create a URL for the search results list including the arguments for a specific master number and its section tree.

Parameters:
titleNode - A volume item containing the persistent object of the master number item and the sections state.
tocSeq - Section sequence number.
tocState - The type of update to be applied to the sections tree. Must be one of expand, expandnew, close, or expandall. If the value is expandnew or expandall than the the whole sections tree is reset to its default state or is fully expanded.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A URL for the target page browser.
Throws:
ServerException

generateSectionsView

protected java.lang.String generateSectionsView(TitleQueryNode titleNode,
                                                ServerContext ctx)
                                         throws ServerException
Generate a sections tree view for a master number volume.

Parameters:
titleNode - A volume item containing the persistent object of the master number item and the sections state.
Returns:
An HTML view of the sections tree.
Throws:
ServerException

createTitlesView

protected java.lang.String createTitlesView(TitleQueryState titlesState,
                                            ServerContext ctx)
                                     throws ServerException
Create a view of the current block of titles.

Parameters:
titlesState - All the titles associated with the owning tree node.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A XHTML view of a sub-list of titles.
Throws:
ServerException

createTitlesViewGraphical

protected java.lang.String createTitlesViewGraphical(TitleQueryState titlesState,
                                                     ServerContext ctx)
                                              throws ServerException
Create a view of the current block of titles.

Parameters:
titlesState - All the titles associated with the owning tree node.
ctx - The server context with HTTP request, URL arguments, and HTTP response
Returns:
A XHTML view of a sub-list of titles.
Throws:
ServerException

generateRefineLink

protected static java.lang.String generateRefineLink(java.lang.String url,
                                                     ServerContext ctx)

removedArg

protected static java.lang.String removedArg(java.lang.String url,
                                             java.lang.String argName)

generateRange

protected static java.lang.String generateRange(java.lang.String url,
                                                int titlesCount,
                                                ServerContext ctx)

adjustedGeography

public static java.lang.String[] adjustedGeography(java.lang.String[] geography)
Adjust the submitted geographies. If they are not there, assume that all of them are to be used.


display

public HTMLHandler display(java.lang.Object result,
                           ServerContext ctx)
                    throws java.lang.Exception
Create an HTML view for search results requests. It uses an HTML template with placeholders which are replaced by dynamcially generated HTML. The following URL arguments are expected after the '?' character:

ResourceType=Census or Legislation or Essays or Registrar General or TNA
SearchTerms=the actual search terms
SearchContent=All or Metadata
expressionKind=All or Any or Exact or Boolean
Date=the year or year range
Geography=E or W or S or I or C
Sorting=resource-type date geography or resource-type geography date or geography resource-type date
path=path to search tree node
treestate=contract or expand or expandnew
active=yes or no
titlepos=position of first title to be displayed (default is zero)
range=all (use grouped results listing if not specified)

Some additonal URL arguments are only needed when browsing through a sections tree of a master number item:
mno=master number
tocstate=expand or expandnew or close or expandall
tocseq=Table of Contents sequence number

Specified by:
display in interface BasicFrame
Parameters:
result - The result from a server method, always NULL, unless exception thrown.
ctx - The server context containing the request, response, and current session objects.
Returns:
An HTML handler containing the generated HTML ready to be sent back as a response by the servlet controller.
Throws:
java.lang.Exception