KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jahia.deprecated.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.deprecated.taglibs.container.ContainerListTag;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.services.usermanager.JahiaUser;
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             if (parent.isDeclarationPass()) {
121                 return false;
122             }
123             containerList = parent.getContainerList();
124         }
125         if (containerList != null) {
126             Enumeration JavaDoc containers = containerList.getContainers();
127             return ( containers.hasMoreElements() );
128         }
129         return false;
130     }
131
132     public String JavaDoc getLauncher(JahiaData jData) throws JahiaException {
133         String JavaDoc value = jData.gui().drawContainerListNextWindowPageURL( containerList, windowStepInt, windowSizeInt, this.method.equals("post") );
134         if ( value != null && this.method.equals("post") )
135         {
136             StringBuffer JavaDoc buff = new StringBuffer JavaDoc("javascript:changePage(document.");
137             buff.append(getFormName());
138             buff.append(",document.");
139             buff.append(getFormName());
140             buff.append(".ctnscroll_");
141             buff.append(containerList.getDefinition().getName());
142             buff.append(",'");
143             buff.append(value);
144             buff.append("');");
145             value = buff.toString();
146         }
147
148         return value;
149     }
150
151     public int doEndTag() throws JspException JavaDoc {
152         // let's reinitialize the tag variables to allow tag object reuse in
153
// pooling.
154
containerList = null;
155         title = "Next&gt;&gt;";
156         style = "";
157         method = "get";
158         formName = "";
159
160         windowStepInt = 1;
161         windowSizeInt = -1;
162         windowStep = null;
163         windowSize = null;
164         return EVAL_PAGE;
165     }
166
167 }
Popular Tags