1 18 19 package org.apache.struts.taglib.logic; 20 21 import java.util.Collection ; 22 import java.util.Map ; 23 import java.lang.reflect.Array ; 24 25 import javax.servlet.jsp.JspException ; 26 27 import org.apache.struts.taglib.TagUtils; 28 29 36 public class EmptyTag extends ConditionalTagBase { 37 38 39 41 42 50 protected boolean condition() throws JspException { 51 52 return (condition(true)); 53 54 } 55 56 57 67 protected boolean condition(boolean desired) throws JspException { 68 if (this.name == null) { 69 JspException e = 70 new JspException (messages.getMessage("empty.noNameAttribute")); 71 TagUtils.getInstance().saveException(pageContext, e); 72 throw e; 73 } 74 75 Object value = null; 76 if (this.property == null) { 77 value = TagUtils.getInstance().lookup(pageContext, name, scope); 78 } else { 79 value = TagUtils.getInstance().lookup(pageContext, name, property, scope); 80 } 81 82 boolean empty = true; 83 84 if (value == null) { 85 empty = true; 86 87 } else if (value instanceof String ) { 88 String strValue = (String ) value; 89 empty = (strValue.length() < 1); 90 91 } else if (value instanceof Collection ) { 92 Collection collValue = (Collection ) value; 93 empty = collValue.isEmpty(); 94 95 } else if (value instanceof Map ) { 96 Map mapValue = (Map ) value; 97 empty = mapValue.isEmpty(); 98 99 } else if (value.getClass().isArray()) { 100 empty = Array.getLength(value) == 0; 101 102 } else { 103 empty = false; 104 } 105 106 return (empty == desired); 107 } 108 109 } 110 | Popular Tags |