KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > markup > xsp > XSPSessionHelper


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.components.language.markup.xsp;
17
18 import org.apache.cocoon.environment.Session;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.List JavaDoc;
23
24 /**
25  * The <code>Session</code> object helper
26  *
27  * @author <a HREF="mailto:ricardo@apache.org">Ricardo Rocha</a>
28  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
29  * @version CVS $Id: XSPSessionHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class XSPSessionHelper {
32
33     /**
34      * Return the given session attribute value or a user-provided default if
35      * none was specified.
36      *
37      * @param session The Session object
38      * @param name The parameter name
39      * @param defaultValue Value to substitute in absence of a parameter value
40      */

41     public static Object JavaDoc getSessionAttribute(Session session, String JavaDoc name,
42                                              Object JavaDoc defaultValue) {
43         Object JavaDoc value = null;
44         if (session != null) {
45             value = session.getAttribute(name);
46         }
47
48         if (value == null) {
49             value = defaultValue;
50         }
51
52         return value;
53     }
54
55     /**
56      * Get the session attribute names.
57      *
58      * @param session The Session object
59      */

60     public static List JavaDoc getSessionAttributeNames(Session session) {
61         ArrayList JavaDoc v = new ArrayList JavaDoc();
62         if (session == null) {
63             return v;
64         }
65         Enumeration JavaDoc e = session.getAttributeNames();
66         while (e.hasMoreElements()) {
67             v.add(e.nextElement());
68         }
69         return v;
70     }
71 }
72
Popular Tags