Author: michiel
Date: 2009-09-15 12:04:42 +0200 (Tue, 15 Sep 2009)
New Revision: 38628
Modified:
mmbase/trunk/core/src/main/java/org/mmbase/datatypes/processors/OtherField.java
Log:
added 'onlyIfEmpty' options
Modified:
mmbase/trunk/core/src/main/java/org/mmbase/datatypes/processors/OtherField.java
===================================================================
---
mmbase/trunk/core/src/main/java/org/mmbase/datatypes/processors/OtherField.java
2009-09-15 08:16:58 UTC (rev 38627)
+++
mmbase/trunk/core/src/main/java/org/mmbase/datatypes/processors/OtherField.java
2009-09-15 10:04:42 UTC (rev 38628)
@@ -30,9 +30,21 @@
protected String fieldName;
+ protected boolean onlyIfEmpty = false;
+
public void setField(String fn) {
fieldName = fn;
}
+ /**
+ * For setters, the other field will only be set if it is currently
empty. For getters, the
+ * other field will only be used, if this value is empty.
+ */
+ public void setOnlyIfEmpty(boolean b) {
+ onlyIfEmpty = b;
+ }
+ protected boolean empty(Node n, String field) {
+ return n.isNull(field) || "".equals(n.getValue(field));
+ }
}
@@ -40,6 +52,9 @@
private static final long serialVersionUID = 1L;
public Object process(final Node node, final Field field, final Object
value) {
+ if (onlyIfEmpty && ! empty(node, fieldName)) {
+ return value;
+ }
node.setValue(fieldName, value);
return value;
}
@@ -49,7 +64,15 @@
private static final long serialVersionUID = 1L;
public Object process(Node node, Field field, Object value) {
- return node.getValue(fieldName);
+ if (onlyIfEmpty) {
+ if (value == null || "".equals(value)) {
+ return node.getValue(fieldName);
+ } else {
+ return value;
+ }
+ } else {
+ return node.getValue(fieldName);
+ }
}
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs