1 /*
2 * $Id: EnvironmentScopeMap.java 942404 2010-05-08 15:36:51Z apetrelli $
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;
22
23 import java.util.Set;
24
25 import org.apache.tiles.request.collection.ScopeMap;
26 import org.apache.tiles.request.freemarker.extractor.EnvironmentScopeExtractor;
27
28 import freemarker.core.Environment;
29 import freemarker.template.TemplateModelException;
30
31 /**
32 * <p>
33 * Private implementation of <code>Map</code> for servlet request attributes.
34 * </p>
35 *
36 * @version $Rev: 942404 $ $Date: 2010-05-09 01:36:51 +1000 (Sun, 09 May 2010) $
37 */
38
39 final class EnvironmentScopeMap extends ScopeMap {
40
41 /**
42 * The request object to use.
43 */
44 private Environment request = null;
45
46 /**
47 * Constructor.
48 *
49 * @param request The request object to use.
50 */
51 public EnvironmentScopeMap(Environment request) {
52 super(new EnvironmentScopeExtractor(request));
53 this.request = request;
54 }
55
56 @SuppressWarnings("unchecked")
57 @Override
58 public Set<String> keySet() {
59 try {
60 return request.getKnownVariableNames();
61 } catch (TemplateModelException e) {
62 throw new FreemarkerRequestException(
63 "Cannot get known variable names", e);
64 }
65 }
66 }