/* (non-Javadoc)
* @see com.apress.prospring.web.struts.AbstractBlogManagerAction#executeInternal(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected ActionForward executeInternal(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String forward;
Entry entry;
EditEntryForm entryForm = (EditEntryForm)form;
if (request.getParameter("submit") == null) {
// we need to load the entry
int entryId = RequestUtils.getRequiredIntParameter(request, "entryId");
entry = getBlogManager().getEntry(entryId);
BeanUtils.copyProperties(entryForm, entry);
entryForm.setPostDateTime(entry.getPostDate().getTime());
forward = "edit";
} else {
// we are saving the entry
entry = new Entry();
BeanUtils.copyProperties(entry, entryForm);
entry.setPostDate(new Date(entryForm.getPostDateTime()));
getBlogManager().saveEntry(entry, SessionSecurityManager.getUser(request));
if (entryForm.getAttachment() != null) {
Attachment attachment = new Attachment();
attachment.setContentType("");
attachment.setFileData(entryForm.getAttachment().getFileData());
attachment.setFileName("attachment.txt");
getBlogManager().attachToEntry(attachment, entry.getEntryId());
}
forward = "posted";
}
return mapping.findForward(forward);