Package sunlabs.brazil.handler
Class RePollHandler
- java.lang.Object
-
- java.lang.Thread
-
- sunlabs.brazil.handler.PollHandler
-
- sunlabs.brazil.handler.RePollHandler
-
- All Implemented Interfaces:
java.lang.Runnable
,Handler
public class RePollHandler extends PollHandler
Do regsub processing on content to extract properties.Properties:
- encoding
- The character set encoding to use when converting the request results to a string. Defaults to the default encoding.
- prepend
- The string to prepend to all properties. Extracted properties will contain the the "re" token as an additional prefix.
- re
- the list of "re" tokens to process in order. Each "re" token has the following attributes:
- re.exp
- The regular expression to search for.
- re.sub
- The regular expression substitution pattern. If 'E' is specified, the substitution is done after the extraction.
- re.names
- A white-space delimited set of tokens to use instead of numerical
indices to name the properties.
The first name in the list names the entire match, the remaining
names name the sub-expressions. If there are more properties
extracted than names provided, the "left over" properties will
have numerical indeces. This implies 'E'.
If the name "X" is used, no property will be extracted for that match.
- re.key
- The index of the sub-match (starting at 1) that will be used to name the row number portion of the property name instead of a counter. This is useful if one of the sub-matches will be unique for each matching pattern. This option is ignored if the "O" flag is specified, as there will be only one match so no "key" is required.
- re.flags
- One or more ASCII flags to control how this "re" is processed.
Consists of one or more of The following (defaults to "SFE"):.
Characters not on this list are ignored.
- E Extract current result into server properties. See the rules for naming the properties, below. At least one regular expression Must have an "E" flag.
- F Process if previous "RE" failed.
- I Ignore case in expression
- O only do one substitution or extraction, not all
- R Reset content to original before proceeding Otherwise, the result of the previous substitution (if any) is used.
- S Process if previous "RE" succeeded
First remote content is obtained. Then each regular expression token is processed in turn for the purpose of extracting portions of that content into server properties. [re].sub is used to transform the content before attempting to extract properties.
Content is extracted into the following properties.
- prepend.[re].[m].[n]
- The result of the expression associated with token "re". 'n' is the sub-expression number, and 'm' is the match number, both starting at '0'. If the 'O' flag is specified, there can only be one value for 'm', so it is not included (e.g. the name of the property will be "prepend.[re].[n]).
- prepend.[re].matches
- A list of matches, that may be used as an iterator to foreach.
- prepend.[re].subexpressions
- The number of sub-expressions associated with [re].
- Version:
- %V% RePollHandler.java 2.2
- Author:
- Stephen Uhler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RePollHandler.Extract
A "bag" to store regular expression extraction instructions
-
Field Summary
-
Fields inherited from class sunlabs.brazil.handler.PollHandler
interval, post, url
-
-
Constructor Summary
Constructors Constructor Description RePollHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fillProps(java.util.Properties props, HttpRequest target)
Fill the properties by extracting fields from the response.boolean
init(Server server, java.lang.String prefix)
Set up the initial configuration, and kick off a thread to periodically fetch the url.void
processText(java.util.Properties props, java.lang.String data)
Process the contents as a string through the regular expressions.boolean
respond(Request request)
Allow The url and post data (if any) to be changed.-
Methods inherited from class sunlabs.brazil.handler.PollHandler
run
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Description copied from class:PollHandler
Set up the initial configuration, and kick off a thread to periodically fetch the url.- Specified by:
init
in interfaceHandler
- Overrides:
init
in classPollHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
public boolean respond(Request request)
Allow The url and post data (if any) to be changed. A query parameter of the form "url=xxx" replaces the current url. A query parameter of the form "post=xxx" replaces the post data, if any was initially defined.- Specified by:
respond
in interfaceHandler
- Overrides:
respond
in classPollHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
true
if the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()
orRequest.sendError
.
-
fillProps
public void fillProps(java.util.Properties props, HttpRequest target) throws java.io.IOException
Fill the properties by extracting fields from the response. This overrides fillProps.- Overrides:
fillProps
in classPollHandler
- Throws:
java.io.IOException
-
processText
public void processText(java.util.Properties props, java.lang.String data)
Process the contents as a string through the regular expressions. This is public, and separate from fillProps to make unit testing easier.
-
-