1 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 ; 34 35 public class WriteMessage extends EditMessage 36 { 37 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 warning; 44 45 protected AreaCustomizer areaCustomizer; 46 47 49 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 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 getWarning() {return warning;} 62 public String getActionName() {return "area.WriteMessage";} 63 64 public String getCssClass(Message m){ return ""; } 65 public boolean getUnread(Message m) { return true; } 66 public String getMessageView() {return areaCustomizer.getMessageView();} 67 public String getWriteView() { return areaCustomizer.getWriteView(); } 68 69 public boolean getBodyEmpty(Object m) 70 { 71 return false; 72 } 73 74 public boolean getDeleteAccess(Message message) throws java.sql.SQLException , 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 protected String doExecute() 87 { 88 String ret = INPUT; 89 90 try 91 { 92 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 (System.currentTimeMillis()); 128 msg.ownerID = manager.getUserID(); 129 msg.visible = true; 130 131 preview = new MessageData(manager, msg); 132 133 area.mode = "0"; } 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 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 } 168 catch (Exception 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 |