1 package org.apache.turbine.services.template.mapper; 2 3 18 19 import java.util.ArrayList ; 20 import java.util.Arrays ; 21 import java.util.List ; 22 23 import org.apache.commons.lang.StringUtils; 24 25 import org.apache.turbine.modules.Loader; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import org.apache.turbine.services.template.TemplateService; 31 32 50 51 public class ClassMapper 52 extends BaseMapper 53 implements Mapper 54 { 55 56 private Loader loader = null; 57 58 59 private static Log log = LogFactory.getLog(ClassMapper.class); 60 61 66 public ClassMapper() 67 { 68 } 69 70 74 public Loader getLoader() 75 { 76 return loader; 77 } 78 79 83 public void setLoader(Loader loader) 84 { 85 this.loader = loader; 86 log.debug("Loader is " + this.loader); 87 } 88 89 96 public String doMapping(String template) 97 { 98 log.debug("doMapping(" + template + ")"); 99 100 List components 102 = new ArrayList (Arrays.asList(StringUtils.split( 103 template, 104 String.valueOf(TemplateService.TEMPLATE_PARTS_SEPARATOR)))); 105 int componentSize = components.size() - 1 ; 106 107 String className = (String ) components.get(componentSize); 110 components.remove(componentSize--); 111 112 log.debug("className is " + className); 113 114 int dotIndex = className.lastIndexOf(TemplateService.EXTENSION_SEPARATOR); 116 className = (dotIndex < 0) ? className : className.substring(0, dotIndex); 117 118 boolean firstRun = !className.equals(TemplateService.DEFAULT_NAME); 122 123 for(;;) 124 { 125 String pkg = StringUtils.join(components.iterator(), String.valueOf(separator)); 126 StringBuffer testName = new StringBuffer (); 127 128 log.debug("classPackage is now: " + pkg); 129 130 if (!components.isEmpty()) 131 { 132 testName.append(pkg); 133 testName.append(separator); 134 } 135 136 testName.append((firstRun) 137 ? className 138 : TemplateService.DEFAULT_NAME); 139 140 log.debug("Looking for " + testName); 141 try 142 { 143 loader.getAssembler(testName.toString()); 144 log.debug("Found it, returning " + testName); 145 return testName.toString(); 146 } 147 catch (Exception e) 148 { 149 } 151 152 if (firstRun) 153 { 154 firstRun = false; 155 } 156 else 157 { 158 if (components.isEmpty()) 159 { 160 break; } 162 components.remove(componentSize--); 163 } 164 } 165 166 log.debug("Returning default"); 167 return getDefaultName(template); 168 } 169 } 170 171 172 173 174 | Popular Tags |