KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > token > RequestToken


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 /*
14  * Created on 20.10.2003
15  *
16  * To change the template for this generated file go to
17  * Window>Preferences>Java>Code Generation>Code and Comments
18  */

19 package com.tonbeller.wcf.token;
20
21 import javax.servlet.http.HttpSession JavaDoc;
22
23 public class RequestToken {
24   static final String JavaDoc WEBKEY = RequestToken.class.getName();
25   private String JavaDoc token;
26   private String JavaDoc page;
27   private String JavaDoc httpParameterName;
28
29   RequestToken() {
30   }
31
32   public String JavaDoc getPage() {
33     return page;
34   }
35
36   public String JavaDoc getToken() {
37     return token;
38   }
39
40   public void setPage(String JavaDoc string) {
41     page = string;
42   }
43
44   public void setToken(String JavaDoc string) {
45     token = string;
46   }
47
48   public String JavaDoc getHttpParameterName() {
49     return httpParameterName;
50   }
51
52   public void setHttpParameterName(String JavaDoc string) {
53     httpParameterName = string;
54   }
55
56   /**
57    * allow browser navigation in the next request.
58    */

59   public void clear() {
60     setToken(null);
61   }
62
63   /**
64    * appends "?token=wcf1234" or "&token=wcf1234" to url
65    * @param url the url to which the token parameter should be added.
66    */

67   public String JavaDoc appendHttpParameter(String JavaDoc url) {
68     if (token == null || httpParameterName == null)
69       return url;
70     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
71     sb.append(url);
72     if (url.indexOf('?') >= 0)
73       sb.append('&');
74     else
75       sb.append('?');
76     sb.append(httpParameterName);
77     sb.append('=');
78     sb.append(token);
79     return sb.toString();
80   }
81
82
83   public static RequestToken instance(HttpSession JavaDoc session) {
84     RequestToken s = (RequestToken) session.getAttribute(WEBKEY);
85     if (s == null) {
86       s = new RequestToken();
87       session.setAttribute(WEBKEY, s);
88     }
89     return s;
90   }
91
92 }
Popular Tags