View Javadoc

1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23   
24  package net.smartlab.web.page;
25  
26  import java.util.Enumeration;
27  
28  import javax.servlet.jsp.tagext.TagData;
29  import javax.servlet.jsp.tagext.TagExtraInfo;
30  import javax.servlet.jsp.tagext.ValidationMessage;
31  import javax.servlet.jsp.tagext.VariableInfo;
32  
33  /**
34   * Additional features for the <code>PaginateTag</code>.
35   * 
36   * @author rlogiacco
37   */
38  public class PaginateTei extends TagExtraInfo {
39  
40  	/**
41  	 * @see javax.servlet.jsp.tagext.TagExtraInfo#getVariableInfo(javax.servlet.jsp.tagext.TagData)
42  	 */
43  	public final VariableInfo[] getVariableInfo(TagData data) {
44  		return new VariableInfo[] {new VariableInfo("paginator", "net.smartlab.web.page.Paginator", true, VariableInfo.NESTED)};
45  	}
46  
47  	/**
48  	 * @see javax.servlet.jsp.tagext.TagExtraInfo#isValid(javax.servlet.jsp.tagext.TagData)
49  	 */
50  	public boolean isValid(TagData tagData) {
51  		boolean hasHref = false;
52  		boolean hasForm = false;
53  
54  		Enumeration attributes = tagData.getAttributes();
55  		while (attributes.hasMoreElements()) {
56  			String attribute = (String)attributes.nextElement();
57  			if (attribute.equals("href")) {
58  				hasHref = true;
59  			} else if (attribute.equals("form")) {
60  				hasForm = true;
61  			}
62  		}
63  		if (hasHref && hasForm) {
64  			// ERROR
65  			return false;
66  		}
67  		return true;
68  	}
69  
70  	/**
71  	 * @see javax.servlet.jsp.tagext.TagExtraInfo#validate(javax.servlet.jsp.tagext.TagData)
72  	 */
73  	public ValidationMessage[] validate(TagData tagData) {
74  		boolean hasHref = false;
75  		boolean hasForm = false;
76  		
77  		Enumeration attributes = tagData.getAttributes();
78  		while (attributes.hasMoreElements()) {
79  			String attribute = (String)attributes.nextElement();
80  			if (attribute.equals("href")) {
81  				hasHref = true;
82  			} else if (attribute.equals("form")) {
83  				hasForm = true;
84  			}
85  		}
86  		if (hasHref && hasForm) {
87  			return new ValidationMessage[] {new ValidationMessage(tagData.getId(), "Page tag has both href and form attributes")};
88  		}
89  		return null;
90  	}
91  
92  }