01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.language.markup.xsp;
18:
19: import org.apache.cocoon.environment.Session;
20:
21: import java.util.ArrayList;
22: import java.util.Enumeration;
23: import java.util.List;
24:
25: /**
26: * The <code>Session</code> object helper
27: *
28: * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
29: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
30: * @version CVS $Id: XSPSessionHelper.java 433543 2006-08-22 06:22:54Z crossley $
31: */
32: public class XSPSessionHelper {
33:
34: /**
35: * Return the given session attribute value or a user-provided default if
36: * none was specified.
37: *
38: * @param session The Session object
39: * @param name The parameter name
40: * @param defaultValue Value to substitute in absence of a parameter value
41: */
42: public static Object getSessionAttribute(Session session,
43: String name, Object defaultValue) {
44: Object value = null;
45: if (session != null) {
46: value = session.getAttribute(name);
47: }
48:
49: if (value == null) {
50: value = defaultValue;
51: }
52:
53: return value;
54: }
55:
56: /**
57: * Get the session attribute names.
58: *
59: * @param session The Session object
60: */
61: public static List getSessionAttributeNames(Session session) {
62: ArrayList v = new ArrayList();
63: if (session == null) {
64: return v;
65: }
66: Enumeration e = session.getAttributeNames();
67: while (e.hasMoreElements()) {
68: v.add(e.nextElement());
69: }
70: return v;
71: }
72: }
|