KickJava   Java API By Example, From Geeks To Geeks.

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


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.Area;
29 import net.killingar.forum.internal.Message;
30 import webwork.action.ActionContext;
31
32 public class EditMessage extends ActionAreaSupport
33 {
34   // Attributes -----------------------------------------------------
35
public long messageID = -1;
36   public long replyMessageID = -1;
37   public String JavaDoc subject;
38   public String JavaDoc body;
39   public String JavaDoc command = "";
40   public boolean bodyEmpty;
41   public MessageData preview;
42   public String JavaDoc postMode = "html";
43     public Area area;
44   public long time = View.NOT_SET;
45
46     protected AreaCustomizer areaCustomizer;
47
48   // Types ----------------------------------------------------------
49

50   // Setters --------------------------------------------------------
51
public void setMessageID(long l) {messageID = l;}
52   public void setBody(String JavaDoc s) {body = s;}
53   public void setCommand(String JavaDoc s) {command = s;}
54   public void setSubject(String JavaDoc s) {subject = s;}
55   public void setPostMode(String JavaDoc s) {postMode = s;}
56   public void setTime(long in) {time = in;}
57
58   // Getters --------------------------------------------------------
59
public MessageData getPreview() {return preview;}
60     public String JavaDoc getSubject() {return subject;}
61     public String JavaDoc getBody() {return body;}
62     public String JavaDoc getPostMode() {return postMode;}
63     public Area getArea() {return area;}
64   public long getTime() {return time;}
65     public long getAreaID() {return area.getId();}
66     public String JavaDoc getActionName() {return "area.EditMessage";}
67     public long getMessageID() {return messageID;}
68     public String JavaDoc getMessageView() {return areaCustomizer.getMessageView();}
69     public String JavaDoc getEditMessageView() {return areaCustomizer.getEditMessageView();}
70     public long getReplyMessageID() {return replyMessageID;}
71
72   // Implementation -------------------------------------------------
73
protected String JavaDoc doExecute()
74   {
75     try
76     {
77             Message message = areamgr.getMessage(messageID);
78             if (message == null)
79             {
80                 addErrorMessage("invalid message ID specified");
81                 return ERROR;
82             }
83
84             replyMessageID = message.getParentID();
85
86             area = areamgr.getArea(message.areaID);
87
88             areaCustomizer = AbstractAreaCustomizer.getAreaCustomizer(area);
89
90             if (body == null)
91                 body = message.body;
92             if (subject == null)
93                 subject = message.subject;
94
95             if (postMode.equals("text"))
96             {
97                 body = net.killingar.forum.internal.Utils.disableHTML(body);
98                 subject = net.killingar.forum.internal.Utils.disableHTML(subject);
99             }
100
101             body = body.trim();
102             subject = subject.trim();
103
104             if (command.equals("post"))
105             {
106                 if (!areaCustomizer.editMessagePreProccess(this))
107                 {
108                     ActionContext.getValueStack().pushValue(areaCustomizer);
109                     return INPUT;
110                 }
111
112                 message.body = body;
113                 message.subject = subject;
114
115                 if (subject.equals(""))
116                 {
117                     addErrorMessage("you must specify a summary");
118                     return INPUT;
119                 }
120
121           areamgr.changeMessage(message);
122
123         return SUCCESS;
124             }
125             else
126             {
127                 areaCustomizer.previewMessage(this);
128                 ActionContext.getValueStack().pushValue(areaCustomizer);
129
130                 message.body = body;
131                 message.subject = subject;
132                 preview = new MessageData(manager, message);
133             }
134
135             //subject = net.killingar.forum.internal.Utils.disableHTML(subject);
136

137       // get postmode
138
}
139     catch (Exception JavaDoc exception)
140     {
141             exception.printStackTrace();
142       addErrorMessage("error getting area manager or area (" + exception.toString() + ")");
143       return ERROR;
144     }
145     return INPUT;
146   }
147
148   protected void doValidation()
149   {
150     if (messageID == -1)
151       addErrorMessage("no message id specified");
152   }
153 }
Popular Tags