1 18 19 package org.apache.struts.tiles; 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletContext ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.struts.Globals; 30 import org.apache.struts.config.ModuleConfig; 31 import org.apache.struts.util.ModuleUtils; 32 33 46 public class TilesUtilStrutsModulesImpl extends TilesUtilStrutsImpl { 47 48 57 public void doForward( 58 String uri, 59 HttpServletRequest request, 60 HttpServletResponse response, 61 ServletContext servletContext) 62 throws IOException , ServletException { 63 64 request.getRequestDispatcher(uri).forward(request, response); 65 } 66 67 76 public void doInclude( 77 String uri, 78 HttpServletRequest request, 79 HttpServletResponse response, 80 ServletContext servletContext) 81 throws IOException , ServletException { 82 83 request.getRequestDispatcher(uri).include(request, response); 84 } 85 86 92 public DefinitionsFactory getDefinitionsFactory( 93 ServletRequest request, 94 ServletContext servletContext) { 95 96 return getDefinitionsFactory( 97 servletContext, 98 getModuleConfig((HttpServletRequest ) request, servletContext)); 99 } 100 101 107 public DefinitionsFactory getDefinitionsFactory( 108 ServletContext servletContext, 109 ModuleConfig moduleConfig) { 110 111 return (DefinitionsFactory) servletContext.getAttribute( 112 DEFINITIONS_FACTORY + moduleConfig.getPrefix()); 113 } 114 115 121 protected void makeDefinitionsFactoryAccessible( 122 DefinitionsFactory factory, 123 ServletContext servletContext) { 124 125 String prefix = factory.getConfig().getFactoryName(); 126 servletContext.setAttribute(DEFINITIONS_FACTORY + prefix, factory); 127 } 128 129 135 protected TilesRequestProcessor getRequestProcessor( 136 HttpServletRequest request, 137 ServletContext servletContext) { 138 139 ModuleConfig moduleConfig = getModuleConfig(request, servletContext); 140 141 return (TilesRequestProcessor) servletContext.getAttribute( 142 Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix()); 143 } 144 145 154 protected ModuleConfig getModuleConfig( 155 HttpServletRequest request, 156 ServletContext servletContext) { 157 158 ModuleConfig moduleConfig = 159 ModuleUtils.getInstance().getModuleConfig(request); 160 161 if (moduleConfig == null) { 162 ModuleUtils.getInstance().selectModule(request, servletContext); 164 moduleConfig = ModuleUtils.getInstance().getModuleConfig(request); 165 } 166 167 return moduleConfig; 168 } 169 170 } | Popular Tags |