* current request, from local storage, or from remote peers as needed.
*/
protected Feed currentFeed(RequestContext request) throws ParseException,
FileNotFoundException, IOException {
Feed feed = null;
RequestContextWrapper wrapper = new RequestContextWrapper(request);
// System.err.println(new Date().toString() + " "
// + wrapper.getTargetPath());
// fetch from request context
feed = (Feed) wrapper.getAttribute(Scope.REQUEST, "com.trsst.Feed");
if (feed != null) {
// shortcut for very common case
return feed;
}
feed = Abdera.getInstance().newFeed();
feed.setId(canonicalFeedIdForQuery(request));
// build a title string from query params
List<String> values;
String title = "";
values = request.getParameters("tag");
if (values != null) {
for (String value : values) {
title = title + '#' + value + ' ';
}
}
values = request.getParameters("mention");
if (values != null) {
for (String value : values) {
title = title + '@' + value + ' ';
}
}
String query = request.getParameter("q");
if (query != null) {
title = title + query;
}
title = title.trim();
if (title.length() == 0) {
title = "Search Results";
}
feed.setTitle(title);
// default to one month ago in case of zero results
feed.setUpdated(new Date(System.currentTimeMillis() - 1000 * 60 * 60
* 24 * 30));
if (feed != null) {
if (feed.getEntries().size() == 0
|| wrapper.getParameter("sync") != null) {
// no local results: check the relays now
pullFromRelay(feedId, request);
} else {
// we have some results: return these and check relays later
pullLaterFromRelay(feedId, request);
}
}
// store in request context
wrapper.setAttribute(Scope.REQUEST, "com.trsst.Feed", feed);
return feed;
}