components.remove(componentSize--);
log.debug("templateName is " + templateName);
// Last element decides, which template Service to use...
TemplateEngineService tes = TurbineTemplate.getTemplateEngineService(templateName);
if (tes == null)
{
return null;
}
String defaultName =
TurbineTemplate.getDefaultLayoutTemplateName(templateName); // We're, after all, a Layout Template Mapper...
// This is an optimization. If the name we're looking for is
// already the default name for the template, don't do a "first run"
// which looks for an exact match.
boolean firstRun = !templateName.equals(defaultName);
for(;;)
{
String templatePackage = StringUtils.join(components.iterator(), String.valueOf(separator));
log.debug("templatePackage is now: " + templatePackage);
StringBuffer testName = new StringBuffer();
if (!components.isEmpty())
{
testName.append(templatePackage);
testName.append(separator);
}
testName.append((firstRun)
? templateName
: defaultName);
// But the Templating service must look for the name with prefix
StringBuffer templatePath = new StringBuffer();
if (StringUtils.isNotEmpty(prefix))
{
templatePath.append(prefix);
templatePath.append(separator);
}
templatePath.append(testName);
log.debug("Looking for " + templatePath);
if (tes.templateExists(templatePath.toString()))
{
log.debug("Found it, returning " + testName);
return testName.toString();
}