KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > action > infra > ActionSuper


1 package org.javabb.action.infra;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import javax.servlet.http.HttpSession JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.javabb.infra.ApplicationContext;
12 import org.javabb.infra.JbbConfig;
13 import org.javabb.infra.Online;
14 import org.javabb.infra.PagedList;
15 import org.javabb.infra.UserContext;
16 import org.javabb.vo.Forum;
17 import org.javabb.vo.Topic;
18 import org.javabb.vo.User;
19 import org.springframework.web.util.HtmlUtils;
20
21 import com.opensymphony.webwork.ServletActionContext;
22 import com.opensymphony.webwork.util.Timer;
23 import com.opensymphony.xwork.ActionContext;
24 import com.opensymphony.xwork.ActionSupport;
25
26 /*
27  * Copyright 2004 JavaFree.org
28  *
29  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
30  * use this file except in compliance with the License. You may obtain a copy of
31  * the License at
32  *
33  * http://www.apache.org/licenses/LICENSE-2.0
34  *
35  * Unless required by applicable law or agreed to in writing, software
36  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
37  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
38  * License for the specific language governing permissions and limitations under
39  * the License.
40  */

41
42 /**
43  * $Id: ActionSuper.java,v 1.4.8.3 2006/08/14 14:26:26 daltoncamargo Exp $
44  * @author Dalton Camargo - <a HREF="mailto:dalton@javabb.org">dalton@javabb.org </a> <br>
45  * @author Ronald Tetsuo Miura
46  */

