in src/java/org/apache/turbine/services/template/mapper/ScreenDefaultTemplateMapper.java [71:155]
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;
}
String defaultName = "Default.vm";
// 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 run this loop only two times. The
// first time with the 'real' name and the
// second time with "Default". The second time
// we will end up here and break the for(;;) loop.
break;
}
}
log.debug("Returning default");
return getDefaultName(template);
}