// analysis, and ease of code reading too - Pending further thought
String line = null;
while ((line = br.readLine()) != null)
{
// get the log line object
LogLine logLine = getLogLine(line);
// if there are line segments get on with the analysis
if (logLine != null)
{
// first find out if we are constraining by date and
// if so apply the restrictions
if ((startDate != null) && (!logLine.afterDate(startDate)))
{
continue;
}
if ((endDate !=null) && (!logLine.beforeDate(endDate)))
{
break;
}
// count the number of lines parsed
lineCount++;
// if we are not constrained by date, register the date
// as the start/end date if it is the earliest/latest so far
// FIXME: this should probably have a method of its own
if (startDate == null)
{
if (logStartDate != null)
{
if (logLine.beforeDate(logStartDate))
{
logStartDate = logLine.getDate();
}
}
else
{
logStartDate = logLine.getDate();
}
}
if (endDate == null)
{
if (logEndDate != null)
{
if (logLine.afterDate(logEndDate))
{
logEndDate = logLine.getDate();
}
}
else
{
logEndDate = logLine.getDate();
}
}
// count the warnings
if (logLine.isLevel("WARN"))
{
// FIXME: really, this ought to be some kind of level
// aggregator
warnCount++;
}
// is the action a search?
if (logLine.isAction("search"))
{
// get back all the valid search words from the query
String[] words = analyseQuery(logLine.getParams());
// for each search word add to the aggregator or
// increment the aggregator's counter
for (int j = 0; j < words.length; j++)
{
// FIXME: perhaps aggregators ought to be objects
// themselves
searchAggregator.put(words[j], increment(searchAggregator, words[j]));
}
}
// is the action a login, and are we counting user logins?
if (logLine.isAction("login") && !userEmail.equals("off"))
{
userAggregator.put(logLine.getUser(), increment(userAggregator, logLine.getUser()));
}
// is the action an item view?
if (logLine.isAction("view_item"))
{
String handle = logLine.getParams();
// strip the handle string
Matcher matchHandle = handleRX.matcher(handle);
handle = matchHandle.replaceAll("");
// strip the item id string
Matcher matchItem = itemRX.matcher(handle);
handle = matchItem.replaceAll("");
handle.trim();
// either add the handle to the aggregator or
// increment its counter
itemAggregator.put(handle, increment(itemAggregator, handle));
}
// log all the activity
actionAggregator.put(logLine.getAction(), increment(actionAggregator, logLine.getAction()));
}
}
// close the file reading buffers
br.close();