Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../../img/srcFileCovDistChart0.png 29% of files have more coverage
54   252   23   5,4
22   112   0,43   10
10     2,3  
1    
1,1% of code in this file is excluded from these metrics.
 
  PaginateTag       Line # 41 54 23 0% 0.0
 
No Tests
 
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    package net.smartlab.web.page;
24   
25    import java.io.IOException;
26    import java.util.Collection;
27    import javax.servlet.http.HttpServletRequest;
28    import javax.servlet.jsp.JspException;
29    import javax.servlet.jsp.JspTagException;
30    import javax.servlet.jsp.PageContext;
31    import org.apache.struts.taglib.TagUtils;
32   
33    /**
34    * TODO documentation
35    *
36    * @author rlogiacco
37    * @jsp.tag name="paginate" body-content="JSP"
38    * tei-class="net.smartlab.web.page.PaginateTei" display-name=""
39    * description=""
40    */
 
41    public class PaginateTag extends AbstractTag {
42   
43    /* # net.smartlab.web.page.PaginateTei tei */
44    /**
45    * TODO documentation Comment for <code>PARAMETER</code>
46    */
47    public final static String PARAMETER = "net.smartlab.web.page";
48   
49    /**
50    * TODO documentation Comment for <code>paginator</code>
51    *
52    * @directed true
53    */
54    private Paginator paginator = null;
55   
56    /**
57    * TODO documentation Comment for <code>name</code>
58    */
59    private String name = null;
60   
61    /**
62    * TODO documentation
63    */
64    private String property = null;
65   
66    /**
67    * TODO documentation Comment for <code>name</code>
68    */
69    private String parameter;
70   
71    /**
72    * TODO documentation Comment for <code>href</code>
73    */
74    private String href = "";
75   
76    /**
77    * TODO documentation Comment for <code>form</code>
78    */
79    private String form = null;
80   
81    /**
82    * TODO documentation Comment for <code>size</code>
83    */
84    private int size = Paginator.UNLIMITED_ITEMS;
85   
86    /**
87    * TODO documentation Comment for <code>pages</code>
88    */
89    private int pages = Paginator.UNLIMITED_PAGES;
90   
91   
92    /**
93    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
94    */
 
95  0 toggle public int doStartTag() throws JspException {
96  0 String index = ((HttpServletRequest)context.getRequest()).getParameter(parameter);
97  0 Object attribute = TagUtils.getInstance().lookup(context, name, property, "request");
98  0 if (attribute instanceof Paginator) {
99  0 this.paginator = (Paginator)attribute;
100  0 } else if (attribute instanceof Collection) {
101  0 this.paginator = new CollectionPaginator((Collection)attribute);
102  0 String attributeName = name;
103  0 if (property != null) {
104  0 attributeName = property;
105    }
106  0 context.setAttribute(attributeName, this.paginator, PageContext.PAGE_SCOPE);
107    }
108  0 context.setAttribute("paginator", this.paginator, PageContext.PAGE_SCOPE);
109  0 if (size == Paginator.UNLIMITED_ITEMS) {
110  0 paginator.setPageSize(paginator.getCount());
111    } else {
112  0 paginator.setPageSize(size);
113    }
114  0 paginator.setPages(pages);
115  0 if (index != null && index.length() > 0) {
116  0 paginator.setPage(Integer.parseInt(index));
117    } else {
118  0 paginator.setPage(1);
119    }
120  0 if (form != null) {
121  0 try {
122  0 context.getOut().println("<input type='hidden' name='" + parameter + "'/>");
123  0 context.getOut().println("<script>");
124  0 context.getOut().println(" function paginate(page) {");
125  0 context.getOut().println(" document.forms['" + form + "'].elements['" + parameter + "'].value = page;");
126  0 context.getOut().println(" document.forms['" + form + "'].action = '';");
127  0 context.getOut().println(" document.forms['" + form + "'].submit();");
128  0 context.getOut().println(" }");
129  0 context.getOut().println("</script>");
130    } catch (IOException ioe) {
131    throw new JspTagException(ioe);
132    }
133    }
134  0 return EVAL_BODY_INCLUDE;
135    }
136   
137    /**
138    * TODO documentation
139    *
140    * @param name
141    * @jsp.attribute required="true" rtexprvalue="false" type="String"
142    * description="Name of the attribute containing the
143    * paginator instance"
144    */
 
145  0 toggle public void setName(String name) {
146  0 this.name = name;
147  0 this.parameter = PARAMETER + '.' + name;
148    }
149   
 
150  0 toggle public void setProperty(String property) {
151  0 this.property = property;
152  0 if (property != null) {
153  0 this.parameter = PARAMETER + '.' + name + "." + property;
154    }
155    }
156   
157    /**
158    * TODO documentation
159    *
160    * @return
161    */
 
162  0 toggle protected String getHref() {
163  0 if (form == null) {
164  0 String query = ((HttpServletRequest)context.getRequest()).getQueryString();
165  0 if (query != null) {
166  0 int start = query.indexOf(parameter + '=');
167  0 int end = query.length();
168  0 if (start > -1) {
169  0 end = query.indexOf("&", start);
170  0 if (end > -1) {
171  0 query = query.substring(0, start) + query.substring(end + 1) + '&' + parameter + '=';
172    } else {
173  0 query = query.substring(0, start + parameter.length() + 1);
174    }
175    } else {
176  0 query = query + '&' + parameter + '=';
177    }
178    } else {
179  0 query = parameter + '=';
180    }
181  0 return href + '?' + query;
182    } else {
183  0 return href.substring(1);
184    }
185    }
186   
187    /**
188    * TODO documentation
189    *
190    * @param href
191    * @jsp.attribute required="false" rtexprvalue="true" type="String"
192    * description="The url where pagination actions are
193    * submitted: leave blank or not specified to use the same
194    * page"
195    */
 
196  0 toggle public void setHref(String href) {
197  0 this.href = href;
198    }
199   
200    /**
201    * TODO documentation
202    *
203    * @param form
204    * @jsp.attribute required="false" rtexprvalue="true" type="String"
205    * description="The name of form to use to vehicle pagination
206    * informations"
207    */
 
208  0 toggle public void setForm(String form) {
209  0 this.form = form;
210    }
211   
212    /**
213    * TODO documentation
214    *
215    * @param size
216    * @jsp.attribute required="false" rtexprvalue="true" type="int"
217    * description="Number of items per page"
218    */
 
219  0 toggle public void setSize(int size) {
220  0 this.size = size;
221    }
222   
223    /**
224    * TODO documentation
225    *
226    * @param pages
227    * @jsp.attribute required="false" rtexprvalue="true" type="int"
228    * description="Maximum number of pages displayed in a row"
229    */
 
230  0 toggle public void setPages(int pages) {
231  0 this.pages = pages;
232    }
233   
234    /**
235    * @see net.smartlab.web.page.AbstractTag#getPaginator()
236    */
 
237  0 toggle protected Paginator getPaginator() {
238  0 return paginator;
239    }
240   
241    /**
242    * Checks if the pagination involves a form. Pagination with forms uses an
243    * hidden field to pass pagination infos, otherwise a request parameter is
244    * used.
245    *
246    * @return <code>true</code> if the pagination involves a form,
247    * <code>false</code> otherwise.
248    */
 
249  0 toggle protected boolean isForm() {
250  0 return form != null;
251    }
252    }