KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > action > PrivMsgAction


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.javabb.action;
18
19 import java.util.Date JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.javabb.action.infra.BaseAction;
23 import org.javabb.component.PostFormatter;
24 import org.javabb.infra.UserContext;
25 import org.javabb.transaction.PrivMsgTransaction;
26 import org.javabb.vo.PrivMsg;
27 import org.javabb.vo.User;
28
29 /**
30  * @author Lucas Teixeira - <a HREF="mailto:lucas@javabb.org">lucas@javabb.org</a>
31  */

32 /*$Id: PrivMsgAction.java,v 1.6.8.2 2006/04/17 17:47:05 daltoncamargo Exp $*/
33 public class PrivMsgAction extends BaseAction {
34
35     private PostFormatter postFormatter;
36     private PrivMsg pm;
37     private List JavaDoc lstMsgs;
38     private PrivMsgTransaction pmTransaction = null;
39     
40     //Reply
41
private String JavaDoc title;
42     private Long JavaDoc userId;
43     private String JavaDoc username;
44     private String JavaDoc msg;
45     
46     //action identifier
47
private String JavaDoc act;
48     
49     //multiple selector
50
private Long JavaDoc[] idPm;
51
52     public String JavaDoc inbox() throws Exception JavaDoc {
53         User logado = UserContext.getContext().getUser();
54         lstMsgs = pmTransaction.getUserInbox(logado);
55         return SUCCESS;
56     }
57     
58     public String JavaDoc outbox() throws Exception JavaDoc {
59         User logado = UserContext.getContext().getUser();
60         lstMsgs = pmTransaction.getUserOutbox(logado);
61         return SUCCESS;
62     }
63     
64     public String JavaDoc readIn() throws Exception JavaDoc {
65         pm = pmTransaction.loadRecivied(pm);
66         act = "readIn";
67         if (pm.getUserTo().equals(UserContext.getContext().getUser()))
68             return SUCCESS;
69         else
70             throw new Exception JavaDoc("Você pode ler apenas as suas mensagens."); //i18n ?
71
}
72     
73     public String JavaDoc readOut() throws Exception JavaDoc {
74         pm = pmTransaction.loadSent(pm);
75         act = "readOut";
76         if (pm.getUserFrom().equals(UserContext.getContext().getUser()))
77             return SUCCESS;
78         else
79             throw new Exception JavaDoc("Você pode ler apenas as suas mensagens."); //i18n ?
80
}
81     
82     public String JavaDoc deleteSelectedInbox() throws Exception JavaDoc {
83         if (idPm != null)
84             pmTransaction.deleteSelectedInbox(pmTransaction.asPrivMsgList(idPm));
85         
86         return SUCCESS;
87     }
88     
89     public String JavaDoc deleteInbox() throws Exception JavaDoc {
90         lstMsgs = pmTransaction.getUserInbox(UserContext.getContext().getUser());
91         pmTransaction.deleteSelectedInbox(lstMsgs);
92         return SUCCESS;
93     }
94     
95     public String JavaDoc deleteSelectedOutbox() throws Exception JavaDoc {
96         if (idPm != null)
97             pmTransaction.deleteSelectedOutbox(pmTransaction.asPrivMsgList(idPm));
98         
99         return SUCCESS;
100     }
101     
102     public String JavaDoc deleteOutbox() throws Exception JavaDoc {
103         lstMsgs = pmTransaction.getUserOutbox(UserContext.getContext().getUser());
104         pmTransaction.deleteSelectedOutbox(lstMsgs);
105         return SUCCESS;
106     }
107
108     
109     public String JavaDoc send() throws Exception JavaDoc {
110         pm.setUserTo(new User(userId));
111         pm.setData(new Date JavaDoc());
112         pm.setRead(new Integer JavaDoc(0));
113         pm.setUserFrom(UserContext.getContext().getUser());
114         Long JavaDoc mpId = pmTransaction.send(pm);
115
116         pmTransaction.delegateMail(getText("pm_you_have_new_message"), userId, mpId);
117         
118         return SUCCESS;
119     }
120     
121     public String JavaDoc newPm() throws Exception JavaDoc {
122         act = "new";
123         return SUCCESS;
124     }
125     
126     public String JavaDoc quote() throws Exception JavaDoc {
127         //i18n in this 'RE:'
128
PrivMsg _pm = pmTransaction.loadRecivied(pm);
129         title = "Re: "+_pm.getTopic();
130         username = _pm.getUserFrom().getUser();
131         userId = _pm.getUserFrom().getId();
132         //hardcoded, bleh
133
msg = "[quote=\""+username+"\"]"+_pm.getText()+"[/quote]\n\n";
134         act = "quote";
135         return SUCCESS;
136     }
137     
138     public String JavaDoc reply() throws Exception JavaDoc {
139         //i18n in this 'RE:'
140
PrivMsg _pm = pmTransaction.loadRecivied(pm);
141         title = "Re: "+_pm.getTopic();
142         username = _pm.getUserFrom().getUser();
143         userId = _pm.getUserFrom().getId();
144         act = "reply";
145         return SUCCESS;
146     }
147
148     /**
149      * Send a message on click
150      * of PM Button (viewpost or viewprovile)
151      * @throws Exception
152      */

153     public String JavaDoc externalSend() throws Exception JavaDoc {
154         act = "reply";
155         return SUCCESS;
156     }
157     
158     /**
159      * @param post
160      * @return formated post
161      */

162     public String JavaDoc formatTextToBBCode(String JavaDoc text) {
163         return postFormatter.formatTextToBBCode(text);
164     }
165
166
167     public List JavaDoc getLstMsgs() {
168         return lstMsgs;
169     }
170     public void setLstMsgs(List JavaDoc lstMsgs) {
171         this.lstMsgs = lstMsgs;
172     }
173
174     public PrivMsg getPm() {
175         return pm;
176     }
177     public void setPm(PrivMsg pm) {
178         this.pm = pm;
179     }
180     
181     public Long JavaDoc[] getIdPm() { return idPm; }
182     public void setIdPm(Long JavaDoc[] idPm) { this.idPm = idPm; }
183
184     //DI
185
public void setPmTransaction(PrivMsgTransaction pmTransaction) {
186         this.pmTransaction = pmTransaction;
187     }
188
189     /**
190      * @param postFormatter the new postFormatter value
191      */

192     public void setPostFormatter(PostFormatter postFormatter) {
193         this.postFormatter = postFormatter;
194     }
195     
196     /**
197      * @return Returns the title.
198      */

199     public String JavaDoc getTitle() {
200         return title;
201     }
202     /**
203      * @param title The title to set.
204      */

205     public void setTitle(String JavaDoc title) {
206         this.title = title;
207     }
208     /**
209      * @return Returns the msg.
210      */

211     public String JavaDoc getMsg() {
212         return msg;
213     }
214     /**
215      * @param msg The msg to set.
216      */

217     public void setMsg(String JavaDoc msg) {
218         this.msg = msg;
219     }
220     /**
221      * @return Returns the username.
222      */

223     public String JavaDoc getUsername() {
224         return username;
225     }
226     /**
227      * @param username The username to set.
228      */

229     public void setUsername(String JavaDoc username) {
230         this.username = username;
231     }
232     /**
233      * @return Returns the userId.
234      */

235     public Long JavaDoc getUserId() {
236         return userId;
237     }
238     /**
239      * @param userId The userId to set.
240      */

241     public void setUserId(Long JavaDoc userId) {
242         this.userId = userId;
243     }
244     /**
245      * @return Returns the action.
246      */

247     public String JavaDoc getAct() {
248         return act;
249     }
250     /**
251      * @param action The action to set.
252      */

253     public void setAct(String JavaDoc action) {
254         this.act = action;
255     }
256 }
Popular Tags