org.apache.cocoon.forms.formmodel.algorithms
Class SimpleFormula
java.lang.Object
org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
- All Implemented Interfaces:
- Contextualizable, LogEnabled, CalculatedFieldAlgorithm
- Direct Known Subclasses:
- RepeatedFormula
public class SimpleFormula
- extends AbstractBaseAlgorithm
An xreported expression based algorithm.
This algorithm can be used to write simple formulas, examples are :
- 20% VAT calculation : eval="(amount / 100) * 20"
- 100$ volume discount : eval="If(amount > 1000,100,0)"
(read: if amount is greater than 1000 then the result will be 100, otherwise 0)
- Number of boxes needed to carry that number of items : eval="Ceiling(items / boxsize)"
- Number of items you can add before another box is needed : eval="Reminder(items,boxside)"
Note: please take care that xreporter expressions are not that accurate when it comes to decimals. The default
divide operator rounds the result, see http://issues.cocoondev.org/browse/XRP-115. Also consider that the
available set of functions can be expanded implementing and using new ones. Please see
http://outerthought.net/wqm/xreporter/en/expressions.html for an overview of xreportes expressions and
IsNullFunction
or
StringFunction
for examples of custom xreporter functions.
- Version:
- $Id: SimpleFormula.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Field Summary |
protected org.outerj.expression.Expression |
formula
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
formula
protected org.outerj.expression.Expression formula
SimpleFormula
public SimpleFormula()
isSuitableFor
public boolean isSuitableFor(Datatype dataType)
- Description copied from interface:
CalculatedFieldAlgorithm
- Checks wether this algorithm is able to return the given datatype. For example,
an arithmetic algorithm like sum should check that the given datatype is a number.
- Parameters:
dataType
- The target datatype.
- Returns:
- true if this algorithm can return a compatible value, false otherwise.
calculate
public Object calculate(Form form,
Widget parent,
Datatype datatype)
- Description copied from interface:
CalculatedFieldAlgorithm
- Performs the actual calculation.
- Parameters:
form
- The form.parent
- The parent widget of the CalculatedField
widget (may be the same as form)datatype
- The target datatype.
- Returns:
- the calculated value for the
CalculatedField
.
getFormula
public org.outerj.expression.Expression getFormula()
- Returns:
- Returns the formula.
setFormula
public void setFormula(org.outerj.expression.Expression formula)
- Parameters:
formula
- The formula to set.
Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.