{
Calendar startTime;
Calendar stopTime;
int numDays = DEFAULT_DAYS;
WikiEngine engine = context.getEngine();
AuthorizationManager mgr = engine.getAuthorizationManager();
//
// Parse parameters.
//
String days;
DateFormat entryFormat;
String startDay = null;
boolean hasComments = false;
int maxEntries;
String weblogName;
if( (weblogName = params.get(PARAM_PAGE)) == null )
{
weblogName = context.getPage().getName();
}
if( (days = context.getHttpParameter( "weblog."+PARAM_DAYS )) == null )
{
days = params.get( PARAM_DAYS );
}
if( ( params.get(PARAM_ENTRYFORMAT)) == null )
{
entryFormat = Preferences.getDateFormat( context, TimeFormat.DATETIME );
}
else
{
entryFormat = new SimpleDateFormat( params.get(PARAM_ENTRYFORMAT) );
}
if( days != null )
{
if( days.equalsIgnoreCase("all") )
{
numDays = Integer.MAX_VALUE;
}
else
{
numDays = TextUtil.parseIntParameter( days, DEFAULT_DAYS );
}
}
if( (startDay = params.get(PARAM_STARTDATE)) == null )
{
startDay = context.getHttpParameter( "weblog."+PARAM_STARTDATE );
}
if( TextUtil.isPositive( params.get(PARAM_ALLOWCOMMENTS) ) )
{
hasComments = true;
}
maxEntries = TextUtil.parseIntParameter( params.get(PARAM_MAXENTRIES),
Integer.MAX_VALUE );
//
// Determine the date range which to include.
//
startTime = Calendar.getInstance();
stopTime = Calendar.getInstance();
if( startDay != null )
{
SimpleDateFormat fmt = new SimpleDateFormat( DEFAULT_DATEFORMAT );
try
{
Date d = fmt.parse( startDay );
startTime.setTime( d );
stopTime.setTime( d );
}
catch( ParseException e )
{
return "Illegal time format: "+startDay;
}
}
//
// Mark this to be a weblog
//
context.getPage().setAttribute(ATTR_ISWEBLOG, "true");
//
// We make a wild guess here that nobody can do millisecond
// accuracy here.
//
startTime.add( Calendar.DAY_OF_MONTH, -numDays );
startTime.set( Calendar.HOUR, 0 );
startTime.set( Calendar.MINUTE, 0 );
startTime.set( Calendar.SECOND, 0 );
stopTime.set( Calendar.HOUR, 23 );
stopTime.set( Calendar.MINUTE, 59 );
stopTime.set( Calendar.SECOND, 59 );
StringBuffer sb = new StringBuffer();
try
{
List<WikiPage> blogEntries = findBlogEntries( engine.getPageManager(),
weblogName,
startTime.getTime(),
stopTime.getTime() );
Collections.sort( blogEntries, new PageDateComparator() );
sb.append("<div class=\"weblog\">\n");
for( Iterator i = blogEntries.iterator(); i.hasNext() && maxEntries-- > 0 ; )
{
WikiPage p = (WikiPage) i.next();
if( mgr.checkPermission( context.getWikiSession(),
new PagePermission(p, PagePermission.VIEW_ACTION) ) )
{
addEntryHTML(context, entryFormat, hasComments, sb, p);
}
}