Package org.nemesis.forum.webapp.admin.action

Source Code of org.nemesis.forum.webapp.admin.action.EditForumAction

package org.nemesis.forum.webapp.admin.action;

import java.util.Enumeration;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.nemesis.forum.Forum;
import org.nemesis.forum.ForumFactory;
import org.nemesis.forum.webapp.admin.bean.ForumBean;
import org.nemesis.forum.webapp.exception.UnauthorizedException;

/**
* @author dlaurent
*
* 20 f�vr. 2003
*/
public class EditForumAction extends BaseAction {

  static protected Log log = LogFactory.getLog(EditForumAction.class);

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    //check logon
    checkUser(request);

    ActionErrors errors = new ActionErrors();
    //    user need cancel
    if (isCancelled(request)) {
      return (mapping.findForward("cancel"));
    }

    try {

      ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request));
      Forum forum = forumFactory.getForum(Integer.parseInt(request.getParameter("id")));

      //check permission
      checkPermission(request, OperationConstants.EDIT_FORUM, forum);

      //first, populate
      if (request.getParameter("forumBean.id") == null) {
       
        ForumBean fb =new ForumBean();
        fb.setDescription(forum.getDescription());
        fb.setId(forum.getID());
        fb.setModerationType(forum.getModerationType());
        fb.setName(forum.getName());
        String key=null;
        for(Enumeration e= forum.propertyNames();e.hasMoreElements();){
          key=(String)e.nextElement();
          fb.setPropertie(key, forum.getProperty(key));
        }

        PropertyUtils.setProperty(form, "forumBean", fb);
        return mapping.findForward("view");
      }

      //save     
      ForumBean fb = (ForumBean) PropertyUtils.getProperty(form, "forumBean");
      forum.setModerationType(fb.getModerationType());
      forum.setDescription(fb.getDescription());
      //non forum.setName(fb.getDescription());
     
      //properties
      String temp = null;
      for (Iterator it = fb.getProperties().keySet().iterator(); it.hasNext();) {
        temp = (String) it.next();
        forum.setProperty(temp, (String) fb.getProperties().get(temp));
      }

    } catch (NumberFormatException aee) {
      errors.add("general", new ActionError("addForum.unauthorized"));
    } catch (UnauthorizedException aee) {     
      errors.add("general", new ActionError("addForum.unauthorized"));
      saveErrors(request, errors);
      return mapping.findForward("cancel");
    } catch (Exception e) {
      String eid = this.getClass().getName() + "_" + System.currentTimeMillis();
      log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e);
      errors.add("general", new ActionError("error.general", "erreur id:" + eid));
    }

    if (!errors.isEmpty()) {
      saveErrors(request, errors);
      return (mapping.findForward("cancel"));
    }

    return mapping.findForward("success");
  }

}
TOP

Related Classes of org.nemesis.forum.webapp.admin.action.EditForumAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.