Subversion Repositories general

Rev

Rev 961 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
958 dev 1
/**
2
 * Extends and based on Apache Struts source code.
3
 *
4
 * Copyleft Anatoli Klassen (anatoli@aksoft.net)
5
 */
6
package ak.strutsx.taglib;
1024 dev 7
 
8
import java.util.Iterator;
9
import java.util.Collection;
10
import java.util.Map;
11
import javax.servlet.jsp.JspException;
12
import org.apache.struts.util.RequestUtils;
13
import org.apache.struts.taglib.logic.ConditionalTagBase;
14
 
15
public class EmptyTag
16
	extends ConditionalTagBase
17
{
18
    protected boolean condition()
19
    	throws JspException
20
    {
21
        return condition(true);
22
    }
23
 
24
    protected boolean condition(boolean desired)
25
    	throws JspException
26
    {
27
		if(this.name == null) {
28
			JspException e = new JspException(messages.getMessage("empty.noNameAttribute"));
29
			RequestUtils.saveException(pageContext, e);
30
			throw e;
31
		}
32
 
33
		boolean empty = true;
34
 
35
		Object value = null;
36
		if(this.property == null)
37
			value = RequestUtils.lookup(pageContext, name, scope);
38
		else
39
			value = RequestUtils.lookup(pageContext, name, property, scope);
40
 
41
		if(value != null) {
42
			if(value instanceof String)
43
				empty = (((String)value).length() < 1);
44
			else if(value instanceof Collection)
45
				empty = ((Collection)value).isEmpty();
46
			else if(value instanceof Map)
47
				empty = ((Map)value).isEmpty();
48
			else if(value instanceof Iterator)
49
				empty = !((Iterator)value).hasNext();
50
			else
51
				empty = false;
52
		}
53
 
54
		return (empty == desired);
55
    }
56
}