final String pathBasedContentType = PathUtilities.extractType((String) context.get(Globals.PATH));
String templateName = StringUtils.defaultString(context.getTemplateName(),
RepositoryManager.DEFAULT_TEMPLATE_NAME);
Repository defaultRepository = site.getRepositoryManager().getDefaultRepository();
// verify if there is a default repository decided by 3rd party components; controllers, extensions, etc.
if (context.getDefaultRepositoryName() != null) {
defaultRepository = site.getRepositoryManager()
.getRepository(context.getDefaultRepositoryName());
}
// calculate the Template name
View view = (View) context.get(Globals.VIEW);
if (view != null && StringUtils.isNotBlank(view.getTemplate())) {
templateName = view.getTemplate();
} else {
view = defaultRepository.getView(path);
if (view != null && view.getTemplate() != null) {
templateName = view.getTemplate();
}
}
// Render the Default Template. The template will pull out the View, the result being sent out as
// the Template body merged with the View's own content. Controllers are executed *before*
// rendering the Template *and before* rendering the View, but only if there are any View or Template
// Controllers defined by the user.
Repository templatesRepository = site.getRepositoryManager().getTemplatesRepository();
if (context.getTemplatesRepositoryName() != null) {
templatesRepository = site.getRepositoryManager()
.getRepository(context.getTemplatesRepositoryName());
}
if (templatesRepository != null) {
String out = templatesRepository.getRepositoryWrapper(context)
.get(templateName + pathBasedContentType);
response.withContentLength(out.getBytes(Charset.forName(Globals.UTF8)).length)
.withBody(out);
} else {