Package edu.indiana.lib.twinpeaks.search
Class HttpTransactionQueryBase
- java.lang.Object
-
- edu.indiana.lib.twinpeaks.search.QueryBase
-
- edu.indiana.lib.twinpeaks.search.HttpTransactionQueryBase
-
- All Implemented Interfaces:
HttpTransactionQueryInterface,QueryInterface
- Direct Known Subclasses:
Query,SruQueryBase,Web2Query
public abstract class HttpTransactionQueryBase extends QueryBase implements HttpTransactionQueryInterface
Base class for HTTP search activities
-
-
Field Summary
-
Fields inherited from interface edu.indiana.lib.twinpeaks.search.HttpTransactionQueryInterface
METHOD_GET, METHOD_POST, REDIRECT_AUTOMATIC, REDIRECT_MANAGED, REDIRECT_MANAGED_SINGLESTEP
-
-
Constructor Summary
Constructors Constructor Description HttpTransactionQueryBase()Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearParameters()Clear the parameter listElementgetBody(Document pageDocument)Locate the HTML BODY element in the page documentbooleangetFollowRedirects()Should URLConnection follow redirects?ElementgetFormElement(Document pageDocument, String formName)Find a named FORM elementStringgetParameter(String name)Get a named parameterStringgetParameterName(String value)Get the parameter name associated with the 1st occurance of this valueDocumentgetQueryDocument(String consumer)Fetch the final query form as a DOM documentStringgetQueryMethod()Fetch the current HTTP query methodStringgetQueryUrl(String consumer)Fetch the URL for the querybyte[]getResponseBytes()Get the server response textStringgetResponseCharacterSet()Fetch the response character setDocumentgetResponseDocument()Parse the server response (override as required)StringgetResponseHeader(String name)Fetch a named HTTP response parameterStringgetResponseString()Get the server response textStringgetSearchString()Fetch the current search textSessionContextgetSessionContext()Get the SessionContext object for this userStringgetSessionParameter(String consumer, String name)Fetch the requested general purpose parameterObjectgetSessionValue(String consumer, String name)Fetch the requested general purpose parameterStringgetUrl()Fetch the current search URLvoidinitialize(SessionContext session)One time initializationURLnewFullUrl(String baseComponent, String relativeComponent)Construct a new URL from base and relative componentsvoidremoveQueryUrl(String consumer)Delete a stored query URLvoidremoveSessionParameter(String consumer, String name)Delete the requested general purpose parametervoidsetDefaultCharacterSet(String cs)Set the default character set for this transactionvoidsetParameter(String name, String value)Set up a name=value pairvoidsetParametersFromFormInputs(Document pageDocument, String formName, List nameList)Produce a target URL for this query by combining the form "action" value with the base URL of the query pagevoidsetParametersFromInputNames(Document pageDocument, List nameList)Set query parameters based on page-wide INPUTsvoidsetParametersFromInputs(Document pageDocument, List nameList)Deprecated.Replaced by#setParametersFromInputNames()voidsetParametersFromInputValues(Document pageDocument, List nameList)Set query parameters based on page-wide INPUTsvoidsetParametersFromNameList(NodeList nodeList, List nameList)Set query parameters based on element names (save name=value pairs)voidsetParametersFromValueList(NodeList nodeList, List nameList)Set query parameters based on element values (save name=value pairs)voidsetPreserveBaseUrlFile(boolean state)Set the "file preservation state" for getBaseUrlSpecification()voidsetQueryDocument(String consumer, Document queryForm)Save the final query form as a DOM documentvoidsetQueryMethod(String method)Set the HTTP query method (post or get)voidsetQueryUrl(String consumer, String queryUrl)Save the URL for the query pagevoidsetRedirectBehavior(int behavior)Establish a mechanism for handling redirectsvoidsetSearchString(String searchString)Specify the search textvoidsetSessionParameter(String consumer, String name, String value)Save a general purpose parametervoidsetSessionValue(String consumer, String name, Object value)Save a general purpose parametervoidsetUrl(String url)Set search URLvoidsetUrl(URL url)Set search URLvoidsetUrlFromAnchor(Element anchor)Produce a target URL for this query by combining an anchor "href" value with the base URL of the query pagevoidsetUrlFromForm(Document pageDocument, String formName)Produce a target URL for this query by combining the form "action" value with the base URL of the query pageintsubmit()Submit a request (POST or GET) and read the response.-
Methods inherited from class edu.indiana.lib.twinpeaks.search.QueryBase
getIntegerRequestParameter, getRequestParameter, getRequestParameterMap, parseRequest, populateRequestParameters
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface edu.indiana.lib.twinpeaks.search.QueryInterface
doQuery
-
-
-
-
Method Detail
-
initialize
public void initialize(SessionContext session)
One time initialization- Specified by:
initializein interfaceQueryInterface- Parameters:
session- SessionContext object
-
setUrl
public void setUrl(String url)
Set search URL- Parameters:
url- URL string
-
setUrl
public void setUrl(URL url)
Set search URL- Parameters:
url- URL object
-
getUrl
public String getUrl()
Fetch the current search URL
-
setSearchString
public void setSearchString(String searchString)
Specify the search text- Parameters:
searchString- Text to look for
-
getSearchString
public String getSearchString()
Fetch the current search text- Specified by:
getSearchStringin classQueryBase- Returns:
- The search string
-
setQueryMethod
public void setQueryMethod(String method)
Set the HTTP query method (post or get)- Specified by:
setQueryMethodin interfaceHttpTransactionQueryInterface- Parameters:
method-METHOD_POSTorMETHOD_GET
-
getQueryMethod
public String getQueryMethod()
Fetch the current HTTP query method- Returns:
- The method (as text)
-
getResponseHeader
public String getResponseHeader(String name)
Fetch a named HTTP response parameter- Parameters:
name- Parameter name- Returns:
- Parameter value
-
setDefaultCharacterSet
public void setDefaultCharacterSet(String cs)
Set the default character set for this transaction- Parameters:
cs- Character set (UTF-8, ISO-8859-1, etc)
-
getResponseCharacterSet
public String getResponseCharacterSet()
Fetch the response character set- Returns:
- Character set designation (as a String)
-
setQueryUrl
public void setQueryUrl(String consumer, String queryUrl)
Save the URL for the query page- Parameters:
consumer- A unique name for the "user" of this objectqueryUrl- Address of the final query page
-
getQueryUrl
public String getQueryUrl(String consumer)
Fetch the URL for the query- Parameters:
consumer- A unique name for the "user" of this object- Returns:
- Address of the final query page
-
removeQueryUrl
public void removeQueryUrl(String consumer)
Delete a stored query URL- Parameters:
consumer- A unique name for the "user" of this object
-
setQueryDocument
public void setQueryDocument(String consumer, Document queryForm)
Save the final query form as a DOM document- Parameters:
consumer- A unique name for the "user" of this objectqueryForm- Query page as a DOM document
-
getQueryDocument
public Document getQueryDocument(String consumer)
Fetch the final query form as a DOM document- Parameters:
consumer- A unique name for the "user" of this object- Returns:
- Query form (as a DOM document)
-
setSessionParameter
public void setSessionParameter(String consumer, String name, String value)
Save a general purpose parameter- Parameters:
consumer- A unique name for the "user" of this objectname- Parameter namevalue- Parameter value
-
getSessionParameter
public String getSessionParameter(String consumer, String name)
Fetch the requested general purpose parameter- Parameters:
consumer- A unique name for the "user" of this objectname- Parameter name- Returns:
- Parameter value (null if none)
-
setSessionValue
public void setSessionValue(String consumer, String name, Object value)
Save a general purpose parameter- Parameters:
consumer- A unique name for the "user" of this objectname- Parameter namevalue- Parameter value
-
removeSessionParameter
public void removeSessionParameter(String consumer, String name)
Delete the requested general purpose parameter- Parameters:
consumer- A unique name for the "user" of this objectname- Parameter name
-
getSessionValue
public Object getSessionValue(String consumer, String name)
Fetch the requested general purpose parameter- Parameters:
consumer- A unique name for the "user" of this objectname- Parameter name- Returns:
- Parameter value (null if none)
-
getSessionContext
public SessionContext getSessionContext()
Get the SessionContext object for this user- Returns:
- The current SessionContext
-
setRedirectBehavior
public void setRedirectBehavior(int behavior) throws SearchExceptionEstablish a mechanism for handling redirects- Specified by:
setRedirectBehaviorin interfaceHttpTransactionQueryInterface- Parameters:
behavior- Specifies the desired behavior. Use one of:- REDIRECT_AUTOMATIC -
URLConnectionhandles all redirects - REDIRECT_MANAGED - The
submit()code handles any redirects - REDIRECT_MANAGED_SINGLESTEP - The caller will handle each redirect
- REDIRECT_AUTOMATIC -
- Throws:
SearchException
-
setPreserveBaseUrlFile
public void setPreserveBaseUrlFile(boolean state)
Set the "file preservation state" for getBaseUrlSpecification()- Parameters:
state- true to preserve URL file portion
-
getFollowRedirects
public boolean getFollowRedirects()
Should URLConnection follow redirects?- Returns:
- true if URLConnection should handle redirects
-
setParameter
public void setParameter(String name, String value)
Set up a name=value pair- Parameters:
name- Parameter namevalue- Parameter value
-
getParameter
public String getParameter(String name)
Get a named parameter- Parameters:
name- Parameter name- Returns:
- Parameter value
-
getParameterName
public String getParameterName(String value)
Get the parameter name associated with the 1st occurance of this value- Parameters:
value- Parameter value- Returns:
- Parameter name
-
clearParameters
public void clearParameters()
Clear the parameter list
-
submit
public int submit() throws SearchExceptionSubmit a request (POST or GET) and read the response. Various aspects of the response can be inspected using the "getXXX()" methods.- Returns:
- Submission status code (200 = success)
- Throws:
SearchException
-
getResponseString
public String getResponseString()
Get the server response text- Specified by:
getResponseStringin interfaceQueryInterface- Returns:
- The response (as a String)
-
getResponseBytes
public byte[] getResponseBytes()
Get the server response text- Specified by:
getResponseBytesin interfaceQueryInterface- Returns:
- The response (as a byte array)
-
getResponseDocument
public Document getResponseDocument() throws SearchException
Parse the server response (override as required)- Returns:
- Response Document
- Throws:
SearchException
-
getBody
public Element getBody(Document pageDocument)
Locate the HTML BODY element in the page document- Parameters:
pageDocument- An HTML page (as a DOM)- Returns:
- The body Element
-
newFullUrl
public URL newFullUrl(String baseComponent, String relativeComponent)
Construct a new URL from base and relative components- Parameters:
baseComponent- Base URL - the relative URL is added to thisrelativeComponent- A partial (or full) URL that represents our target- Returns:
- A full URL composed of the relative URL combined with "missing" portions taken from the base
-
setParametersFromInputs
public void setParametersFromInputs(Document pageDocument, List nameList)
Deprecated.Replaced by#setParametersFromInputNames()Set query parameters based on page-wide INPUTs- Parameters:
pageDocument- The search engine query page (as a DOM Document)nameList- A list of the parameters we're looking for
-
setParametersFromInputNames
public void setParametersFromInputNames(Document pageDocument, List nameList)
Set query parameters based on page-wide INPUTs- Parameters:
pageDocument- The search engine query page (as a DOM Document)nameList- A list of the parameters we're looking for
-
setParametersFromInputValues
public void setParametersFromInputValues(Document pageDocument, List nameList)
Set query parameters based on page-wide INPUTs- Parameters:
pageDocument- The search engine query page (as a DOM Document)nameList- A list of the parameters we're looking for
-
setParametersFromFormInputs
public void setParametersFromFormInputs(Document pageDocument, String formName, List nameList) throws SearchException
Produce a target URL for this query by combining the form "action" value with the base URL of the query page- Parameters:
pageDocument- The search engine query page (as a DOM Document)formName- The name of the FORM to lookup (egFORM name="formName")nameList- A list of the parameters we're looking for- Throws:
SearchException
-
setParametersFromNameList
public void setParametersFromNameList(NodeList nodeList, List nameList)
Set query parameters based on element names (save name=value pairs)- Parameters:
nodeList- List of Elements to evaluatenameList- A list of the parameters we're looking for
-
setParametersFromValueList
public void setParametersFromValueList(NodeList nodeList, List nameList)
Set query parameters based on element values (save name=value pairs)- Parameters:
nodeList- List of Elements to evaluatenameList- A list of the parameters we're looking for
-
setUrlFromAnchor
public void setUrlFromAnchor(Element anchor) throws SearchException
Produce a target URL for this query by combining an anchor "href" value with the base URL of the query page- Parameters:
anchor- Anchor element- Throws:
SearchException
-
setUrlFromForm
public void setUrlFromForm(Document pageDocument, String formName) throws SearchException
Produce a target URL for this query by combining the form "action" value with the base URL of the query page- Parameters:
pageDocument- The search engine query page (as a DOM Document)formName- The name of the FORM to lookup (egFORM name="formName")- Throws:
SearchException
-
-