KickJava   Java API By Example, From Geeks To Geeks.

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


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 session attribute.
27  * If the specified session 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="session-attribute" pattern="style"&gt;
33  * &lt;map:read 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: SessionAttributeMatcher.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class SessionAttributeMatcher 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 session attribute to find
48      * @param objectModel environment passed through via cocoon
49      * @return null or map containing value of session attribute 'pattern'
50      */

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