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

import com.adaptris.annotation.AdapterComponent;
import com.adaptris.annotation.ComponentProfile;
import com.adaptris.annotation.InputFieldDefault;
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;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;

/**
 * <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 {

  @InputFieldDefault(value = "false")
  private Boolean ignoreWhitespace;

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

  public Boolean getIgnoreWhitespace() {
    return ignoreWhitespace;
  }

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

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

@@ -51,16 +51,107 @@
 rator;%0A%0A
+import org.apache.commons.lang3.BooleanUtils;%0Aimport org.apache.commons.lang3.StringUtils;%0A
 import c
@@ -244,58 +244,8 @@
 le;%0A
-import com.adaptris.annotation.InputFieldDefault;%0A
 impo
@@ -456,97 +456,8 @@
 ias;
-%0Aimport org.apache.commons.lang.BooleanUtils;%0Aimport org.apache.commons.lang.StringUtils;
 %0A%0A/*
@@ -1007,46 +1007,8 @@
  %7B%0A%0A
-  @InputFieldDefault(value = %22false%22)%0A
   pr
@@ -1245,16 +1245,18 @@
    if (i
+sI
 gnoreWhi
@@ -1359,25 +1359,25 @@
 %0A  p
-ublic B
+rivate b
 oolean 
-get
+is
 Igno
@@ -1404,16 +1404,52 @@
  return 
+BooleanUtils.toBooleanDefaultIfNull(
 ignoreWh
@@ -1448,32 +1448,40 @@
 ignoreWhitespace
+, false)
 ;%0A  %7D%0A%0A  public 
@@ -1484,41 +1484,16 @@
 lic 
-void setIgnoreWhitespace(
 Boolean 
 igno
@@ -1480,33 +1480,36 @@
  public Boolean 
-i
+getI
 gnoreWhitespace)
@@ -1507,24 +1507,25 @@
 itespace
+(
 ) %7B%0A    
 this.ign
@@ -1520,13 +1520,15 @@
     
-this.
+return 
 igno
@@ -1543,45 +1543,50 @@
 pace
- = ignoreWhitespace;%0A  %7D%0A%0A  private b
+;%0A  %7D%0A%0A  public void setIgnoreWhitespace(B
 oole
@@ -1600,33 +1600,32 @@
 reWhitespace
-(
 ) %7B%0A    
 return Boole
@@ -1616,55 +1616,33 @@
     
-return BooleanUtils.toBooleanDefaultIfNull(getI
+this.ignoreWhitespace = i
 gnor
@@ -1656,18 +1656,8 @@
 pace
-(), false)
 ;%0A  

Revert "Fix IsEmpty to make ignorewhitespace option visible on UI"