KickJava   Java API By Example, From Geeks To Geeks.

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


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 header.
28  * If the specified request header parameter exists, its value is
29  * retrieved for later sitemap substitution.
30  *
31  * <p><b>Example:</b></p>
32  * <pre>
33  * &lt;map:match type="header" pattern="referer"&gt;
34  * &lt;map:redirect-to uri="{1}"/&gt;
35  * &lt;/map:match&gt;
36  * </pre>
37  *
38  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
39  * @version CVS $Id: HeaderMatcher.java 30932 2004-07-29 17:35:38Z vgritsenko $
40  */

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

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