KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

51     public Map JavaDoc match(String JavaDoc pattern, Map JavaDoc objectModel, Parameters parameters) {
52
53         Object JavaDoc attribute = ObjectModelHelper.getRequest(objectModel).getAttribute(pattern);
54
55         if (attribute == null) {
56             return null;
57         } else {
58             Map JavaDoc map = new HashMap JavaDoc();
59             map.put("1", attribute.toString());
60             return map;
61         }
62     }
63 }
64
Popular Tags