KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20
21 import java.util.Map JavaDoc;
22
23 /**
24  * A <code>Selector</code> that matches a string in the parameters object passed to it.
25  *
26  * <pre>
27  * &lt;map:selector name="parameter" factory="org.apache.cocoon.selection.ParameterSelector"/&gt;
28  *
29  * &lt;map:select type="parameter"&gt;
30  * &lt;map:parameter name="parameter-selector-test" value="{mySitemapParameter}"/&gt;
31  *
32  * &lt;map:when test="myParameterValue"&gt;
33  * &lt;!-- executes iff {mySitemapParameter} == "myParameterValue" --&gt;
34  * &lt;map:transform SRC="stylesheets/page/uk.xsl"/&gt;
35  * &lt;/map:when&gt;
36  * &lt;map:otherwise&gt;
37  * &lt;map:transform SRC="stylesheets/page/us.xsl"/&gt;
38  * &lt;/map:otherwise&gt;
39  * &lt;/map:select&gt;
40  * </pre>
41  *
42  * The purpose of this selector is to allow an action to set parameters
43  * and to be able to select between different pipeline configurations
44  * depending on those parameters.
45  *
46  * @author <a HREF="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
47  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
48  * @version CVS $Id: ParameterSelector.java 30932 2004-07-29 17:35:38Z vgritsenko $
49  */

50 public class ParameterSelector implements ThreadSafe, Selector {
51
52     public boolean select(String JavaDoc expression, Map JavaDoc objectModel, Parameters parameters) {
53         String JavaDoc compareToString = parameters.getParameter("parameter-selector-test", null);
54         return compareToString != null && compareToString.equals(expression);
55     }
56 }
57
Popular Tags