* @return String The result of the action.
*/
public String save() {
if(!hasActionErrors()) try {
WeblogManager weblogMgr = WebloggerFactory.getWeblogger().getWeblogManager();
WeblogEntry entry = new WeblogEntry();
entry.setCreator(getAuthenticatedUser());
entry.setWebsite(getActionWeblog());
// set updatetime & pubtime if it was specified
entry.setUpdateTime(new Timestamp(new Date().getTime()));
entry.setPubTime(getBean().getPubTime(getLocale(), getActionWeblog().getTimeZoneInstance()));
// copy data to new entry pojo
getBean().copyTo(entry);
// handle pubtime auto set
if(entry.isPublished()) {
if(entry.getPubTime() == null) {
// no time specified, use current time
entry.setPubTime(entry.getUpdateTime());
}
// if user does not have author perms then force PENDING status
if(!getActionWeblog().hasUserPermissions(getAuthenticatedUser(),WeblogPermission.AUTHOR)) {
entry.setStatus(WeblogEntry.PENDING);
}
}
// if user is an admin then apply pinned to main value as well
if(getAuthenticatedUser().hasRole("admin")) {
entry.setPinnedToMain(getBean().getPinnedToMain());
}
if(!StringUtils.isEmpty(getBean().getEnclosureURL())) try {
// Fetch MediaCast resource
log.debug("Checking MediaCast attributes");
MediacastResource mediacast = MediacastUtil.lookupResource(getBean().getEnclosureURL());
// set mediacast attributes
entry.putEntryAttribute("att_mediacast_url", mediacast.getUrl());
entry.putEntryAttribute("att_mediacast_type", mediacast.getContentType());
entry.putEntryAttribute("att_mediacast_length", ""+mediacast.getLength());
} catch (MediacastException ex) {
addMessage(getText(ex.getErrorKey()));
}
if(log.isDebugEnabled()) {
log.debug("entry bean is ...\n"+getBean().toString());
log.debug("final status = "+entry.getStatus());
log.debug("updtime = "+entry.getUpdateTime());
log.debug("pubtime = "+entry.getPubTime());
}
log.debug("Saving entry");
weblogMgr.saveWeblogEntry(entry);
WebloggerFactory.getWeblogger().flush();
// notify search of the new entry
reindexEntry(entry);