01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.panels.misc;
17:
18: import javax.servlet.http.HttpServletRequest;
19:
20: import de.odysseus.calyxo.base.ModuleContext;
21: import de.odysseus.calyxo.base.access.AccessException;
22: import de.odysseus.calyxo.base.access.DynamicMapAccessor;
23: import de.odysseus.calyxo.base.access.AccessorMap;
24: import de.odysseus.calyxo.panels.PanelsContext;
25: import de.odysseus.calyxo.panels.PanelsSupport;
26: import de.odysseus.calyxo.panels.conf.ParamConfig;
27:
28: /**
29: * This accessor contains a <code>param</code> child to access
30: * panel parameters.
31: *
32: * @author Christoph Beck
33: */
34: public class PanelsAccessor extends AccessorMap {
35: /**
36: * Lookup parameter within current panels context stack.
37: *
38: * @author Christoph Beck
39: */
40: public class ParamAccessor extends DynamicMapAccessor {
41: /**
42: * Lookup parameter.
43: */
44: protected Object get(HttpServletRequest request, Object key) {
45: PanelsContext context = support.getContext(request);
46: ParamConfig param = context.lookupParamConfig(key
47: .toString());
48: if (param == null) {
49: throw new AccessException("Unknown panel parameter '"
50: + key + "'");
51: }
52: if (!param.isDefined()) {
53: throw new AccessException(
54: "Undefined value for panel parameter '" + key
55: + "'");
56: }
57: return param.getValue();
58: }
59: }
60:
61: final PanelsSupport support;
62:
63: public PanelsAccessor(ModuleContext context) {
64: super ();
65:
66: support = PanelsSupport.getInstance(context);
67:
68: put("param", new ParamAccessor());
69: }
70: }
|