KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > area > WriteMessage


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.area;
27
28 import net.killingar.forum.internal.AccessDeniedException;
29 import net.killingar.forum.internal.AccessLevel;
30 import net.killingar.forum.internal.Message;
31 import webwork.action.ActionContext;
32
33 import java.sql.Timestamp JavaDoc;
34
35 public class WriteMessage extends EditMessage
36 {
37   // Attributes -----------------------------------------------------
38
public long areaID = -1;
39   public MessageData replyMessage;
40   public MessageData previousMessage;
41     public MessageData message;
42     public long replyMessageTime = View.NOT_SET;
43     public String JavaDoc warning;
44
45     protected AreaCustomizer areaCustomizer;
46
47   // Types ----------------------------------------------------------
48

49   // Setters --------------------------------------------------------
50
public void setAreaID(long l) {areaID = l;}
51   public void setReplyMessageID(long l) {replyMessageID = l;}
52     public void setReplyMessageTime(long in) {replyMessageTime = in;}
53
54   // Getters --------------------------------------------------------
55
public MessageData getReplyMessage() {return replyMessage;}
56   public MessageData getPreviousMessage() {return previousMessage;}
57     public MessageData getMessage() {return message;}
58     public long getAreaID() {return areaID;}
59     public long getReplyMessageID() {return replyMessageID;}
60     public long getReplyMessageTime() {return replyMessageTime;}
61     public String JavaDoc getWarning() {return warning;}
62     public String JavaDoc getActionName() {return "area.WriteMessage";}
63
64     public String JavaDoc getCssClass(Message m){ return ""; }
65     public boolean getUnread(Message m) { return true; }
66     public String JavaDoc getMessageView() {return areaCustomizer.getMessageView();}
67     public String JavaDoc getWriteView() { return areaCustomizer.getWriteView(); }
68
69     public boolean getBodyEmpty(Object JavaDoc m)
70     {
71         return false;
72     }
73
74     public boolean getDeleteAccess(Message message) throws java.sql.SQLException JavaDoc, AccessDeniedException
75     {
76         if (message == null || preview == null || message.getId() == preview.getId())
77             return false;
78
79         return
80             message.getOwnerID() == manager.getUserID() ||
81             areamgr.hasAccess(manager.getUserID(), area.getAreaGroupID(), AccessLevel.removeMessage);
82     }
83
84
85   // Implementation -------------------------------------------------
86
protected String JavaDoc doExecute()
87   {
88         String JavaDoc ret = INPUT;
89
90     try
91     {
92       // get postmode
93
if (postMode == null)
94                 postMode = optionmgr.get("default post mode", "html");
95
96       if (replyMessageID != -1)
97             {
98         replyMessage = new MessageData(manager, areamgr.getMessage(replyMessageID), false, false);
99                 message = replyMessage;
100
101                 area = areamgr.getArea(areamgr.getMessage(replyMessageID).areaID);
102
103                 if (replyMessageTime != View.NOT_SET && replyMessage.lastChanged.getTime() > replyMessageTime)
104                 {
105                     warning = "message changed since last view";
106                     command = "preview";
107
108                     replyMessageTime = System.currentTimeMillis();
109                 }
110             }
111       else
112                 area = areamgr.getArea(areaID);
113
114             areaCustomizer = AbstractAreaCustomizer.getAreaCustomizer(area);
115
116             if (command.equals("preview"))
117             {
118                 areaCustomizer.previewMessage(this);
119                 ActionContext.getValueStack().pushValue(areaCustomizer);
120
121                 Message msg;
122                 if (postMode.equals("text"))
123                     msg = new Message(areaID, replyMessageID, net.killingar.forum.internal.Utils.disableHTML(subject), net.killingar.forum.internal.Utils.disableHTML(body));
124                 else
125                     msg = new Message(areaID, replyMessageID, subject, body);
126
127                 msg.timecreated = new Timestamp JavaDoc(System.currentTimeMillis());
128                 msg.ownerID = manager.getUserID();
129                 msg.visible = true;
130
131                 preview = new MessageData(manager, msg);
132
133                 area.mode = "0"; // hack to remove reply button on previewed messages
134
}
135             else if (!command.equals(""))
136             {
137                 if (postMode.equals("text"))
138                 {
139                     body = net.killingar.forum.internal.Utils.disableHTML(body);
140                     subject = net.killingar.forum.internal.Utils.disableHTML(subject);
141                 }
142
143                 if (!areaCustomizer.addMessagePreProccess(this))
144                 {
145                     ActionContext.getValueStack().pushValue(areaCustomizer);
146                     return INPUT;
147                 }
148
149                 if (subject.equals(""))
150                 {
151                     addErrorMessage("you must specify a summary");
152                     //System.err.println("WriteMessage: you must specify a summary");
153
return INPUT;
154                 }
155
156                 if (replyMessageID != -1)
157                     areaID = areamgr.getMessage(replyMessageID).areaID;
158
159         Message message = new Message(areaID, replyMessageID, subject, body);
160
161         areamgr.addMessage(message);
162
163         return SUCCESS;
164             }
165
166             //System.err.println("WriteMessage.input: subject: "+subject+" body: "+body);
167
}
168     catch (Exception JavaDoc exception)
169     {
170             exception.printStackTrace();
171       addErrorMessage("error getting area manager or area (" + exception.toString() + ")");
172       return ERROR;
173     }
174
175     return ret;
176   }
177
178   protected void doValidation()
179   {
180     if (areaID == -1 && replyMessageID == -1)
181       addErrorMessage("no area id and no reply message id specified ("+areaID+", "+replyMessageID+")");
182   }
183 }
Popular Tags