1 126 package com.ivata.groupware.business.library.struts; 127 128 import javax.servlet.http.HttpServletRequest ; 129 import javax.servlet.http.HttpServletResponse ; 130 import javax.servlet.http.HttpSession ; 131 132 import org.apache.struts.action.ActionErrors; 133 import org.apache.struts.action.ActionForm; 134 import org.apache.struts.action.ActionMapping; 135 136 import com.ivata.groupware.admin.security.server.SecuritySession; 137 import com.ivata.groupware.admin.setting.Settings; 138 import com.ivata.groupware.admin.setting.SettingsDataTypeException; 139 import com.ivata.groupware.business.library.Library; 140 import com.ivata.groupware.business.library.comment.CommentDO; 141 import com.ivata.groupware.business.library.item.LibraryItemDO; 142 import com.ivata.mask.MaskFactory; 143 import com.ivata.mask.util.StringHandling; 144 import com.ivata.mask.util.SystemException; 145 import com.ivata.mask.web.struts.MaskAction; 146 import com.ivata.mask.web.struts.MaskAuthenticator; 147 148 149 159 public class CommentAction extends MaskAction { 160 private Library library; 161 private Settings settings; 162 171 public CommentAction(Library library, Settings settings, 172 MaskFactory maskFactory, MaskAuthenticator authenticator) { 173 super(maskFactory, authenticator); 174 this.library = library; 175 this.settings = settings; 176 } 177 178 198 public void clear(final ActionMapping mapping, 199 final ActionErrors errors, 200 final ActionForm form, 201 final HttpServletRequest request, 202 final HttpServletResponse response, 203 final HttpSession session) throws SystemException { 204 session.removeAttribute("libraryCommentForm"); 206 } 207 208 231 public String execute(final ActionMapping mapping, 232 final ActionErrors errors, 233 final ActionForm form, 234 final HttpServletRequest request, 235 final HttpServletResponse response, 236 final HttpSession session) throws SystemException { 237 CommentForm commentForm = (CommentForm) form; 238 239 ItemForm itemForm = (ItemForm) session.getAttribute("libraryItemForm"); 240 241 if (StringHandling.isNullOrEmpty(commentForm.getList())) { 242 commentForm.setList("false"); 243 } 244 245 if (itemForm == null && commentForm.getList().equals("false")) { 248 return "utilClosePopUp"; 249 } 250 251 LibraryItemDO item = null; 252 253 if (commentForm.getList().equals("false")) { 254 item = itemForm.getItem(); 255 } 256 257 Integer requestParentId = StringHandling.integerValue( 258 request.getParameter("parentId")); 259 Integer requestId = StringHandling.integerValue( 260 request.getParameter("id")); 261 CommentDO comment = commentForm.getComment(); 262 CommentDO parent = null; 263 if (comment != null) { 264 parent = comment.getParent(); 265 } 266 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession"); 267 comment.setCreatedBy(securitySession.getUser()); 268 269 if (requestParentId != null) { 271 commentForm.setComment(comment = new CommentDO()); 272 comment.setParent(parent = library.findCommentByPrimaryKey( 273 securitySession, requestParentId)); 274 275 276 } else if (requestId != null) { 278 commentForm.setComment(comment = library.findCommentByPrimaryKey( 279 securitySession, requestId)); 280 } 281 282 if (comment.getItem() == null) { 283 if (item != null) { 284 comment.setItem(item); 285 } else { 286 comment.setItem(parent.getItem()); 287 } 288 } 289 290 if (comment.getCreatedBy() == null) { 291 comment.setCreatedBy(securitySession.getUser()); 292 } 293 294 commentForm.setBundle("library"); 295 commentForm.setDeleteKey("submitComment.alert.delete"); 296 297 if (StringHandling.isNullOrEmpty(comment.getSubject())) { 299 try { 300 comment.setSubject(settings.getStringSetting(securitySession, 301 "emailSubjectReplyPrefix", 302 securitySession.getUser()) + 303 (((parent == null) || 304 StringHandling.isNullOrEmpty(parent.getSubject())) 305 ? ((item != null) ? item.getTitle() : comment.getItem().getTitle()) 306 : parent.getSubject())); 307 } catch (SettingsDataTypeException e) { 308 throw new SystemException(e); 309 } 310 } 311 return null; 312 } 313 314 339 public String onConfirm(final ActionMapping mapping, 340 final ActionErrors errors, 341 final ActionForm form, 342 final HttpServletRequest request, 343 final HttpServletResponse response, 344 final HttpSession session, 345 final String defaultForward) throws SystemException { 346 347 CommentDO comment = ((CommentForm) form).getComment(); 349 CommentDO parent = comment.getParent(); 350 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession"); 351 StringBuffer openerPage = new StringBuffer (); 352 353 if (((CommentForm) form).getList().equals("true")) { 354 openerPage.append("/library/openComments.jsp"); 355 } else { 356 openerPage.append("/library/display.action?id="); 357 openerPage.append(comment.getItem().getId()); 358 } 359 360 if (comment.getId() == null) { 361 comment.setCreatedBy(securitySession.getUser()); 362 363 Integer parentId = (parent == null) ? null : parent.getId(); 364 365 comment = library.addComment(securitySession, comment); 366 } else { 367 library.amendComment(securitySession, comment); 369 } 370 371 374 if (!((CommentForm) form).getList().equals("true")) { 376 openerPage.append("#comment"); 377 openerPage.append(comment.getId()); 378 } 379 380 request.setAttribute("openerPage", openerPage.toString()); 381 382 return defaultForward; 383 } 384 385 408 public String onDelete(final ActionMapping mapping, 409 final ActionErrors errors, 410 final ActionForm form, 411 final HttpServletRequest request, 412 final HttpServletResponse response, 413 final HttpSession session, final String defaultForward) throws SystemException { 414 return null; 415 } 416 } 417 | Popular Tags |