2010-02-04 07:30:56 +01:00
|
|
|
package com.metaweb.gridworks.expr;
|
|
|
|
|
2010-02-07 07:16:46 +01:00
|
|
|
import java.util.Properties;
|
2010-02-04 07:30:56 +01:00
|
|
|
|
|
|
|
import com.metaweb.gridworks.model.Cell;
|
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.model.Row;
|
|
|
|
|
|
|
|
public class ExpressionUtils {
|
|
|
|
static public Properties createBindings(Project project) {
|
|
|
|
Properties bindings = new Properties();
|
2010-02-05 00:38:40 +01:00
|
|
|
|
|
|
|
bindings.put("true", true);
|
|
|
|
bindings.put("false", false);
|
|
|
|
|
2010-02-04 07:30:56 +01:00
|
|
|
bindings.put("project", project);
|
2010-02-05 00:38:40 +01:00
|
|
|
|
2010-02-04 07:30:56 +01:00
|
|
|
return bindings;
|
|
|
|
}
|
|
|
|
|
2010-02-23 00:51:44 +01:00
|
|
|
static public void bind(Properties bindings, Row row, int rowIndex, Cell cell) {
|
2010-02-04 07:30:56 +01:00
|
|
|
bindings.put("row", row);
|
2010-02-23 00:51:44 +01:00
|
|
|
bindings.put("rowIndex", rowIndex);
|
2010-02-04 07:30:56 +01:00
|
|
|
bindings.put("cells", row.getField("cells", bindings));
|
|
|
|
|
2010-02-07 04:36:40 +01:00
|
|
|
if (cell == null) {
|
|
|
|
bindings.remove("cell");
|
|
|
|
bindings.remove("value");
|
|
|
|
} else {
|
|
|
|
bindings.put("cell", cell);
|
|
|
|
bindings.put("value", cell.value);
|
|
|
|
}
|
2010-02-04 07:30:56 +01:00
|
|
|
}
|
2010-02-05 09:39:10 +01:00
|
|
|
|
2010-02-27 06:48:33 +01:00
|
|
|
static public boolean isError(Object o) {
|
|
|
|
return o != null && o instanceof EvalError;
|
|
|
|
}
|
|
|
|
/*
|
2010-02-05 09:39:10 +01:00
|
|
|
static public boolean isBlank(Object o) {
|
2010-02-07 07:16:46 +01:00
|
|
|
return o == null || (o instanceof String && ((String) o).length() == 0);
|
2010-02-05 09:39:10 +01:00
|
|
|
}
|
2010-02-27 06:48:33 +01:00
|
|
|
*/
|
|
|
|
static public boolean isNonBlankData(Object o) {
|
|
|
|
return
|
|
|
|
o != null &&
|
|
|
|
!(o instanceof EvalError) &&
|
|
|
|
(!(o instanceof String) || ((String) o).length() > 0);
|
|
|
|
}
|
2010-02-05 09:39:10 +01:00
|
|
|
|
|
|
|
static public boolean isTrue(Object o) {
|
|
|
|
return o != null &&
|
|
|
|
(o instanceof Boolean ?
|
|
|
|
((Boolean) o).booleanValue() :
|
|
|
|
Boolean.parseBoolean(o.toString()));
|
|
|
|
}
|
2010-02-04 07:30:56 +01:00
|
|
|
}
|