KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > taglibs > button > NextWindowButtonTag


1 package org.jahia.taglibs.button;
2
3 import java.util.Enumeration JavaDoc;
4
5 import javax.servlet.jsp.JspException JavaDoc;
6
7 import org.jahia.data.JahiaData;
8 import org.jahia.data.containers.JahiaContainerList;
9 import org.jahia.exceptions.JahiaException;
10 import org.jahia.services.usermanager.JahiaUser;
11 import org.jahia.taglibs.container.ContainerListTag;
12
13 /**
14  * <p>Title: This tag generates a next window button for scrollable container lists</p>
15  * <p>Description: </p>
16  * <p>Copyright: Copyright (c) 2002</p>
17  * <p>Company: Jahia Ltd</p>
18  * @author Serge Huber
19  * @version 1.0
20  */

21 // 05.05.2002 NK : Added Post method support
22

23 public class NextWindowButtonTag extends AbstractButtonTag {
24
25     private JahiaContainerList containerList = null;
26     private String JavaDoc title = "Next&gt;&gt;";
27     private String JavaDoc style = "";
28     private String JavaDoc method = "get";
29     private String JavaDoc formName = "";
30
31     private int windowStepInt = 1;
32     private int windowSizeInt = -1;
33
34     // these are necessary since we must be JavaBean compliant.
35
private String JavaDoc windowStep;
36     private String JavaDoc windowSize;
37
38
39     public void setTitle(String JavaDoc title) {
40         this.title = title;
41     }
42
43     public void setStyle(String JavaDoc style) {
44         this.style = style;
45     }
46
47     public void setMethod(String JavaDoc method) {
48         if ( method != null )
49         {
50             this.method = method;
51         }
52     }
53
54     public void setFormName(String JavaDoc formName) {
55         if ( formName != null )
56         {
57             this.formName = formName.trim();
58         }
59     }
60
61     public void setWindowStep(String JavaDoc windowStep) {
62         this.windowStep = windowStep;
63         try {
64             windowStepInt = Integer.parseInt(windowStep);
65             if (windowStepInt < 0)
66               windowStepInt = 0;
67         } catch (NumberFormatException JavaDoc nfe) {
68             windowStepInt = 0;
69         }
70     }
71
72     public void setWindowSize(String JavaDoc windowSize) {
73         this.windowSize = windowSize;
74         try {
75             windowSizeInt = Integer.parseInt(windowSize);
76             if (windowSizeInt < 1)
77               windowSizeInt = -1;
78         } catch (NumberFormatException JavaDoc nfe) {
79             windowSizeInt = -1;
80         }
81     }
82
83     public String JavaDoc getTitle() {
84         return this.title;
85     }
86
87     public String JavaDoc getStyle() {
88         return this.style;
89     }
90
91     public String JavaDoc getMethod() {
92         return this.method;
93     }
94
95     public String JavaDoc getFormName() {
96         return this.formName;
97     }
98
99     public int getWindowStepInt() {
100         return this.windowStepInt;
101     }
102
103     public int getWindowSizeInt() {
104         return this.windowSizeInt;
105     }
106
107     public String JavaDoc getWindowStep() {
108         return this.windowStep;
109     }
110
111     public String JavaDoc getWindowSize() {
112         return this.windowSize;
113     }
114
115     public boolean testRights (JahiaData jData) {
116         JahiaUser user = jData.params().getUser();
117         // retrieves the current container list
118
ContainerListTag parent = (ContainerListTag) findAncestorWithClass(this,ContainerListTag.class);
119         if (parent != null) {
120             containerList = parent.getContainerList();
121         }
122         if (containerList != null) {
123             Enumeration JavaDoc containers = containerList.getContainers();
124             return ( containers.hasMoreElements() );
125         }
126         return false;
127     }
128
129     public String JavaDoc getLauncher(JahiaData jData) throws JahiaException {
130         String JavaDoc value = jData.gui().drawContainerListNextWindowPageURL( containerList, windowStepInt, windowSizeInt, this.method.equals("post") );
131         if ( value != null && this.method.equals("post") )
132         {
133             StringBuffer JavaDoc buff = new StringBuffer JavaDoc("javascript:changePage(document.");
134             buff.append(getFormName());
135             buff.append(",document.");
136             buff.append(getFormName());
137             buff.append(".ctnscroll_");
138             buff.append(containerList.getDefinition().getName());
139             buff.append(",'");
140             buff.append(value);
141             buff.append("');");
142             value = buff.toString();
143         }
144
145         return value;
146     }
147
148     public int doEndTag() throws JspException JavaDoc {
149         // let's reinitialize the tag variables to allow tag object reuse in
150
// pooling.
151
containerList = null;
152         title = "Next&gt;&gt;";
153         style = "";
154         method = "get";
155         formName = "";
156
157         windowStepInt = 1;
158         windowSizeInt = -1;
159         windowStep = null;
160         windowSize = null;
161         return EVAL_PAGE;
162     }
163
164 }
Popular Tags