1 package org.apache.turbine.modules.pages; 2 3 18 19 import java.util.List ; 20 21 import org.apache.commons.lang.StringUtils; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.ecs.Doctype; 26 27 import org.apache.turbine.Turbine; 28 import org.apache.turbine.TurbineConstants; 29 import org.apache.turbine.modules.ActionLoader; 30 import org.apache.turbine.modules.LayoutLoader; 31 import org.apache.turbine.modules.Page; 32 import org.apache.turbine.modules.Screen; 33 import org.apache.turbine.modules.ScreenLoader; 34 import org.apache.turbine.util.RunData; 35 import org.apache.turbine.util.TurbineException; 36 37 90 public class DefaultPage 91 extends Page 92 { 93 94 protected Log log = LogFactory.getLog(this.getClass()); 95 96 102 public void doBuild(RunData data) 103 throws Exception  104 { 105 doBuildBeforeAction(data); 108 109 if (data.hasAction()) 112 { 113 ActionLoader.getInstance().exec(data, data.getAction()); 114 } 115 116 if (StringUtils.isNotEmpty(data.getRedirectURI())) 118 { 119 return; 120 } 121 122 setDefaultDoctype(data); 125 126 doBuildAfterAction(data); 129 130 String screenName = data.getScreen(); 131 132 log.debug("Building " + screenName); 133 134 ScreenLoader sl = ScreenLoader.getInstance(); 139 Screen aScreen = sl.getInstance(screenName); 140 String layout = aScreen.getLayout(data); 141 142 if (layout != null) 145 { 146 LayoutLoader.getInstance().exec(data, layout); 147 } 148 else 149 { 150 ScreenLoader.getInstance().exec(data, screenName); 151 } 152 153 doPostBuild(data); 156 } 157 158 166 protected void doBuildBeforeAction(RunData data) 167 throws Exception  168 { 169 } 170 171 178 protected void doBuildAfterAction(RunData data) 179 throws Exception  180 { 181 } 182 183 190 protected void doPostBuild(RunData data) 191 throws Exception  192 { 193 } 194 195 205 private void setDefaultDoctype(RunData data) 206 throws Exception  207 { 208 String errMsg = 209 "default.doctype property not set properly in TurbineResources.properties!"; 210 List doctypeProperty = 211 Turbine.getConfiguration().getList(TurbineConstants.DEFAULT_DOCUMENT_TYPE_KEY); 212 213 if (doctypeProperty != null) 214 { 215 switch(doctypeProperty.size()) 216 { 217 case 0: 218 { 219 break; 221 } 222 case 1: 223 { 224 String doc = (String ) doctypeProperty.get(0); 225 if (doc.equalsIgnoreCase(TurbineConstants.DOCUMENT_TYPE_HTML40TRANSITIONAL)) 226 { 227 data.getPage().setDoctype(new Doctype.Html40Transitional()); 228 } 229 else if (doc.equalsIgnoreCase(TurbineConstants.DOCUMENT_TYPE_HTML40STRICT)) 230 { 231 data.getPage().setDoctype(new Doctype.Html40Strict()); 232 } 233 else if (doc.equalsIgnoreCase(TurbineConstants.DOCUMENT_TYPE_HTML40FRAMESET)) 234 { 235 data.getPage().setDoctype(new Doctype.Html40Frameset()); 236 } 237 else 238 { 239 throw new TurbineException(errMsg); 240 } 241 break; 242 } 243 case 2: 244 { 245 data.getPage() 246 .setDoctype(new Doctype() 247 .setIdentifier((String ) doctypeProperty.get(0)) 248 .setUri((String ) doctypeProperty.get(1))); 249 break; 250 } 251 default: 252 { 253 throw new TurbineException(errMsg); 254 } 255 } 256 } 257 } 258 } 259 | Popular Tags |