/*
* ExprPropsHandler.java
*
* Brazil project web application toolkit,
* export version: 2.3
* Copyright (c) 2001-2006 Sun Microsystems, Inc.
*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License Version
* 1.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is included as the file "license.terms",
* and also available at http://www.sun.com/
*
* The Original Code is from:
* Brazil project web application toolkit release 2.3.
* The Initial Developer of the Original Code is: drach.
* Portions created by drach are Copyright (C) Sun Microsystems, Inc.
* All Rights Reserved.
*
* Contributor(s): drach, suhler.
*
* Version: 2.5
* Created by drach on 01/07/11
* Last modified by suhler on 06/11/13 15:02:26
*
* Version Histories:
*
* 2.5 06/11/13-15:02:26 (suhler)
* move MatchString to package "util" from "handler"
*
* 2.4 04/12/30-12:37:45 (suhler)
* doc fixes
*
* 2.3 04/05/24-14:42:18 (suhler)
* added discussion on how to use the calculator with 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: *
* 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
* {@link sunlabs.brazil.template.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=true ** will 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=1 ** The choice of the name "true" is arbitrary, it could be any * valiable whose value is "1". * * @author Steve Drach <drach@sun.com> * @version 2.5, 06/11/13 * * @see ExprProps * @see sunlabs.brazil.server.Request */ public class ExprPropsHandler implements Handler { private MatchString isMine; // check for matching url public boolean init(Server server, String prefix) { isMine = new MatchString(prefix, server.props); return true; } /** * * Creates an instance of
ExprProps
that uses
* request.props
for the wrapped
* Calculator
's symbol table.
*
* @see sunlabs.brazil.util.Calculator
*
* @return false
*/
public boolean
respond(Request request) throws IOException {
if (isMine.match(request.url)) {
PropertiesList pl = new PropertiesList(new ExprProps(request), true);
pl.addBefore(request.serverProps);
}
return false;
}
}