public void request(StringFinder context) {
OutputStream outstream = (OutputStream)context.getObject(MojasefConstants.RESPONSE_STREAM);
StreamStringCollector collector = new StreamStringCollector(outstream);
Tract page = null;
String filename = context.get(MojasefConstants.REQUEST_LOCALPATH);
page = (Tract)tracts.getObject(filename);
if (page == null && ("".equals(filename) || filename.endsWith("/"))) {
page = (Tract)tracts.getObject(filename+context.get(MojasefConstants.DEFAULT_LEAFNAME));
}
if (page == null) {
page = (Tract)templates.getObject("404");
}
if (page == null) {
page = new MapTract("Oops, 404: ${mojasef.request.path.URI}");
StorerHelper.put(context, HTTPConstants.RESPONSE_CODE, "404");
}
StringFinder result = new FetcherStringFinder(
new FallbackFetcher(page.getUnderlyingFetcher(), context.getUnderlyingFetcher()));
Tract template = findTemplate(result);
engine.expandTemplate(context, template, collector);
collector.flush();
}