1 package org.apache.turbine.services.template.mapper; 2 3 18 19 import java.util.List ; 20 import java.util.ArrayList ; 21 import java.util.Arrays ; 22 23 import org.apache.commons.lang.StringUtils; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import org.apache.turbine.services.template.TemplateEngineService; 29 import org.apache.turbine.services.template.TemplateService; 30 import org.apache.turbine.services.template.TurbineTemplate; 31 32 42 43 public class ScreenDefaultTemplateMapper 44 extends BaseTemplateMapper 45 implements Mapper 46 { 47 48 private static Log log = LogFactory.getLog(ScreenDefaultTemplateMapper.class); 49 50 55 public ScreenDefaultTemplateMapper() 56 { 57 } 58 59 66 public String doMapping(String template) 67 { 68 log.debug("doMapping(" + template + ")"); 69 List components 71 = new ArrayList (Arrays.asList(StringUtils.split( 72 template, 73 String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR)))); 74 int componentSize = components.size() - 1 ; 75 76 String templateName = (String ) components.get(componentSize); 79 components.remove(componentSize--); 80 81 log.debug("templateName is " + templateName); 82 83 TemplateEngineService tes = TurbineTemplate.getTemplateEngineService(templateName); 85 86 if (tes == null) 87 { 88 return null; 89 } 90 91 String defaultName = "Default.vm"; 92 93 boolean firstRun = !templateName.equals(defaultName); 97 98 for(;;) 99 { 100 String templatePackage = StringUtils.join(components.iterator(), String.valueOf(separator)); 101 102 log.debug("templatePackage is now: " + templatePackage); 103 104 StringBuffer testName = new StringBuffer (); 105 106 if (!components.isEmpty()) 107 { 108 testName.append(templatePackage); 109 testName.append(separator); 110 } 111 112 testName.append((firstRun) 113 ? templateName 114 : defaultName); 115 116 StringBuffer templatePath = new StringBuffer (); 118 if (StringUtils.isNotEmpty(prefix)) 119 { 120 templatePath.append(prefix); 121 templatePath.append(separator); 122 } 123 templatePath.append(testName); 124 125 log.debug("Looking for " + templatePath); 126 127 if (tes.templateExists(templatePath.toString())) 128 { 129 log.debug("Found it, returning " + testName); 130 return testName.toString(); 131 } 132 133 if (firstRun) 134 { 135 firstRun = false; 136 } 137 else 138 { 139 break; 144 } 145 } 146 147 log.debug("Returning default"); 148 return getDefaultName(template); 149 } 150 } 151 | Popular Tags |