1 package org.nemesis.forum.webapp.admin.action; 2 3 import java.util.Iterator ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 8 import org.apache.commons.beanutils.PropertyUtils; 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.apache.struts.action.ActionError; 12 import org.apache.struts.action.ActionErrors; 13 import org.apache.struts.action.ActionForm; 14 import org.apache.struts.action.ActionForward; 15 import org.apache.struts.action.ActionMapping; 16 import org.nemesis.forum.Forum; 17 import org.nemesis.forum.ForumFactory; 18 import org.nemesis.forum.ProfileManager; 19 import org.nemesis.forum.User; 20 import org.nemesis.forum.config.Constants; 21 import org.nemesis.forum.exception.AlreadyExistsException; 22 import org.nemesis.forum.exception.UnauthorizedException; 23 import org.nemesis.forum.webapp.admin.bean.ForumBean; 24 25 26 27 32 public class AddForumAction extends BaseAction { 33 34 static protected Log log =LogFactory.getLog(AddForumAction.class); 35 36 37 public ActionForward execute(ActionMapping mapping, 38 ActionForm form, 39 HttpServletRequest request, 40 HttpServletResponse response) 41 throws Exception { 42 43 checkUser(request); 45 checkPermission(request,OperationConstants.ADD_FORUM); 47 48 49 ActionErrors errors = new ActionErrors(); 50 if (isCancelled(request)) { 52 return (mapping.findForward("cancel")); 53 } 54 55 try { 56 57 58 ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request)); 59 ProfileManager manager = forumFactory.getProfileManager(); 60 User user = manager.getUser(getAuthToken(request).getUserID()); 61 try { 62 63 ForumBean fb=(ForumBean)PropertyUtils.getProperty(form, "forumBean"); 64 ForumFactory ff =ForumFactory.getInstance(getAuthToken(request)); 65 Forum f =ff.createForum(fb.getName(),fb.getDescription()); 66 67 71 f.addUserPermission(user,Constants.READ); 73 f.addUserPermission(user,Constants.MODERATOR); 74 f.addUserPermission(user,Constants.CREATE_THREAD); 75 f.addUserPermission(user,Constants.CREATE_MESSAGE); 76 f.addUserPermission(user,Constants.FORUM_ADMIN); 77 80 f.setModerationType(fb.getModerationType()); 81 82 String temp=null; 84 for(Iterator it=fb.getProperties().keySet().iterator();it.hasNext();){ 85 temp=(String )it.next(); 86 f.setProperty(temp,(String )fb.getProperties().get(temp)); 87 } 88 89 90 } 91 catch( AlreadyExistsException aee ) { 92 errors.add("general", new ActionError("addForum.alreadyExist")); 93 } 94 catch( UnauthorizedException aee ) { 95 aee.printStackTrace(); 96 errors.add("general", new ActionError("addForum.unauthorized")); 97 saveErrors(request, errors); 98 return mapping.findForward("cancel"); 99 } 100 101 } catch (Exception e) { 102 String eid=this.getClass().getName()+"_"+System.currentTimeMillis(); 103 log.error("eid:"+eid+"\nsessionID" +request.getSession().getId(),e) ; 104 errors.add("general", new ActionError("error.general","erreur id:"+eid)); 105 } 106 107 if (!errors.isEmpty()) { 108 saveErrors(request, errors); 109 return (mapping.getInputForward()); 110 } 111 112 return mapping.findForward("success"); 113 } 114 115 } | Popular Tags |