throws IOException, ServletException {
ActionForward forward = mapping.findForward("weblogEdit.page");
ActionMessages uiMessages = new ActionMessages();
try {
WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
Roller roller = RollerFactory.getRoller();
RollerSession rses = RollerSession.getRollerSession(request);
UserManager userMgr = roller.getUserManager();
WeblogManager weblogMgr = roller.getWeblogManager();
UserData ud = userMgr.getUser(form.getCreatorId());
WebsiteData site = userMgr.getWebsite(form.getWebsiteId());
WeblogEntryData entry = null;
if ( rses.isUserAuthorizedToAuthor(site)
|| (rses.isUserAuthorized(site)
&& !form.getStatus().equals(WeblogEntryData.PUBLISHED) )) {
ActionErrors errors = validateEntry(null, form);
if (errors.size() > 0) {
saveErrors(request, errors);
request.setAttribute("model",
new WeblogEntryPageModel(request, response, mapping,
(WeblogEntryFormEx)actionForm,
WeblogEntryPageModel.EDIT_MODE));
return forward;
}
if (form.getId() == null || form.getId().trim().length()==0) {
entry = new WeblogEntryData();
entry.setCreator(ud);
entry.setWebsite( site );
} else {
entry = weblogMgr.getWeblogEntry(form.getId());
}
mLogger.debug("setting update time now");
form.setUpdateTime(new Timestamp(new Date().getTime()));
if ("PUBLISHED".equals(form.getStatus()) &&
"0/0/0".equals(form.getDateString())) {
mLogger.debug("setting pubtime now");
/* NOTE: the wf.copyTo() method will override this value
* based on data submitted with the form if that data is
* not null. check the method to verify.
*
* this means that setting the pubtime here only takes
* effect if the entry is being published for the first
* time.
*/
form.setPubTime(form.getUpdateTime());
}
mLogger.debug("copying submitted form data to entry object");
form.copyTo(entry, request.getLocale(),request.getParameterMap());
// Fetch MediaCast content type and length
mLogger.debug("Checking MediaCast attributes");
if (!checkMediaCast(entry, uiMessages)) {
mLogger.debug("Invalid MediaCast attributes");
} else {
mLogger.debug("Validated MediaCast attributes");
}
// Store value object (creates new or updates existing)
entry.setUpdateTime(new Timestamp(new Date().getTime()));
// make sure we have an anchor value set
if(entry.getAnchor() == null || entry.getAnchor().trim().equals("")) {
entry.setAnchor(weblogMgr.createAnchor(entry));
}
mLogger.debug("Saving entry");
weblogMgr.saveWeblogEntry(entry);
RollerFactory.getRoller().flush();
mLogger.debug("Populating form");
form.copyFrom(entry, request.getLocale());
request.setAttribute(
RequestConstants.WEBLOGENTRY_ID, entry.getId());
// Reindex entry, flush caches, etc.
reindexEntry(RollerFactory.getRoller(), entry);
mLogger.debug("Removing from cache");
RollerRequest rreq = RollerRequest.getRollerRequest(request);
//PageCacheFilter.removeFromCache(request, entry.getWebsite());
CacheManager.invalidate(entry);
// Queue applicable pings for this update.
if(entry.isPublished()) {
RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(entry);
}
// Clean up session objects we used
HttpSession session = request.getSession(true);
session.removeAttribute("spellCheckEvents");
session.removeAttribute("entryText");
// Load up request with data for view
request.setAttribute("model",
new WeblogEntryPageModel(request, response, mapping,
(WeblogEntryFormEx)actionForm,
WeblogEntryPageModel.EDIT_MODE));
if (!rses.isUserAuthorizedToAuthor(site) &&
rses.isUserAuthorized(site) && entry.isPending()) {
// implies that entry just changed to pending
notifyWebsiteAuthorsOfPendingEntry(request, entry);
uiMessages.add(null,
new ActionMessage("weblogEdit.submittedForReview"));
// so clear entry from editor
actionForm = new WeblogEntryFormEx();
request.setAttribute(mapping.getName(), actionForm);
forward = create(mapping, actionForm, request, response);
} else {
uiMessages.add(null,
new ActionMessage("weblogEdit.changesSaved"));