Class ExprPropsHandler
java.lang.Object
sunlabs.brazil.properties.ExprPropsHandler
- All Implemented Interfaces:
Handler
The
ExprPropsHandler
installs an expression evaluator as a
"smart properties" into the current request object, enabling arithmetic and
logical expression evaluation in property name lookups.
The following configuration parameters are used:
- prefix, suffix, glob, match
- Only URL's that match are allowed.
(See
MatchString
).
Using the expression evaluator can be a bit tricky, as the evaluator works by interpreting a property name as an expression, and using its the expression result as its value. For example, the construct:
"${x + 4 == 3}"will evaluate to either "1" or "0", depending upon the value of "x". For use with the
<if>
constuct of the
BSLTemplate
, the following construct:
<if name="${x + 4 == 3}"> ... [if expression] ... </if>Will take (or not take) the "if expression" if there is a property named "1" that is set (to anything but 0 or false), but a property named "0" is not set. An entry in a server configuration file:
1=truewill do the trick.
alternately, the construct:
<if name=true value="${x + 4 == 3}"> ... [if expression] ... </if>Will work as expected only if there is a configuration property:
true=1The choice of the name "true" is arbitrary, it could be any valiable whose value is "1".
- Version:
- 2.5, 06/11/13
- Author:
- Steve Drach <drach@sun.com>
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ExprPropsHandler
public ExprPropsHandler()
-
-
Method Details
-
init
Description copied from interface:Handler
Initializes the handler.- Specified by:
init
in interfaceHandler
- 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
Creates an instance ofExprProps
that usesrequest.props
for the wrappedCalculator
's symbol table.- Specified by:
respond
in interfaceHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
- false
- Throws:
IOException
- if there was an I/O error while sending the response to the client. Typically, in that case, theServer
will (try to) send an error message to the client and then close the client's connection.The
IOException
should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.- See Also:
-