1 25 26 package com.j2biz.blogunity.web.actions.my; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.apache.commons.lang.StringUtils; 32 33 import com.j2biz.blogunity.dao.BlogDAO; 34 import com.j2biz.blogunity.exception.BlogunityException; 35 import com.j2biz.blogunity.i18n.I18N; 36 import com.j2biz.blogunity.i18n.I18NStatusFactory; 37 import com.j2biz.blogunity.pojo.Blog; 38 import com.j2biz.blogunity.web.ActionResultFactory; 39 import com.j2biz.blogunity.web.IActionResult; 40 41 48 public class EditBlogExecAction extends MyAbstractAction { 49 50 private static final IActionResult BLOG_FORM_FORWARD = ActionResultFactory 51 .buildForward("/jsp/my/editBlogForm.jsp"); 52 53 59 public IActionResult execute(HttpServletRequest request, HttpServletResponse response) 60 throws BlogunityException { 61 62 String id = request.getParameter("id"); 63 64 if (StringUtils.isEmpty(id)) { throw new BlogunityException(I18NStatusFactory.create( 65 I18N.ERRORS.ID_NOT_SETTED, "Blog")); } 66 67 String fullname = request.getParameter("fullname"); 68 String description = request.getParameter("description"); 69 String keywords = request.getParameter("keywords"); 70 String commentingAllowd = request.getParameter("commenting"); 71 String anonymousCommentingAllowed = request.getParameter("anonymousCommenting"); 72 73 BlogDAO blogDAO = new BlogDAO(); 74 Blog b = blogDAO.getBlogByID(Long.parseLong(id)); 75 76 if (user.getId().longValue() != b.getFounder().getId().longValue() 79 && !user.isAdministrator()) 80 throw new BlogunityException(I18NStatusFactory 81 .create(I18N.ERRORS.USER_NOT_AUTHORIZED_FOR_EXECUTION)); 82 83 b.setFullName(StringUtils.isEmpty(fullname) ? b.getUrlName() : fullname); 84 b.setDescription(StringUtils.isEmpty(description) ? null : description); 85 b.setKeywords(StringUtils.isEmpty(keywords) ? null : keywords); 86 87 if (b.getType() == Blog.COMMUNITY_BLOG) { 88 String communityType = request.getParameter("communityType"); 89 try { 90 b.setCommunityType(Integer.parseInt(communityType)); 91 } catch (NumberFormatException e) { 92 b.setCommunityType(Blog.PUBLIC_COMMUNTIY); 93 } 94 } 95 96 request.setAttribute("requestedBlog", b); 97 return BLOG_FORM_FORWARD; 98 } 99 100 } | Popular Tags |