1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example;
19
20
21 import javax.faces.component.UIData;
22 import javax.faces.context.FacesContext;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26
27 /***
28 * <p>Backing bean for the <code>registration.jsp</code> page.</p>
29 */
30
31 public class RegistrationBacking extends AbstractBacking {
32
33
34
35
36
37 private static final Log log = LogFactory.getLog(RegistrationBacking.class);
38
39
40
41
42
43 private UIData table = null;
44
45
46 /***
47 * <p>Return the <code>UIData</code> instance we are bound to.</p>
48 */
49 public UIData getTable() {
50
51 return (this.table);
52
53 }
54
55
56 /***
57 * <p>Set the <code>UIData</code> instance we are bound to.</p>
58 *
59 * @param table The <code>UIData</code> instance
60 */
61 public void setTable(UIData table) {
62
63 this.table = table;
64
65 }
66
67
68
69
70
71
72 /***
73 * <p>Create a new subscription.</p>
74 */
75 public String create() {
76
77 if (log.isDebugEnabled()) {
78 log.debug("create()");
79 }
80 FacesContext context = FacesContext.getCurrentInstance();
81 StringBuffer url = subscription(context);
82 url.append("?action=Create");
83 url.append("&username=");
84 User user = (User)
85 context.getExternalContext().getSessionMap().get("user");
86 url.append(user.getUsername());
87 forward(context, url.toString());
88 return (null);
89
90 }
91
92
93 /***
94 * <p>Delete an existing subscription.</p>
95 */
96 public String delete() {
97
98 if (log.isDebugEnabled()) {
99 log.debug("delete()");
100 }
101 FacesContext context = FacesContext.getCurrentInstance();
102 StringBuffer url = subscription(context);
103 url.append("?action=Delete");
104 url.append("&username=");
105 User user = (User)
106 context.getExternalContext().getSessionMap().get("user");
107 url.append(user.getUsername());
108 url.append("&host=");
109 Subscription subscription = (Subscription)
110 context.getExternalContext().getRequestMap().get("subscription");
111 url.append(subscription.getHost());
112 forward(context, url.toString());
113 return (null);
114
115 }
116
117
118 /***
119 * <p>Edit an existing subscription.</p>
120 */
121 public String edit() {
122
123 if (log.isDebugEnabled()) {
124 log.debug("edit()");
125 }
126 FacesContext context = FacesContext.getCurrentInstance();
127 StringBuffer url = subscription(context);
128 url.append("?action=Edit");
129 url.append("&username=");
130 User user = (User)
131 context.getExternalContext().getSessionMap().get("user");
132 url.append(user.getUsername());
133 url.append("&host=");
134 Subscription subscription = (Subscription)
135 context.getExternalContext().getRequestMap().get("subscription");
136 url.append(subscription.getHost());
137 forward(context, url.toString());
138 return (null);
139
140 }
141
142
143 /***
144 * <p>Update the subscriptions to reflect any revisions to the
145 * <code>type</code> and <code>autoConnect</code> properties.</p>
146 */
147 public String update() {
148
149 if (log.isDebugEnabled()) {
150 log.debug("update()");
151 }
152
153 FacesContext context = FacesContext.getCurrentInstance();
154
155
156
157 try {
158 UserDatabase database = (UserDatabase)
159 context.getExternalContext().getApplicationMap().
160 get(Constants.DATABASE_KEY);
161 database.save();
162 } catch (Exception e) {
163 log.error("Database save", e);
164 }
165
166
167 StringBuffer sb = registration(context);
168 sb.append("?action=Edit");
169 forward(context, sb.toString());
170 return (null);
171
172 }
173
174
175 }