KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > micronova > util > PageContextMap


1 /*
2
3 Copyright 2003-2007 MicroNova (R)
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or
7 without modification, are permitted provided that the following
8 conditions are met:
9
10     * Redistributions of source code must retain the above copyright
11     notice, this list of conditions and the following disclaimer.
12
13     * Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17     * Neither the name of MicroNova nor the names of its contributors
18     may be used to endorse or promote products derived from this
19     software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32
33 */

34
35 package com.micronova.util;
36
37 import javax.servlet.http.*;
38 import javax.servlet.jsp.*;
39 import java.util.*;
40 import com.micronova.jsp.tag.*;
41
42 /** A Map to access scoped PageContext attributes (backed by PageContext) */
43
44 public class PageContextMap extends NestedMap
45 {
46     protected PageContext _pageContext;
47     protected int _scope;
48
49     public PageContextMap(PageContext pageContext, int scope, List list)
50     {
51         super();
52
53         _pageContext = pageContext;
54         _scope = scope;
55
56         Enumeration enumeration = null;
57
58         if ((list != null) && (!list.isEmpty()))
59         {
60             enumeration = Collections.enumeration(list);
61         }
62
63         if (enumeration == null)
64         {
65             // session scope is handled separately
66

67             if (scope == PageContext.SESSION_SCOPE)
68             {
69                 enumeration = ((HttpServletRequest)_pageContext.getRequest()).getSession().getAttributeNames();
70             }
71             else
72             {
73                 enumeration = _pageContext.getAttributeNamesInScope(_scope);
74             }
75         }
76
77         while (enumeration.hasMoreElements())
78         {
79             String JavaDoc name = enumeration.nextElement().toString();
80             this.put(name, pageContext.getAttribute(name, _scope));
81         }
82     }
83
84     public PageContextMap(PageContext pageContext, int scope)
85     {
86         this(pageContext, scope, null);
87     }
88     
89     public PageContext getPageContext()
90     {
91         return _pageContext;
92     }
93
94     public int getScope()
95     {
96         return _scope;
97     }
98
99     public Object JavaDoc putObject(Object JavaDoc objectSource, Object JavaDoc key, Object JavaDoc value)
100     {
101         String JavaDoc keyString = key.toString();
102         PageContext pageContext = _pageContext;
103
104         YuzuTag.setScopedAttribute(pageContext, keyString, value, _scope);
105
106         return super.putObject(objectSource, key, value);
107     }
108 }
109
Popular Tags