View Javadoc

1   /*
2    * $Id: StrutsSpringObjectFactory.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.tiles;
19  
20  import org.apache.tiles.listener.TilesListener;
21  import org.apache.tiles.TilesUtilImpl;
22  import org.apache.tiles.TilesUtil;
23  
24  import javax.servlet.ServletContextEvent;
25  import javax.servlet.ServletContext;
26  
27  /***
28   * Custom TilesListener which can be used to allow freemarker
29   * invocation from tiles components.
30   *
31   * @version $Rev: 397992 $ $Date$
32   */
33  public class StrutsTilesListener extends TilesListener {
34  
35      /***
36       * The key used to identify the freemarker mask.
37       */
38      public static final String MASK_INIT_PARAM = "freemarker-mask";
39  
40      /***
41       * Configured mask;
42       */
43      private String mask;
44  
45      /***
46       * Initialize the tiles system, overriding the TilesUtilImpl
47       * @param servletContextEvent
48       */
49      public void contextInitialized(ServletContextEvent servletContextEvent) {
50          ServletContext context = servletContextEvent.getServletContext();
51          mask = context.getInitParameter(MASK_INIT_PARAM);
52  
53          if(mask == null) {
54              mask = ".ftl";
55          }
56  
57          TilesUtilImpl tilesUtil = new StrutsTilesUtilImpl();
58          TilesUtil.setTilesUtil(tilesUtil);
59          super.contextInitialized(servletContextEvent);
60      }
61  }