in src/java/org/apache/turbine/services/template/mapper/LayoutTemplateMapper.java [75:166]
public String doMapping(String template)
{
log.debug("doMapping({})", template);
// Copy our elements into an array
List<String> components
= new ArrayList<>(Arrays.asList(StringUtils.split(
template,
String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR))));
int componentSize = components.size() - 1 ;
// This method never gets an empty string passed.
// So this is never < 0
String templateName = components.get(componentSize);
components.remove(componentSize--);
log.debug("templateName is {}", templateName);
// Last element decides, which template Service to use...
TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
TemplateEngineService tes = templateService.getTemplateEngineService(templateName);
if (tes == null)
{
return null;
}
// We're, after all, a Layout Template Mapper...
String defaultName = templateService.getDefaultLayoutTemplateName(templateName);
// 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);
StringBuilder testName = new StringBuilder();
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
StringBuilder templatePath = new StringBuilder();
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();
}
if (firstRun)
{
firstRun = false;
}
else
{
// We're no longer on the first Run (so we
// already tested the "Default" template)
// and the package is empty (we've hit the
// root. So we now break the endless loop.
if (components.isEmpty())
{
break; // for(;;)
}
// We still have components. Remove the
// last one and go through the loop again.
components.remove(componentSize--);
}
}
log.debug("Returning default");
return getDefaultName(template);
}