package com.adaptris.core.services.conditional.operator;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.adaptris.annotation.AdapterComponent;
import com.adaptris.annotation.ComponentProfile;
import com.adaptris.core.AdaptrisMessage;
import com.adaptris.core.services.conditional.Condition;
import com.adaptris.core.services.conditional.Operator;
import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * <p>
 * This {@link Operator} simply tests that the given value evaluates to null or an empty string.
 * </p>
 * <p>
 * The value used in the isEmpty test is the {@link Condition} that this {@link Operator} is
 * configured for; which could be the message payload or a metadata item for example. <br/>
 * </p>
 *
 * @config is-empty
 * @author bklair
 *
 */
@XStreamAlias("is-empty")
@AdapterComponent
@ComponentProfile(summary = "Tests that a value is null or empty", tag = "conditional,operator")
public class IsEmpty implements Operator {

  private Boolean ignoreWhitespace;

  @Override
  public boolean apply(AdaptrisMessage message, String object) {
    String contentItem = message.resolve(object);
    if (StringUtils.isEmpty(contentItem)) {
      return true;
    }
    if (isIgnoreWhitespace() && StringUtils.isBlank(contentItem)) {
      return true;
    }
    return false;
  }

  private boolean isIgnoreWhitespace() {
    return BooleanUtils.toBooleanDefaultIfNull(ignoreWhitespace, false);
  }

  public Boolean getIgnoreWhitespace() {
    return ignoreWhitespace;
  }

  public void setIgnoreWhitespace(Boolean ignoreWhitespace) {
    this.ignoreWhitespace = ignoreWhitespace;
  }
}

@@ -55,99 +55,8 @@
 r;%0A%0A
-import org.apache.commons.lang3.BooleanUtils;%0Aimport org.apache.commons.lang3.StringUtils;%0A
 impo
@@ -149,16 +149,66 @@
 rofile;%0A
+import com.adaptris.annotation.InputFieldDefault;%0A
 import c
@@ -411,16 +411,105 @@
 amAlias;
+%0Aimport org.apache.commons.lang.BooleanUtils;%0Aimport org.apache.commons.lang.StringUtils;
 %0A%0A/**%0A *
@@ -1051,16 +1051,54 @@
 ator %7B%0A%0A
+  @InputFieldDefault(value = %22false%22)%0A
   privat
@@ -1331,18 +1331,16 @@
    if (i
-sI
 gnoreWhi
@@ -1443,25 +1443,25 @@
 %0A  p
-rivate b
+ublic B
 oolean 
-is
+get
 Igno
@@ -1492,44 +1492,8 @@
 urn 
-BooleanUtils.toBooleanDefaultIfNull(
 igno
@@ -1508,16 +1508,8 @@
 pace
-, false)
 ;%0A  
@@ -1516,32 +1516,57 @@
 %7D%0A%0A  public 
+void setIgnoreWhitespace(
 Boolean 
 getIgnoreWhi
@@ -1545,36 +1545,33 @@
 tespace(Boolean 
-getI
+i
 gnoreWhitespace(
@@ -1565,33 +1565,32 @@
 reWhitespace
-(
 ) %7B%0A    
 return ignor
@@ -1569,39 +1569,37 @@
 itespace) %7B%0A    
-return 
+this.
 ignoreWhitespace
@@ -1602,50 +1602,45 @@
 pace
-;%0A  %7D%0A%0A  public void setIgnoreWhitespace(B
+ = ignoreWhitespace;%0A  %7D%0A%0A  private b
 oole
@@ -1654,32 +1654,33 @@
 reWhitespace
+(
 ) %7B%0A    
 this.ignoreW
@@ -1671,33 +1671,55 @@
     
-this.ignoreWhitespace = i
+return BooleanUtils.toBooleanDefaultIfNull(getI
 gnor
@@ -1725,20 +1725,30 @@
 reWhitespace
+(), false)
 ;%0A  %7D%0A%7D%0A

Fix IsEmpty to make ignorewhitespace option visible on UI