KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > matching > ParameterMatcher


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.matching;
17
18 import org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * This class allows for matching based on a parameter provided from the sitemap.
26  * If the specified sitemap parameter exists, its value is retrieved for later
27  * sitemap substitution.
28  *
29  * <p><b>Example:</b></p>
30  * <pre>
31  * &lt;map:match type="parameter" pattern="dest"&gt;
32  * &lt;map:redirect-to uri="{1}"/&gt;
33  * &lt;/map:match&gt;
34  * </pre>
35  *
36  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
37  * @version CVS $Id: ParameterMatcher.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public class ParameterMatcher implements Matcher, ThreadSafe
40 {
41     /**
42      * Match method to see if the sitemap parameter exists. If it does
43      * have a value the parameter added to the array list for later
44      * sitemap substitution.
45      *
46      * @param pattern name of sitemap parameter to find
47      * @param objectModel environment passed through via cocoon
48      * @return null or map containing value of sitemap parameter 'pattern'
49      */

50     public Map JavaDoc match(String JavaDoc pattern, Map JavaDoc objectModel, Parameters parameters) {
51
52         String JavaDoc parameter = parameters.getParameter(pattern, null);
53         if (parameter == null) {
54             return null; // no parameter defined
55
} else {
56             Map JavaDoc map = new HashMap JavaDoc();
57             map.put("1", parameter);
58             return map; // parameter defined, return map
59
}
60     }
61 }
62
Popular Tags