KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > selection > SimpleSelector


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 org.apache.cocoon.selection;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.avalon.framework.thread.ThreadSafe;
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  * &lt;map:selector name="simple" SRC="org.apache.cocoon.selection.SimpleSelector"/&gt;
28  *
29  * &lt;map:select type="simple"&gt;
30  * &lt;map:parameter name="value" value="{request:method}"/&gt;
31  * &lt;map:when test="GET"&gt;
32  * ...
33  * &lt;/map:when&gt;
34  * &lt;map:when test="POST"&gt;
35  * ...
36  * &lt;/map:when&gt;
37  * &lt;map:when test="PUT"&gt;
38  * ...
39  * &lt;/map:when&gt;
40  * &lt;map:otherwise&gt;
41  * ...
42  * &lt;/map:otherwise&gt;
43  * &lt;/map:select&gt;
44  * </pre>
45  *
46  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
47  * @version CVS $Id: SimpleSelector.java 30932 2004-07-29 17:35:38Z vgritsenko $
48  * @since 2.1
49  */

50 public class SimpleSelector extends AbstractSwitchSelector implements ThreadSafe {
51
52     public Object JavaDoc getSelectorContext(Map JavaDoc objectModel, Parameters parameters) {
53         return parameters.getParameter("value", "");
54     }
55
56     public boolean select(String JavaDoc expression, Object JavaDoc selectorContext) {
57         if (selectorContext == null) {
58             if (getLogger().isWarnEnabled())
59                 getLogger().warn("Value not set -- failing.");
60             return false;
61         }
62
63         return selectorContext.equals(expression);
64     }
65
66 }
67
Popular Tags