* @throws FileNotFoundException
* @throws ViewException
*/
@Override
public RackResponse call(MicroContext context) throws Exception {
RackResponse response = null;
if (context != null) {
SiteContext site = context.getSiteContext();
if (!CollectionUtils.isEmpty(getControllers())) {
for (int i = 0; i < getControllers().size(); i++) {
Map<String, Object> controllerMap = getControllers().get(i);
site.getControllerManager().execute((String) controllerMap.get(Globals.NAME),
context, (Map) controllerMap.get(Globals.OPTIONS));
if (context.isHalt()) return context.getRackResponse();
}
}
if (getView() != null && getView().getPath() != null) {
response = context.getRackResponse();
RepositoryManager repositoryManager = site.getRepositoryManager();
String repositoryName = StringUtils.defaultString(getView().getRepositoryName(),
repositoryManager.getDefaultRepository().getName());
String path = getView().getPath();
context.with(Globals.PATH, path);
String out;
if (getView().getTemplate() != null) {
out = repositoryManager.getTemplatesRepository().getRepositoryWrapper(context)
.get(getView().getTemplate() + PathUtilities.extractType(path));
} else {
Repository repository = repositoryManager.getRepository(repositoryName);
out = repository.getRepositoryWrapper(context).get(getView().getPath());
}
String contentType = Mime.mimeType(PathUtilities.extractType(path));
if (response.getHeaders().get(Globals.HEADERS_CONTENT_TYPE) != null) {
contentType = response.getHeaders().get(Globals.HEADERS_CONTENT_TYPE);
}
response.withContentType(contentType)
.withContentLength(out.getBytes(Charset.forName(Globals.UTF8)).length)
.withBody(out);
// We have a View served by
// Faites vos jeux, rien ne va plus