KickJava   Java API By Example, From Geeks To Geeks.

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


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