1/*2 * $Id: TilesServlet.java 734996 2009-01-16 13:27:28Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.web.startup;
2223import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.apache.tiles.TilesException;
26import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
27import org.apache.tiles.servlet.context.ServletUtil;
28import org.apache.tiles.startup.BasicTilesInitializer;
29import org.apache.tiles.startup.TilesInitializer;
30import org.apache.tiles.web.util.ServletContextAdapter;
3132import javax.servlet.http.HttpServlet;
33import javax.servlet.ServletContext;
34import javax.servlet.ServletException;
3536/***37 * Initialization Servlet.38 *39 * @see org.apache.tiles.web.startup.TilesListener40 * @version $Rev: 734996 $ $Date: 2009-01-16 14:27:28 +0100 (ven, 16 gen 2009) $41 */42publicclassTilesServletextends HttpServlet {
4344/***45 * Log instance.46 */47protectedfinal Log log =
48 LogFactory.getLog(TilesServlet.class);
4950/***51 * The private listener instance, that is used to initialize Tiles52 * container.53 */54private TilesInitializer initializer;
5556/***57 * Constructor.58 *59 * @since 2.1.260 */61publicTilesServlet() {
62 initializer = createTilesInitializer();
63 }
6465/*** {@inheritDoc} */66 @Override
67publicvoid destroy() {
68try {
69 ServletUtil.setContainer(getServletContext(), null);
70 } catch (TilesException e) {
71 log.warn("Unable to remove tiles container from service.", e);
72 }
73 }
7475/*** {@inheritDoc} */76 @Override
77publicvoid init() throws ServletException {
78 ServletContext adaptedContext = newServletContextAdapter(
79 getServletConfig());
80ServletTilesApplicationContext preliminaryContext = newServletTilesApplicationContext(
81 adaptedContext);
82 initializer.initialize(preliminaryContext);
83 }
8485/***86 * Creates a new instance of {@link BasicTilesInitializer}. Override it to use a different initializer.87 *88 * @return The Tiles servlet-based initializer.89 * @since 2.1.290 */91protected TilesInitializer createTilesInitializer() {
92returnnew BasicTilesInitializer();
93 }
94 }