1/*2 * $Id: ScopePropertyAccessor.java 1049696 2010-12-15 20:30:10Z 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.ognl;
2223import java.util.Map;
2425import ognl.OgnlContext;
26import ognl.PropertyAccessor;
2728import org.apache.tiles.request.Request;
2930/**31 * Accesses a scope.32 *33 * @version $Rev: 1049696 $ $Date: 2010-12-16 07:30:10 +1100 (Thu, 16 Dec 2010) $34 */35publicclassScopePropertyAccessorimplements PropertyAccessor {
3637/**38 * The length of the scope suffix: "Scope".39 */40staticfinalint SCOPE_SUFFIX_LENGTH = 5;
4142 @Override
43public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) {
44 Request request = (Request) target;
45 String scope = (String) name;
46if (scope.endsWith("Scope")) {
47 String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH);
48return request.getContext(scopeName);
49 }
50returnnull;
51 }
5253 @Override
54public String getSourceAccessor(OgnlContext context, Object target,
55 Object index) {
56 String scope = (String) index;
57if (scope.endsWith("Scope")) {
58 String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH);
59return".getContext(\"" + scopeName + "\")";
60 }
61returnnull;
62 }
6364 @Override
65public String getSourceSetter(OgnlContext context, Object target,
66 Object index) {
67returnnull;
68 }
6970 @Override
71publicvoid setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
72 Object value) {
73// Does nothing.74 }
7576 }