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 import javax.servlet.jsp.PageContext ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 44 public class TilesUtil { 45 46 47 protected static Log log = LogFactory.getLog(TilesUtil.class); 48 49 50 protected static TilesUtilImpl tilesUtilImpl = new TilesUtilImpl(); 51 52 56 static public TilesUtilImpl getTilesUtil() { 57 return tilesUtilImpl; 58 } 59 60 66 static public void setTilesUtil(TilesUtilImpl tilesUtil) { 67 if (implAlreadySet) { 68 return; 69 } 70 tilesUtilImpl = tilesUtil; 71 implAlreadySet = true; 72 } 73 74 79 static boolean isTilesUtilImplSet() { 80 return implAlreadySet; 81 } 82 83 84 private static boolean implAlreadySet = false; 85 86 95 public static void doForward( 96 String uri, 97 HttpServletRequest request, 98 HttpServletResponse response, 99 ServletContext servletContext) 100 throws IOException , ServletException { 101 102 tilesUtilImpl.doForward(uri, request, response, servletContext); 103 } 104 105 115 public static void doInclude( 116 String uri, 117 HttpServletRequest request, 118 HttpServletResponse response, 119 ServletContext servletContext) 120 throws IOException , ServletException { 121 122 tilesUtilImpl.doInclude(uri, request, response, servletContext); 123 } 124 125 133 public static void doInclude(String uri, PageContext pageContext) 134 throws IOException , ServletException { 135 tilesUtilImpl.doInclude(uri, pageContext); 136 } 137 138 142 public static DefinitionsFactory getDefinitionsFactory( 143 ServletRequest request, 144 ServletContext servletContext) { 145 return tilesUtilImpl.getDefinitionsFactory(request, servletContext); 146 } 147 148 161 public static DefinitionsFactory createDefinitionsFactory( 162 ServletContext servletContext, 163 DefinitionsFactoryConfig factoryConfig) 164 throws DefinitionsFactoryException { 165 return tilesUtilImpl.createDefinitionsFactory(servletContext, factoryConfig); 166 } 167 168 179 public static ComponentDefinition getDefinition( 180 String definitionName, 181 ServletRequest request, 182 ServletContext servletContext) 183 throws FactoryNotFoundException, DefinitionsFactoryException { 184 185 try { 186 return getDefinitionsFactory(request, servletContext).getDefinition( 187 definitionName, 188 (HttpServletRequest ) request, 189 servletContext); 190 191 } catch (NullPointerException ex) { throw new FactoryNotFoundException("Can't get definitions factory from context."); 193 } 194 } 195 196 200 protected static void testReset() { 201 implAlreadySet = false; 202 tilesUtilImpl = new TilesUtilImpl(); 203 } 204 205 } | Popular Tags |