public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res)
throws Exception
{
RollerRequest rreq = RollerRequest.getRollerRequest(req);
PingTargetManager pingTargetMgr =
RollerFactory.getRoller().getPingTargetManager();
PingTargetForm pingTargetForm = (PingTargetForm) form;
try
{
BasePageModel pageModel =
new BasePageModel(getPingTargetEditTitle(), req, res, mapping);
req.setAttribute("model",pageModel);
if (!hasRequiredRights(rreq, rreq.getWebsite()))
{
return mapping.findForward(ACCESS_DENIED_PAGE);
}
PingTargetData pingTarget = null;
String pingTargetId = pingTargetForm.getId();
if (pingTargetId != null && pingTargetId.length() > 0)
{
pingTarget = pingTargetMgr.getPingTarget(
pingTargetForm.getId());
if (pingTarget == null)
throw new RollerException(
"No such ping target id: " + pingTargetId);
pingTargetForm.copyTo(pingTarget, req.getLocale());
}
else
{
pingTarget = createPingTarget(rreq, pingTargetForm);
}
// Call private helper to validate ping target
// If there are errors, go back to the target edit page.
ActionMessages errors = validate(rreq, pingTarget);
if (!errors.isEmpty()) {
saveErrors(rreq.getRequest(), errors);
return mapping.findForward(PING_TARGET_EDIT_PAGE);
}
// Appears to be ok.
// Save it, commit and return refreshed view of target list.
pingTargetMgr.savePingTarget(pingTarget);
RollerFactory.getRoller().flush();
ActionMessages msgs = new ActionMessages();
msgs.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("pingTarget.saved"));