KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.cocoon.environment.ObjectModelHelper;
21 import org.apache.cocoon.environment.Request;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * This class allows for matching based on a request parameter.
28  * If the specified request parameter exists, its value is retrieved for later
29  * sitemap substitution.
30  *
31  * <p><b>Example:</b></p>
32  * <pre>
33  * &lt;map:match type="request" pattern="dest"&gt;
34  * &lt;map:redirect-to uri="{1}"/&gt;
35  * &lt;/map:match&gt;
36  * </pre>
37  *
38  * @author <a HREF="mailto:Marcus.Crafter@osa.de">Marcus Crafter</a>
39  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
40  * @version CVS $Id: RequestParameterMatcher.java 30932 2004-07-29 17:35:38Z vgritsenko $
41  */

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

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