Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 12 → Rev 13

/kickup/trunk/src/ak/kickup/core/action/AdminActAction.java
0,0 → 1,96
package ak.kickup.core.action;
 
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
 
import ak.strutsx.RequestUtilsX;
import ak.strutsx.ErrorHandlerX;
import ak.backpath.BackPath;
 
import ak.kickup.util.StringConverter;
import ak.kickup.util.UserException;
import ak.kickup.core.model.Act;
import ak.kickup.core.model.ActManager;
 
public final class AdminActAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(ActManager.getInstance().listActs());
Collections.sort(list, ActManager.NAME_COMPARATOR);
request.setAttribute("acts", list);
return mapping.findForward("default");
}
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long actId = StringConverter.parseLong(theForm.get("id"));
Act act;
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
this, request, "ActEditForm");
 
if(actId == null) {
act = ActManager.getInstance().create();
}
else {
act = ActManager.getInstance().get(actId);
showForm.set("name", act.getName());
showForm.set("comment", act.getComment());
}
 
return mapping.findForward("default");
}
else if("delete".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long actId = StringConverter.parseLong(theForm.get("id"));
Act act = ActManager.getInstance().get(actId);
 
ActManager.getInstance().delete(act);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else if("submit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long actId = StringConverter.parseLong(theForm.get("id"));
Act act;
 
if(actId == null) {
act = ActManager.getInstance().create();
}
else {
act = ActManager.getInstance().get(actId);
}
 
String name = (String)theForm.get("name");
if(ActManager.getInstance().nameExists(act, name)) {
throw new UserException("ak.kickup.core.act.name.nonunique");
}
act.setName(name);
 
act.setComment((String)theForm.get("comment"));
 
ActManager.getInstance().save(act);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
return null;
}
else {
throw new Exception("unknown mapping parameter");
}
}
}