47 public class ActionSuper extends ActionSupport {
48     /** Logger. */
49     protected final Log log = LogFactory.getLog(getClass());
50
51     /** Tempo de load da execução. */
52     private Timer timer = new Timer();
53
54     /** Módulo "quem está online". */
55     private Online online;
56
57     /** Configurações gerais do fórum. */
58     private JbbConfig jbbConfig;
59
60     /** Url usada para redirecionamento de uma action para um jsp. */
61     private String JavaDoc url;
62
63     /** Numero da pagina a ser usada. */
64     protected int _page = 1;
65
66     /** Variavel para guardar valores temporarios. */
67     private String JavaDoc temp;
68     
69     private String JavaDoc captchafield;
70
71     private PagedList _pagedResult;
72
73     /**
74      * @return the application context object
75      */

76     public ApplicationContext getApplication() {
77         return ApplicationContext.getContext();
78     }
79
80     /**
81      * @param online the new online value
82      */

83     public void setOnline(Online online) {
84         this.online = online;
85     }
86
87     /**
88      * @param jbbConfig the new jbbConfig value
89      */

90     public void setJbbConfig(JbbConfig jbbConfig) {
91         this.jbbConfig = jbbConfig;
92     }
93
94     /**
95      * All Forum's configuration. This include total messsage, registered users and so on.
96      * @return Forum's configuration.
97      */

98     public JbbConfig getJbbConfig() {
99         return jbbConfig;
100     }
101
102     /**
103      * @return O tempo de processamento da página.
104      */

105     public Timer getTimer() {
106         return timer;
107     }
108
109     /**
110      * Módulo de quem está online
111      * @return Returns a Online object
112      */

113     public Online getOnline() {
114         return online;
115     }
116
117     /**
118      * @return Returns the url.
119      */

120     public String JavaDoc getUrl() {
121         return url;
122     }
123
124     /**
125      * @param url The url to set.
126      */

127     public void setUrl(String JavaDoc url) {
128         this.url = url;
129     }
130
131     /**
132      * @return Returns the page.
133      */

134     public int getPage() {
135         return _page;
136     }
137
138     /**
139      * @param page The page to set.
140      */

141     public void setPage(int page) {
142         this._page = page;
143     }
144
145     /**
146      * @return Conteúdo das páginas disponíveis para a view
147      */

148     public List JavaDoc getPages() {
149         return (List JavaDoc) getSessionAttribute("pages");
150     }
151
152     /**
153      * @return A última página da paginação
154      */

155     public Integer JavaDoc getLastPage() {
156         return (Integer JavaDoc) getSessionAttribute("last_page");
157     }
158
159     /**
160      * @return Returns the temp.
161      */

162     public String JavaDoc getTemp() {
163         return temp;
164     }
165
166     /**
167      * @param temp The temp to set.
168      */

169     public void setTemp(String JavaDoc temp) {
170         this.temp = temp;
171     }
172
173     /**
174      * @param text
175      * @return htmp-escaped text
176      */

177     public String JavaDoc htmlEscape(String JavaDoc text) {
178         return HtmlUtils.htmlEscape(text);
179     }
180
181     /**
182      * Sets a parameter in the next chained action.
183      * @param name
184      * @param value
185      */

186     protected void setParameter(String JavaDoc name, Object JavaDoc value) {
187         Map JavaDoc params = new HashMap JavaDoc(ActionContext.getContext().getParameters());
188         params.put(name, value);
189         ActionContext.getContext().setParameters(params);
190     }
191
192     /**
193      * Sets a variable to be used in the template.
194      * @param name
195      * @param value
196      */

197     protected void setViewObject(String JavaDoc name, Object JavaDoc value) {
198         Map JavaDoc map = new HashMap JavaDoc();
199         map.put(name, value);
200         ActionContext.getContext().getValueStack().push(map);
201     }
202
203     /**
204      * Retrieves an object from session.
205      * @param attributeName
206      * @return Object in session with name equals nameSession
207      * @see #setSessionAttribute(String, Object)
208      * @see ActionContext#getContext()
209      * @see ActionContext#getSession()
210      */

211     public Object JavaDoc getSessionAttribute(String JavaDoc attributeName) {
212         return ActionContext.getContext().getSession().get(attributeName);
213     }
214
215     /**
216      * Sets a new object in session.
217      * @param nameSession
218      * @param objectSession
219      * @see #removeSessionAttribute(String)
220      * @see #getSessionAttribute(String)
221      * @see ActionContext#getContext()
222      * @see ActionContext#getSession()
223      */

224     public void setSessionAttribute(String JavaDoc nameSession, Object JavaDoc objectSession) {
225         ActionContext ctx = ActionContext.getContext();
226         Map JavaDoc session = ctx.getSession();
227         session.put(nameSession, objectSession);
228     }
229
230     /**
231      * Removes an object from session.
232      * @param attributeName
233      * @see #setSessionAttribute(String, Object)
234      * @see ActionContext#getContext()
235      * @see ActionContext#getSession()
236      */

237     public void removeSessionAttribute(String JavaDoc attributeName) {
238         ActionContext.getContext().getSession().remove(attributeName);
239     }
240
241     public PagedList getPagedResult() {
242         return _pagedResult;
243     }
244
245     public void setPagedResult(PagedList pagedResult) {
246         _pagedResult = pagedResult;
247     }
248
249     public boolean isTopicRead(Topic topic) {
250         try {
251             return UserContext.getContext().isTopicRead(topic);
252         } catch (RuntimeException JavaDoc e) {
253             log.debug(e.getMessage(), e);
254             return true;
255         }
256     }
257
258     public boolean isForumRead(Forum forum) {
259         try {
260             return false;
261             //return UserContext.getContext().isForumRead(forum);
262
} catch (RuntimeException JavaDoc e) {
263             log.debug(e.getMessage(), e);
264             return false;
265         }
266     }
267     
268     
269     /**
270      * Check if in Request Captcha is true or false;
271      * @return captcha validation
272      */

273     public boolean checkCaptcha(){
274         HttpSession JavaDoc ss = ServletActionContext.getRequest().getSession();
275         if(ss != null){
276             String JavaDoc c = (String JavaDoc)ss.getAttribute(nl.captcha.servlet.Constants.SIMPLE_CAPCHA_SESSION_KEY) ;
277             if (c != null && getCaptchafield() != null) {
278                 if (c.equals(getCaptchafield())) {
279                     return true;
280                 }else {
281                     return false;
282                 }
283             }
284         }
285         return false;
286     }
287     
288     
289     /**
290      * Get the user of session
291      * @return
292      * @throws Exception
293      */

294     public User getUserLogged() throws Exception JavaDoc{
295         return (User)this.getSessionAttribute("jbbuser");
296     }
297
298     public String JavaDoc getCaptchafield() {
299         return captchafield;
300     }
301
302     public void setCaptchafield(String JavaDoc captchafield) {
303         this.captchafield = captchafield;
304     }
305     
306 }
Popular Tags