1 /*
2 * $Id: InitParamsServletConfig.java 1306435 2012-03-28 15:39:11Z nlebas $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 package org.apache.tiles.request.freemarker.render;
22
23 import java.util.Collections;
24 import java.util.Enumeration;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import javax.servlet.ServletConfig;
29 import javax.servlet.ServletContext;
30
31 import org.apache.tiles.request.ApplicationContext;
32
33 /**
34 * Implements {@link ServletConfig} to initialize the internal servlet using parameters
35 * set through {@link FreemarkerRenderer#setParameter(String, String)}.
36 *
37 * @version $Rev: 1306435 $ $Date: 2012-03-29 02:39:11 +1100 (Thu, 29 Mar 2012) $
38 */
39 public class InitParamsServletConfig implements ServletConfig {
40
41 /**
42 * The initialization parameters.
43 */
44 private Map<String, String> params = new HashMap<String, String>();
45
46 /**
47 * The application context.
48 */
49 private ApplicationContext applicationContext;
50
51 /**
52 * Constructor.
53 *
54 * @param params Configuration parameters.
55 * @param applicationContext The application context.
56 */
57 public InitParamsServletConfig(Map<String, String> params, ApplicationContext applicationContext) {
58 this.params = params;
59 this.applicationContext = applicationContext;
60 }
61
62 /** {@inheritDoc} */
63 public String getInitParameter(String name) {
64 return params.get(name);
65 }
66
67 /** {@inheritDoc} */
68 public Enumeration<String> getInitParameterNames() {
69 return Collections.enumeration(params.keySet());
70 }
71
72 /** {@inheritDoc} */
73 public ServletContext getServletContext() {
74 return org.apache.tiles.request.servlet.ServletUtil.getServletContext(applicationContext);
75 }
76
77 /** {@inheritDoc} */
78 public String getServletName() {
79 return "FreeMarker Attribute Renderer";
80 }
81 }