use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class AddRoleAction method execute.
/**
* AddRoleAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
String name = context.getRequest().getParameter("name");
if (name == null || name.trim().length() == 0) {
return this.handleSuccess(mapping, context, "success");
}
String description = context.getRequest().getParameter("description");
if (description == null) {
description = "";
}
RoleSecurity role = new RoleSecurity(-1, name, description);
AuthorizationPersistence ap = PersistenceManager.getInstance().getAuthorizationPersistence();
ap.createRole(role, context.getUserProfile().getId());
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class BaseAction method execute.
/**
* This is where the action processes the request. It forwards the invocation to the abstract execute() method and
* returns its forward. Unexcepted exceptions are handled.
*
* @param mapping
* the action mapping that holds the forwards.
* @param form
* the form bean for input.
* @param request
* the http servlet request.
* @param response
* the http servlet response.
*
* @return an action forward or null if the response is committed.
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
UserProfile user = (UserProfile) request.getSession().getAttribute(ContextAdapter.USER_PROFILE_SESSION_KEY);
long actionId = PerformanceManager.getInstance().actionStart(this, request, user);
ContextAdapter context = null;
ActionForward forward = null;
try {
context = new ContextAdapter(request, response);
this.info(this.makeInfo(BaseAction.ENTER_OP, context.getOperator(), null, request));
// log parameters with debug level
/*
* debug("Received parameters:"); for (Enumeration enu = request.getParameterNames();
* enu.hasMoreElements();) { String name = (String) enu.nextElement(); debug("[" + name + "]"); for (int i =
* 0; i < request.getParameterValues(name).length; ++i) { debug(" [" + request.getParameterValues(name)[i]
* + "]"); } }
*/
forward = this.execute(mapping, form, context);
} catch (Exception e) {
this.error(e);
forward = this.handleFailure(mapping, context, BaseAction.GENERIC_ERROR_RESOURCE_KEY);
}
PerformanceManager.getInstance().actionEnd(actionId);
return forward;
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class BaseAction method handleSuccess.
/**
* Handle successful exit with log. Helper method.
*
* @param mapping
* the action mapping that holds the forwards.
* @param context
* the action context to access resources.
* @param forwardName
* represents messsageKey if fail, forward name if succeed.
*
* @return the specified forward.
*/
protected ActionForward handleSuccess(ActionMapping mapping, ContextAdapter context, String forwardName, String parameter) {
String newPath = mapping.findForward(forwardName).getPath() + parameter;
ActionForward forward = new RedirectingActionForward(newPath);
return this.handleSuccess(forward, context, forwardName);
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class DeleteProblemAction method execute.
/**
* Register.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check problem
boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblem.do");
ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
Problem problem = context.getProblem();
ActionMessages messages = new ActionMessages();
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());
messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));
this.saveErrors(context.getRequest(), messages);
String back = isProblemset ? "showProblems" : "showContestProblems";
context.setAttribute("back", back + ".do?contestId=" + context.getContest().getId());
ContestManager.getInstance().refreshContest(context.getContest().getId());
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class ShowRolesAction method execute.
/**
* ShowRolesAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
List<RoleSecurity> roles = authorizationPersistence.getAllRoles();
context.setAttribute("Roles", roles);
return this.handleSuccess(mapping, context, "success");
}
Aggregations