01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.datatypes.processors;
11:
12: import org.mmbase.bridge.*;
13: import org.mmbase.util.logging.*;
14:
15: /**
16: * If this commit-processor is configured on a field, then on commit of the node, the value of a
17: * certain function (on the same node), is set into the field, if the field is empty.
18: *
19: * @author Michiel Meeuwissen
20: * @version $Id: FunctionValueIfEmptyCommitProcessor.java,v 1.3 2008/02/03 17:33:57 nklasens Exp $
21: * @since MMBase-1.8.5
22: */
23:
24: public class FunctionValueIfEmptyCommitProcessor implements
25: CommitProcessor {
26:
27: private static final Logger log = Logging
28: .getLoggerInstance(FunctionValueIfEmptyCommitProcessor.class);
29:
30: private static final long serialVersionUID = 1L;
31: private String functionName;
32:
33: public void setFunctionName(String fn) {
34: functionName = fn;
35: }
36:
37: public void commit(Node node, Field field) {
38: if (node.getValue(field.getName()) == null
39: || "".equals(node.getStringValue(field.getName()))) {
40: node.setValue(field.getName(), node.getFunctionValue(
41: functionName, null));
42: }
43: }
44:
45: }
|