KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > pagination > CListPaginationCurrentPageScrollingValue


1 package org.jahia.deprecated.taglibs.pagination;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.jsp.JspException JavaDoc;
6 import javax.servlet.jsp.JspWriter JavaDoc;
7 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
8
9 import org.jahia.data.containers.JahiaContainerList;
10 import org.jahia.data.containers.JahiaContainerListPagination;
11 import org.jahia.deprecated.taglibs.container.ContainerListTag;
12 import org.jahia.utils.JahiaConsole;
13
14
15 /**
16  * Return the scrolling value of the current page returned from the enclosing ContainerListTag.
17  *
18  * If the attribute valueOnly = "true" ( default value ), returns :
19  * <pre>
20  * windowSize + "_" + windowOffset, i.e. : '5_10'
21  * <pre>
22  *
23  * Else if valueOnly = "false", generate a hidden input :
24  * <pre>
25  * <input type="hidden" name="ctnscroll_contentList1" value="5_10">
26  *
27  * Where : 'contentList1' is the name of the container list
28  * '5_10 : the combination of windowSize = 5, windowOffset = 10 regarding to the values of the enclosing container list.
29  *
30  * </pre>
31  *
32  * @author NK
33  */

34 public class CListPaginationCurrentPageScrollingValue extends BodyTagSupport JavaDoc {
35
36     private JahiaContainerList containerList = null;
37     private JahiaContainerListPagination cPagination = null;
38
39     private String JavaDoc valueOnly = "true";
40
41     public void setValueOnly(String JavaDoc value) {
42         if ( value != null ){
43             this.valueOnly = value.trim().toLowerCase();
44         }
45     }
46
47     public String JavaDoc getValueOnly() {
48         return this.valueOnly;
49     }
50
51
52     public int doStartTag() {
53
54         //JahiaConsole.println("CListPaginationCurrentPageScrollingValue: doStartTag", "Started");
55

56         // gets the enclosing tag ContainerListTag
57
ContainerListTag containerListTag = (ContainerListTag) findAncestorWithClass(this, ContainerListTag.class);
58         if (containerListTag == null || containerListTag.isDeclarationPass()) {
59             return SKIP_BODY;
60         }
61
62         containerList = containerListTag.getContainerList();
63         if ( containerList == null ){
64             return SKIP_BODY;
65         }
66
67         cPagination = containerList.getCtnListPagination();
68         if ( cPagination == null ){
69             return SKIP_BODY;
70         }
71
72         String JavaDoc value = cPagination.getScrollingValue(cPagination.getCurrentPageIndex());
73         if ( value == null ){
74             return SKIP_BODY;
75         }
76
77         if ( this.valueOnly.equals("false") )
78         {
79             try {
80                 StringBuffer JavaDoc buff = new StringBuffer JavaDoc("<input type='hidden' name='");
81                 buff.append("ctnscroll_");
82                 buff.append(containerList.getDefinition().getName());
83                 buff.append("' value='");
84                 buff.append(value);
85                 buff.append("'>");
86                 value = buff.toString();
87             } catch ( Throwable JavaDoc t ) {
88                 t.printStackTrace();
89                 return SKIP_BODY;
90             }
91         }
92
93         try {
94             JspWriter JavaDoc out = pageContext.getOut();
95             out.print(value);
96         } catch (IOException JavaDoc ioe) {
97             JahiaConsole.println("CListPaginationCurrentPageScrollingValue: doStartTag ",ioe.toString());
98         }
99         return SKIP_BODY;
100     }
101
102     public int doEndTag() throws JspException JavaDoc {
103         // let's reinitialize the tag variables to allow tag object reuse in
104
// pooling.
105
containerList = null;
106         cPagination = null;
107
108         valueOnly = "true";
109         return EVAL_PAGE;
110     }
111
112 }
113
Popular Tags