ActionForward forward = mapping.findForward("exportEntries.page");
try
{
RollerRequest rreq = RollerRequest.getRollerRequest(request);
RollerSession rses = RollerSession.getRollerSession(rreq.getRequest());
WeblogEntryManagementForm form = (WeblogEntryManagementForm)actionForm;
if ( rreq.getWebsite() != null
&& rses.isUserAuthorizedToAdmin(rreq.getWebsite()) )
{
request.setAttribute("model",
new BasePageModel("", request, response, mapping));
Locale locale = Locale.getDefault();//rreq.getWebsite().getLocaleInstance();
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
Date startDate;
Date endDate;
try
{
startDate = DateUtil.getStartOfDay(df.parse(form.getStartDateString()));
endDate = DateUtil.getEndOfDay(df.parse(form.getEndDateString()));
}
catch (ParseException e)
{
throw new RollerException("ERROR parsing date:" + e.getMessage());
}
if (startDate != null && endDate != null)
{
// this work should go into a Thread!
WeblogManager weblogMgr =
RollerFactory.getRoller().getWeblogManager();
//List entries = weblogMgr.getWeblogEntriesInDateRange(
//rreq.getUser().getUserName(), null, startDate, endDate, false);
//System.out.println("Export: got " + entries.size() + " entries.");
List entries = weblogMgr.getWeblogEntries(
rreq.getWebsite(), // userName
startDate, // startDate
endDate, // endDate
null, // catName
null, // status
null, // sortby (null for pubtime)
null); // maxEntries
ActionMessages messages = writeSuccessMessage(request, response, rreq, form);
// seperate the entries as specified: day, month, year
Map entryMap = seperateByPeriod(entries, form.getFileBy());
// now export each List in the entryMap
ExportRss exporter = new ExportRss(rreq.getWebsite());
String exportTo = form.getExportFormat().toLowerCase();
if ("atom".equals(exportTo))
{
exporter.setExportAtom(true);
}
ArrayList fileNames = new ArrayList();
Iterator it = entryMap.keySet().iterator();
while(it.hasNext())
{
String key = (String)it.next();
ArrayList list = (ArrayList)entryMap.get(key);
exporter.exportEntries(list, key+"_"+exportTo+".xml");
fileNames.add("Exported " + list.size() + " entry(s) to " + key+"_"+exportTo+".xml<br />");
//System.out.println("Exported: " + list.size() + " entries for " + key);
}
StringBuffer fileMessage = new StringBuffer();
it = fileNames.iterator();
while (it.hasNext())
{
fileMessage.append((String)it.next());
}
if (fileMessage.length() > 0)
{
messages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("weblogEntryExport.exportFiles",
fileMessage.toString()));
}
saveMessages(request, messages);
}
else
{
form.reset(mapping, (ServletRequest)request);
return edit(mapping, actionForm, request, response);
}
//forward = mapping.findForward("exportEntries.done");
}