01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.selection;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22:
23: /**
24: * A very simple selector that operates on string literals, useful especially
25: * in conjunction with input modules. Usage example:
26: * <pre>
27: * <map:selector name="simple" src="org.apache.cocoon.selection.SimpleSelector"/>
28: *
29: * <map:select type="simple">
30: * <map:parameter name="value" value="{request:method}"/>
31: * <map:when test="GET">
32: * ...
33: * </map:when>
34: * <map:when test="POST">
35: * ...
36: * </map:when>
37: * <map:when test="PUT">
38: * ...
39: * </map:when>
40: * <map:otherwise>
41: * ...
42: * </map:otherwise>
43: * </map:select>
44: * </pre>
45: *
46: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
47: * @version CVS $Id: SimpleSelector.java 433543 2006-08-22 06:22:54Z crossley $
48: * @since 2.1
49: */
50: public class SimpleSelector extends AbstractSwitchSelector {
51:
52: public Object getSelectorContext(Map objectModel,
53: Parameters parameters) {
54: return parameters.getParameter("value", "");
55: }
56:
57: public boolean select(String expression, Object selectorContext) {
58: if (selectorContext == null) {
59: if (getLogger().isWarnEnabled())
60: getLogger().warn("Value not set -- failing.");
61: return false;
62: }
63:
64: return selectorContext.equals(expression);
65: }
66:
67: }
|