1 16 17 package org.apache.jetspeed.modules.pages; 18 19 import org.apache.turbine.modules.pages.DefaultPage; 21 22 import org.apache.turbine.util.RunData; 24 import org.apache.turbine.services.template.TurbineTemplate; 25 26 import org.apache.jetspeed.util.MimeType; 28 import org.apache.jetspeed.om.registry.MediaTypeEntry; 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 30 import org.apache.jetspeed.services.logging.JetspeedLogger; 31 import org.apache.jetspeed.services.Registry; 32 import org.apache.jetspeed.capability.CapabilityMap; 33 import org.apache.jetspeed.services.TemplateLocator; 34 import org.apache.jetspeed.services.rundata.JetspeedRunData; 35 import org.apache.jetspeed.services.resources.JetspeedResources; 36 37 88 public class JetspeedTemplatePage extends DefaultPage 89 { 90 private static int httpLifetime = JetspeedResources.getInt("http.lifetime", -1); 91 92 95 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedTemplatePage.class.getName()); 96 97 104 protected void doBuildBeforeAction(RunData data) throws Exception 105 { 106 switch (httpLifetime) 107 { 108 case -1: 109 break; 110 case 0: 111 data.getResponse().setHeader("Cache-Control", "no-cache"); 112 data.getResponse().setHeader("Pragma", "no-cache"); 113 data.getResponse().setDateHeader("Expires", 0); 114 data.getResponse().setDateHeader("Last-Modified", System.currentTimeMillis()); 115 break; 116 default: 117 data.getResponse().setHeader("Cache-Control", "max-age=" + httpLifetime); 118 data.getResponse().setDateHeader("Expires", System.currentTimeMillis() + (httpLifetime * 1000)); 119 data.getResponse().setDateHeader("Last-Modified", System.currentTimeMillis()); 120 break; 121 } 122 123 CapabilityMap cm = ((JetspeedRunData)data).getCapability(); 125 MimeType mime = cm.getPreferredType(); 126 String characterSet = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,"utf-8"); 127 data.setContentType( mime.getContentType()); 128 if ( mime != null ) 129 { 130 MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, mime.getCode()); 131 if ( media != null && media.getCharacterSet() != null) 132 { 133 characterSet = media.getCharacterSet(); 134 } 135 } 136 data.setCharSet( characterSet ); 137 138 if (logger.isDebugEnabled()) 139 { 140 logger.debug( "JetspeedTemplatePage: Setting type to: " + cm.getPreferredType().getContentType() 141 + "; charset=" + JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,"utf-8") 142 ); 143 } 144 145 } 146 147 154 protected void doBuildAfterAction(RunData data) throws Exception 155 { 156 162 if (!data.hasScreen()) 163 { 164 165 if ( data.getTemplateInfo().getScreenTemplate() == null ) 168 { 169 String screen = TurbineTemplate.getDefaultScreen(); 170 data.setScreenTemplate(screen); 171 } 172 173 String ext = TurbineTemplate.getDefaultExtension(); 174 175 String template = data.getTemplateInfo().getScreenTemplate(); 176 177 ((JetspeedRunData)data).setRequestedTemplate(template); 179 180 if (template.lastIndexOf('.')<0) 181 { 182 template=template+"."+ext; 183 } 184 if ( logger.isDebugEnabled() ) 185 { 186 logger.debug("JetspeedTemplatePage: requested template = " + template); 187 } 188 189 193 String locatedScreen = TemplateLocator.locateScreenTemplate(data, template); 194 data.setScreenTemplate( locatedScreen ); 195 if ( logger.isDebugEnabled() ) 196 { 197 logger.debug("JetspeedTemplatePage: calculated template = " + locatedScreen); 198 } 199 200 String layout = TemplateLocator.locateLayoutTemplate(data, template); 201 data.setLayoutTemplate(layout); 202 if ( logger.isDebugEnabled() ) 203 { 204 logger.debug("JetspeedTemplatePage: layoutTemplate is finally " + layout); 205 } 206 207 String screen = TurbineTemplate.getScreenName(template); 208 if (screen == null) 209 { 210 throw new Exception ("Screen could not be determined. \n" + 211 "No matches were found by TemplateService and the \n" + 212 "services.TurbineTemplateService.default.screen \n" + 213 "property was not set."); 214 } 215 data.setScreen(screen); 216 } 217 } 218 219 } 220 | Popular Tags |