Source Code Cross Referenced for ExternalContextImpl.java in  » Portal » Open-Portal » com » sun » faces » portlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.faces.portlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Id: ExternalContextImpl.java,v 1.6 2005/12/15 06:57:56 dg154973 Exp $
0003:         */
0004:
0005:        /*
0006:         * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
0007:         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
0008:         */
0009:
0010:        package com.sun.faces.portlet;
0011:
0012:        import java.io.IOException;
0013:        import java.io.InputStream;
0014:        import java.net.MalformedURLException;
0015:        import java.net.URL;
0016:        import java.security.Principal;
0017:        import java.util.ArrayList;
0018:        import java.util.Collection;
0019:        import java.util.Collections;
0020:        import java.util.Enumeration;
0021:        import java.util.HashSet;
0022:        import java.util.Iterator;
0023:        import java.util.List;
0024:        import java.util.Locale;
0025:        import java.util.Map;
0026:        import java.util.Set;
0027:        import java.util.AbstractMap;
0028:
0029:        import javax.faces.FacesException;
0030:        import javax.faces.context.ExternalContext;
0031:
0032:        import javax.portlet.ActionRequest;
0033:        import javax.portlet.ActionResponse;
0034:        import javax.portlet.PortletContext;
0035:        import javax.portlet.PortletException;
0036:        import javax.portlet.PortletRequest;
0037:        import javax.portlet.PortletRequestDispatcher;
0038:        import javax.portlet.PortletResponse;
0039:        import javax.portlet.PortletSession;
0040:        import javax.portlet.RenderRequest;
0041:        import javax.portlet.RenderResponse;
0042:
0043:        import org.apache.commons.logging.Log;
0044:        import org.apache.commons.logging.LogFactory;
0045:
0046:        /**
0047:         * <p>Concrete implementation of <code>ExternalContext</code> for use in
0048:         * a portlet environment.</p>
0049:         */
0050:
0051:        public class ExternalContextImpl extends ExternalContext {
0052:
0053:            // ------------------------------------------------------------ Constructors
0054:
0055:            /**
0056:             * <p>Create a new instance wrapping the specified Portlet API objects.</p>
0057:             *
0058:             * @param context The <code>PortletContext</code> for this application
0059:             * @param request The <code>PortletRequest</code> for this request
0060:             * @param response The <code>PortletResponse</code> for this response
0061:             */
0062:            public ExternalContextImpl(PortletContext context,
0063:                    PortletRequest request, PortletResponse response) {
0064:                this .context = context;
0065:                this .request = request;
0066:                this .response = response;
0067:                if (log.isTraceEnabled()) {
0068:                    log.trace("Created ExternalContext " + this );
0069:                }
0070:            }
0071:
0072:            // ------------------------------------------------------ Instance Variables
0073:
0074:            // The Log instance for this class
0075:            private static final Log log = LogFactory
0076:                    .getLog(ExternalContextImpl.class);
0077:
0078:            // The Portlet API objects we are wrapping
0079:            private PortletContext context;
0080:            private PortletRequest request;
0081:            private PortletResponse response;
0082:
0083:            // Our private map implementations (lazily instantiated)
0084:            private PortletApplicationMap applicationMap = null;
0085:            private PortletInitParameterMap initParameterMap = null;
0086:            private PortletRequestHeaderMap requestHeaderMap = null;
0087:            private PortletRequestHeaderValuesMap requestHeaderValuesMap = null;
0088:            private PortletRequestMap requestMap = null;
0089:            private PortletRequestParameterMap requestParameterMap = null;
0090:            private PortletRequestParameterValuesMap requestParameterValuesMap = null;
0091:            private PortletSessionMap sessionMap = null;
0092:
0093:            // ---------------------------------------------------------- Public Methods
0094:
0095:            public void dispatch(String path) throws IOException {
0096:                if (log.isTraceEnabled()) {
0097:                    log.trace("dispatchMessage(" + path + ")");
0098:                }
0099:                if (path == null) {
0100:                    throw new NullPointerException();
0101:                }
0102:                if (!(request instanceof  RenderRequest)
0103:                        || !(response instanceof  RenderResponse)) {
0104:                    throw new IllegalStateException(path);
0105:                }
0106:                if (log.isDebugEnabled()) {
0107:                    log.debug("response content type "
0108:                            + ((RenderResponse) response).getContentType());
0109:                }
0110:                PortletRequestDispatcher prd = context
0111:                        .getRequestDispatcher(path);
0112:                if (prd == null) {
0113:                    throw new IllegalArgumentException(path);
0114:                }
0115:                try {
0116:                    prd.include((RenderRequest) request,
0117:                            (RenderResponse) response);
0118:                } catch (PortletException e) {
0119:                    throw new FacesException(e);
0120:                }
0121:            }
0122:
0123:            public String encodeActionURL(String url) {
0124:                if (url == null) {
0125:                    throw new NullPointerException();
0126:                }
0127:                // fix for bug 6243708
0128:                // wrong usage of  PortletResponse.encodeURL
0129:                // method. This method is to be only used to
0130:                // "encode" resource URLs (i.e. servlets, JSPs,
0131:                // static files such as images, etc) and not portlet
0132:                // action or render URLs.
0133:                // return (response.encodeURL(url));
0134:                return url;
0135:            }
0136:
0137:            public String encodeNamespace(String name) {
0138:                if (!(response instanceof  RenderResponse)) {
0139:                    throw new IllegalStateException();
0140:                }
0141:                return (((RenderResponse) response).getNamespace() + name);
0142:            }
0143:
0144:            // PENDING(craigmcc) - Currently identical to encodeActionURL()
0145:            public String encodeResourceURL(String url) {
0146:                if (url == null) {
0147:                    throw new NullPointerException();
0148:                }
0149:                return (response.encodeURL(url));
0150:            }
0151:
0152:            public Map getApplicationMap() {
0153:                if (applicationMap == null) {
0154:                    applicationMap = new PortletApplicationMap(context);
0155:                }
0156:                return (applicationMap);
0157:            }
0158:
0159:            public String getAuthType() {
0160:                return (request.getAuthType());
0161:            }
0162:
0163:            public Object getContext() {
0164:                return (context);
0165:            }
0166:
0167:            public String getInitParameter(String name) {
0168:                if (name == null) {
0169:                    throw new NullPointerException();
0170:                }
0171:                return (context.getInitParameter(name));
0172:            }
0173:
0174:            public Map getInitParameterMap() {
0175:                if (initParameterMap == null) {
0176:                    initParameterMap = new PortletInitParameterMap(context);
0177:                }
0178:                return (initParameterMap);
0179:            }
0180:
0181:            public String getRemoteUser() {
0182:                return (request.getRemoteUser());
0183:            }
0184:
0185:            public Object getRequest() {
0186:                return (request);
0187:            }
0188:
0189:            public String getRequestContextPath() {
0190:                return (request.getContextPath());
0191:            }
0192:
0193:            // PENDING(craigmcc) - Do we want to try to parse "Cookie" properties?
0194:            public Map getRequestCookieMap() {
0195:                return (Collections.unmodifiableMap(Collections.EMPTY_MAP));
0196:            }
0197:
0198:            public Map getRequestHeaderMap() {
0199:                if (requestHeaderMap == null) {
0200:                    requestHeaderMap = new PortletRequestHeaderMap(request);
0201:                }
0202:                return (requestHeaderMap);
0203:            }
0204:
0205:            public Map getRequestHeaderValuesMap() {
0206:                if (requestHeaderValuesMap == null) {
0207:                    requestHeaderValuesMap = new PortletRequestHeaderValuesMap(
0208:                            request);
0209:                }
0210:                return (requestHeaderValuesMap);
0211:            }
0212:
0213:            public Locale getRequestLocale() {
0214:                return (request.getLocale());
0215:            }
0216:
0217:            public Iterator getRequestLocales() {
0218:                return (new LocalesIterator(request.getLocales()));
0219:            }
0220:
0221:            public Map getRequestMap() {
0222:                if (requestMap == null) {
0223:                    requestMap = new PortletRequestMap(request);
0224:                }
0225:                return (requestMap);
0226:            }
0227:
0228:            public Map getRequestParameterMap() {
0229:                if (requestParameterMap == null) {
0230:                    requestParameterMap = new PortletRequestParameterMap(
0231:                            request);
0232:                }
0233:                return (requestParameterMap);
0234:            }
0235:
0236:            public Iterator getRequestParameterNames() {
0237:                return (request.getParameterMap().keySet().iterator());
0238:            }
0239:
0240:            public Map getRequestParameterValuesMap() {
0241:                if (requestParameterValuesMap == null) {
0242:                    requestParameterValuesMap = new PortletRequestParameterValuesMap(
0243:                            request);
0244:                }
0245:                return (requestParameterValuesMap);
0246:            }
0247:
0248:            // PENDING(craigmcc) - Alternate interpretation in portlet environment?
0249:            public String getRequestPathInfo() {
0250:                return (null);
0251:            }
0252:
0253:            // PENDING(craigmcc) - Alternate interpretation in portlet environment?
0254:            public String getRequestServletPath() {
0255:                return (null);
0256:            }
0257:
0258:            public URL getResource(String path) throws MalformedURLException {
0259:                if (path == null) {
0260:                    throw new NullPointerException();
0261:                }
0262:                return (context.getResource(path));
0263:            }
0264:
0265:            public InputStream getResourceAsStream(String path) {
0266:                if (path == null) {
0267:                    throw new NullPointerException();
0268:                }
0269:                return (context.getResourceAsStream(path));
0270:            }
0271:
0272:            public Set getResourcePaths(String path) {
0273:                if (path == null) {
0274:                    throw new NullPointerException();
0275:                }
0276:                return (context.getResourcePaths(path));
0277:            }
0278:
0279:            public Object getResponse() {
0280:                return (response);
0281:            }
0282:
0283:            public Object getSession(boolean create) {
0284:                return (new PortletSessionWrapper(request
0285:                        .getPortletSession(create), response,
0286:                        getRequestParameterMap()));
0287:            }
0288:
0289:            public Map getSessionMap() {
0290:                if (sessionMap == null) {
0291:                    sessionMap = new PortletSessionMap(request, response,
0292:                            getRequestParameterMap());
0293:                }
0294:                return (sessionMap);
0295:            }
0296:
0297:            public Principal getUserPrincipal() {
0298:                return (request.getUserPrincipal());
0299:            }
0300:
0301:            public boolean isUserInRole(String role) {
0302:                if (role == null) {
0303:                    throw new NullPointerException();
0304:                }
0305:                return (request.isUserInRole(role));
0306:            }
0307:
0308:            public void log(String message) {
0309:                if (message == null) {
0310:                    throw new NullPointerException();
0311:                }
0312:                context.log(message);
0313:            }
0314:
0315:            public void log(String message, Throwable exception) {
0316:                if ((message == null) || (exception == null)) {
0317:                    throw new NullPointerException();
0318:                }
0319:                context.log(message, exception);
0320:            }
0321:
0322:            public void redirect(String path) throws IOException {
0323:                if (log.isTraceEnabled()) {
0324:                    log.trace("redirectMessage(" + path + ")");
0325:                }
0326:                if (path == null) {
0327:                    throw new NullPointerException();
0328:                }
0329:                if (!(request instanceof  ActionRequest)
0330:                        || !(response instanceof  ActionResponse)) {
0331:                    throw new IllegalStateException(path);
0332:                }
0333:                try {
0334:                    ((ActionResponse) response).sendRedirect(path);
0335:                } catch (Exception e) {
0336:                    throw new FacesException(e);
0337:                }
0338:            }
0339:
0340:        }
0341:
0342:        // ------------------------------------------------------------- Private Classes
0343:
0344:        class LocalesIterator implements  Iterator {
0345:
0346:            public LocalesIterator(Enumeration locales) {
0347:                this .locales = locales;
0348:            }
0349:
0350:            private Enumeration locales;
0351:
0352:            public boolean hasNext() {
0353:                return locales.hasMoreElements();
0354:            }
0355:
0356:            public Object next() {
0357:                return locales.nextElement();
0358:            }
0359:
0360:            public void remove() {
0361:                throw new UnsupportedOperationException();
0362:            }
0363:
0364:        }
0365:
0366:        abstract class BaseContextMap extends AbstractMap {
0367:
0368:            // Unsupported by all Maps.
0369:            public void clear() {
0370:                throw new UnsupportedOperationException();
0371:            }
0372:
0373:            // Unsupported by all Maps.
0374:            public void putAll(Map t) {
0375:                throw new UnsupportedOperationException();
0376:            }
0377:
0378:            // Supported by maps if overridden
0379:            public Object remove(Object key) {
0380:                throw new UnsupportedOperationException();
0381:            }
0382:
0383:            static class Entry implements  Map.Entry {
0384:
0385:                // immutable Entry
0386:                private final Object key;
0387:                private final Object value;
0388:
0389:                Entry(Object key, Object value) {
0390:                    this .key = key;
0391:                    this .value = value;
0392:                }
0393:
0394:                public Object getKey() {
0395:                    return key;
0396:                }
0397:
0398:                public Object getValue() {
0399:                    return value;
0400:                }
0401:
0402:                // No support of setting the value
0403:                public Object setValue(Object value) {
0404:                    throw new UnsupportedOperationException();
0405:                }
0406:
0407:                public int hashCode() {
0408:                    return ((key == null ? 0 : key.hashCode()) ^ (value == null ? 0
0409:                            : value.hashCode()));
0410:                }
0411:
0412:                public boolean equals(Object obj) {
0413:                    if (obj == null || !(obj instanceof  Map.Entry))
0414:                        return false;
0415:
0416:                    Map.Entry input = (Map.Entry) obj;
0417:                    Object inputKey = input.getKey();
0418:                    Object inputValue = input.getValue();
0419:
0420:                    if (inputKey == key
0421:                            || (inputKey != null && inputKey.equals(key))) {
0422:                        if (inputValue == value
0423:                                || (inputValue != null && inputValue
0424:                                        .equals(value))) {
0425:                            return true;
0426:                        }
0427:                    }
0428:                    return false;
0429:                }
0430:            }
0431:        }
0432:
0433:        class PortletApplicationMap extends BaseContextMap {
0434:
0435:            public PortletApplicationMap(PortletContext context) {
0436:                this .context = context;
0437:            }
0438:
0439:            private PortletContext context = null;
0440:
0441:            public void clear() {
0442:                Iterator keys = keySet().iterator();
0443:                while (keys.hasNext()) {
0444:                    context.removeAttribute((String) keys.next());
0445:                }
0446:            }
0447:
0448:            public boolean containsKey(Object key) {
0449:                return (context.getAttribute(key(key)) != null);
0450:            }
0451:
0452:            public boolean containsValue(Object value) {
0453:                if (value == null) {
0454:                    return (false);
0455:                }
0456:                Enumeration keys = context.getAttributeNames();
0457:                while (keys.hasMoreElements()) {
0458:                    Object next = context.getAttribute((String) keys
0459:                            .nextElement());
0460:                    if (next == value) {
0461:                        return (true);
0462:                    }
0463:                }
0464:                return (false);
0465:            }
0466:
0467:            public Set entrySet() {
0468:                Set entries = new HashSet();
0469:                for (Enumeration e = context.getAttributeNames(); e
0470:                        .hasMoreElements();) {
0471:                    String key = (String) e.nextElement();
0472:                    entries.add(new Entry(key, context.getAttribute(key)));
0473:                }
0474:                return entries;
0475:            }
0476:
0477:            public boolean equals(Object o) {
0478:                return (context.equals(o));
0479:            }
0480:
0481:            public Object get(Object key) {
0482:                return (context.getAttribute(key(key)));
0483:            }
0484:
0485:            public int hashCode() {
0486:                return (context.hashCode());
0487:            }
0488:
0489:            public boolean isEmpty() {
0490:                return (size() < 1);
0491:            }
0492:
0493:            public Set keySet() {
0494:                Set set = new HashSet();
0495:                Enumeration keys = context.getAttributeNames();
0496:                while (keys.hasMoreElements()) {
0497:                    set.add(keys.nextElement());
0498:                }
0499:                return (set);
0500:            }
0501:
0502:            public Object put(Object key, Object value) {
0503:                if (value == null) {
0504:                    return (remove(key));
0505:                }
0506:                String skey = key(key);
0507:                Object previous = context.getAttribute(skey);
0508:                context.setAttribute(skey, value);
0509:                return (previous);
0510:            }
0511:
0512:            public void putAll(Map map) {
0513:                Iterator keys = map.keySet().iterator();
0514:                while (keys.hasNext()) {
0515:                    String key = (String) keys.next();
0516:                    context.setAttribute(key, map.get(key));
0517:                }
0518:            }
0519:
0520:            public Object remove(Object key) {
0521:                String skey = key(key);
0522:                Object previous = context.getAttribute(skey);
0523:                context.removeAttribute(skey);
0524:                return (previous);
0525:            }
0526:
0527:            public int size() {
0528:                int n = 0;
0529:                Enumeration keys = context.getAttributeNames();
0530:                while (keys.hasMoreElements()) {
0531:                    keys.nextElement();
0532:                    n++;
0533:                }
0534:                return (n);
0535:            }
0536:
0537:            public Collection values() {
0538:                List list = new ArrayList();
0539:                Enumeration keys = context.getAttributeNames();
0540:                while (keys.hasMoreElements()) {
0541:                    list.add(context.getAttribute((String) keys.nextElement()));
0542:                }
0543:                return (list);
0544:            }
0545:
0546:            private String key(Object key) {
0547:                if (key == null) {
0548:                    throw new IllegalArgumentException();
0549:                } else if (key instanceof  String) {
0550:                    return ((String) key);
0551:                } else {
0552:                    return (key.toString());
0553:                }
0554:            }
0555:
0556:        }
0557:
0558:        class PortletInitParameterMap extends BaseContextMap {
0559:
0560:            public PortletInitParameterMap(PortletContext context) {
0561:                this .context = context;
0562:            }
0563:
0564:            private PortletContext context = null;
0565:
0566:            public void clear() {
0567:                throw new UnsupportedOperationException();
0568:            }
0569:
0570:            public boolean containsKey(Object key) {
0571:                return (context.getInitParameter(key(key)) != null);
0572:            }
0573:
0574:            public boolean containsValue(Object value) {
0575:                Iterator values = values().iterator();
0576:                while (values.hasNext()) {
0577:                    if (value.equals(values.next())) {
0578:                        return (true);
0579:                    }
0580:                }
0581:                return (false);
0582:            }
0583:
0584:            public Set entrySet() {
0585:                Set entries = new HashSet();
0586:
0587:                for (Enumeration e = context.getInitParameterNames(); e
0588:                        .hasMoreElements();) {
0589:                    String initParamName = (String) e.nextElement();
0590:                    entries.add(new Entry(initParamName, context
0591:                            .getInitParameter(initParamName)));
0592:                }
0593:                return entries;
0594:            }
0595:
0596:            public boolean equals(Object o) {
0597:                return (context.equals(o));
0598:            }
0599:
0600:            public Object get(Object key) {
0601:                return (context.getInitParameter(key(key)));
0602:            }
0603:
0604:            public int hashCode() {
0605:                return (context.hashCode());
0606:            }
0607:
0608:            public boolean isEmpty() {
0609:                return (size() < 1);
0610:            }
0611:
0612:            public Set keySet() {
0613:                Set set = new HashSet();
0614:                Enumeration keys = context.getInitParameterNames();
0615:                while (keys.hasMoreElements()) {
0616:                    set.add(keys.nextElement());
0617:                }
0618:                return (set);
0619:            }
0620:
0621:            public Object put(Object key, Object value) {
0622:                throw new UnsupportedOperationException();
0623:            }
0624:
0625:            public void putAll(Map map) {
0626:                throw new UnsupportedOperationException();
0627:            }
0628:
0629:            public Object remove(Object key) {
0630:                throw new UnsupportedOperationException();
0631:            }
0632:
0633:            public int size() {
0634:                int n = 0;
0635:                Enumeration keys = context.getInitParameterNames();
0636:                while (keys.hasMoreElements()) {
0637:                    keys.nextElement();
0638:                    n++;
0639:                }
0640:                return (n);
0641:            }
0642:
0643:            public Collection values() {
0644:                List list = new ArrayList();
0645:                Enumeration keys = context.getInitParameterNames();
0646:                while (keys.hasMoreElements()) {
0647:                    list.add(context.getInitParameter((String) keys
0648:                            .nextElement()));
0649:                }
0650:                return (list);
0651:            }
0652:
0653:            private String key(Object key) {
0654:                if (key == null) {
0655:                    throw new IllegalArgumentException();
0656:                } else if (key instanceof  String) {
0657:                    return ((String) key);
0658:                } else {
0659:                    return (key.toString());
0660:                }
0661:            }
0662:
0663:        }
0664:
0665:        class PortletRequestHeaderMap extends BaseContextMap {
0666:
0667:            public PortletRequestHeaderMap(PortletRequest request) {
0668:                this .request = request;
0669:            }
0670:
0671:            private PortletRequest request = null;
0672:
0673:            public void clear() {
0674:                throw new UnsupportedOperationException();
0675:            }
0676:
0677:            public boolean containsKey(Object key) {
0678:                return (request.getProperty(key(key)) != null);
0679:            }
0680:
0681:            public boolean containsValue(Object value) {
0682:                Iterator values = values().iterator();
0683:                while (values.hasNext()) {
0684:                    if (value.equals(values.next())) {
0685:                        return (true);
0686:                    }
0687:                }
0688:                return (false);
0689:            }
0690:
0691:            public Set entrySet() {
0692:                Set set = new HashSet();
0693:                Enumeration keys = request.getPropertyNames();
0694:                while (keys.hasMoreElements()) {
0695:                    set.add(request.getProperty((String) keys.nextElement()));
0696:                }
0697:                return (set);
0698:            }
0699:
0700:            public boolean equals(Object o) {
0701:                return (request.equals(o));
0702:            }
0703:
0704:            public Object get(Object key) {
0705:                return (request.getProperty(key(key)));
0706:            }
0707:
0708:            public int hashCode() {
0709:                return (request.hashCode());
0710:            }
0711:
0712:            public boolean isEmpty() {
0713:                return (size() < 1);
0714:            }
0715:
0716:            public Set keySet() {
0717:                Set set = new HashSet();
0718:                Enumeration keys = request.getPropertyNames();
0719:                while (keys.hasMoreElements()) {
0720:                    set.add(keys.nextElement());
0721:                }
0722:                return (set);
0723:            }
0724:
0725:            public Object put(Object key, Object value) {
0726:                throw new UnsupportedOperationException();
0727:            }
0728:
0729:            public void putAll(Map map) {
0730:                throw new UnsupportedOperationException();
0731:            }
0732:
0733:            public Object remove(Object key) {
0734:                throw new UnsupportedOperationException();
0735:            }
0736:
0737:            public int size() {
0738:                int n = 0;
0739:                Enumeration keys = request.getPropertyNames();
0740:                while (keys.hasMoreElements()) {
0741:                    keys.nextElement();
0742:                    n++;
0743:                }
0744:                return (n);
0745:            }
0746:
0747:            public Collection values() {
0748:                List list = new ArrayList();
0749:                Enumeration keys = request.getPropertyNames();
0750:                while (keys.hasMoreElements()) {
0751:                    list.add(request.getProperty((String) keys.nextElement()));
0752:                }
0753:                return (list);
0754:            }
0755:
0756:            private String key(Object key) {
0757:                if (key == null) {
0758:                    throw new IllegalArgumentException();
0759:                } else if (key instanceof  String) {
0760:                    return ((String) key);
0761:                } else {
0762:                    return (key.toString());
0763:                }
0764:            }
0765:
0766:        }
0767:
0768:        class PortletRequestHeaderValuesMap extends BaseContextMap {
0769:
0770:            public PortletRequestHeaderValuesMap(PortletRequest request) {
0771:                this .request = request;
0772:            }
0773:
0774:            private PortletRequest request = null;
0775:
0776:            public void clear() {
0777:                throw new UnsupportedOperationException();
0778:            }
0779:
0780:            public boolean containsKey(Object key) {
0781:                return (request.getProperty(key(key)) != null);
0782:            }
0783:
0784:            public boolean containsValue(Object value) {
0785:                if (!(value instanceof  String[])) {
0786:                    return (false);
0787:                }
0788:                String test[] = (String[]) value;
0789:                Iterator values = values().iterator();
0790:                while (values.hasNext()) {
0791:                    String actual[] = (String[]) values.next();
0792:                    if (test.length == actual.length) {
0793:                        boolean matched = true;
0794:                        for (int i = 0; i < test.length; i++) {
0795:                            if (!test[i].equals(actual[i])) {
0796:                                matched = false;
0797:                                break;
0798:                            }
0799:                        }
0800:                        if (matched) {
0801:                            return (true);
0802:                        }
0803:                    }
0804:                }
0805:                return (false);
0806:            }
0807:
0808:            public Set entrySet() {
0809:                Set set = new HashSet();
0810:                Enumeration keys = request.getPropertyNames();
0811:                while (keys.hasMoreElements()) {
0812:                    set.add(request.getProperties((String) keys.nextElement()));
0813:                }
0814:                return (set);
0815:            }
0816:
0817:            public boolean equals(Object o) {
0818:                return (request.equals(o));
0819:            }
0820:
0821:            public Object get(Object key) {
0822:                List list = new ArrayList();
0823:                Enumeration values = request.getProperties(key(key));
0824:                while (values.hasMoreElements()) {
0825:                    list.add((String) values.nextElement());
0826:                }
0827:                return (((String[]) list.toArray(new String[list.size()])));
0828:            }
0829:
0830:            public int hashCode() {
0831:                return (request.hashCode());
0832:            }
0833:
0834:            public boolean isEmpty() {
0835:                return (size() < 1);
0836:            }
0837:
0838:            public Set keySet() {
0839:                Set set = new HashSet();
0840:                Enumeration keys = request.getPropertyNames();
0841:                while (keys.hasMoreElements()) {
0842:                    set.add(keys.nextElement());
0843:                }
0844:                return (set);
0845:            }
0846:
0847:            public Object put(Object key, Object value) {
0848:                throw new UnsupportedOperationException();
0849:            }
0850:
0851:            public void putAll(Map map) {
0852:                throw new UnsupportedOperationException();
0853:            }
0854:
0855:            public Object remove(Object key) {
0856:                throw new UnsupportedOperationException();
0857:            }
0858:
0859:            public int size() {
0860:                int n = 0;
0861:                Enumeration keys = request.getPropertyNames();
0862:                while (keys.hasMoreElements()) {
0863:                    keys.nextElement();
0864:                    n++;
0865:                }
0866:                return (n);
0867:            }
0868:
0869:            public Collection values() {
0870:                List list = new ArrayList();
0871:                Enumeration keys = request.getPropertyNames();
0872:                while (keys.hasMoreElements()) {
0873:                    String key = (String) keys.nextElement();
0874:                    List list1 = new ArrayList();
0875:                    Enumeration values = request.getProperties(key);
0876:                    while (values.hasMoreElements()) {
0877:                        list1.add((String) values.nextElement());
0878:                    }
0879:                    list.add(((String[]) list1
0880:                            .toArray(new String[list1.size()])));
0881:                }
0882:                return (list);
0883:            }
0884:
0885:            private String key(Object key) {
0886:                if (key == null) {
0887:                    throw new IllegalArgumentException();
0888:                } else if (key instanceof  String) {
0889:                    return ((String) key);
0890:                } else {
0891:                    return (key.toString());
0892:                }
0893:            }
0894:
0895:        }
0896:
0897:        class PortletRequestMap extends BaseContextMap {
0898:
0899:            public PortletRequestMap(PortletRequest request) {
0900:                this .request = request;
0901:            }
0902:
0903:            private PortletRequest request = null;
0904:
0905:            public void clear() {
0906:                Iterator keys = keySet().iterator();
0907:                while (keys.hasNext()) {
0908:                    request.removeAttribute((String) keys.next());
0909:                }
0910:            }
0911:
0912:            public boolean containsKey(Object key) {
0913:                return (request.getAttribute(key(key)) != null);
0914:            }
0915:
0916:            public boolean containsValue(Object value) {
0917:                if (value == null) {
0918:                    return (false);
0919:                }
0920:                Enumeration keys = request.getAttributeNames();
0921:                while (keys.hasMoreElements()) {
0922:                    Object next = request.getAttribute((String) keys
0923:                            .nextElement());
0924:                    if (next == value) {
0925:                        return (true);
0926:                    }
0927:                }
0928:                return (false);
0929:            }
0930:
0931:            public Set entrySet() {
0932:                Set entries = new HashSet();
0933:                for (Enumeration e = request.getAttributeNames(); e
0934:                        .hasMoreElements();) {
0935:                    String key = (String) e.nextElement();
0936:                    entries.add(new Entry(key, request.getAttribute(key)));
0937:                }
0938:                return entries;
0939:            }
0940:
0941:            public boolean equals(Object o) {
0942:                return (request.equals(o));
0943:            }
0944:
0945:            public Object get(Object key) {
0946:                return (request.getAttribute(key(key)));
0947:            }
0948:
0949:            public int hashCode() {
0950:                return (request.hashCode());
0951:            }
0952:
0953:            public boolean isEmpty() {
0954:                return (size() < 1);
0955:            }
0956:
0957:            public Set keySet() {
0958:                Set set = new HashSet();
0959:                Enumeration keys = request.getAttributeNames();
0960:                while (keys.hasMoreElements()) {
0961:                    set.add(keys.nextElement());
0962:                }
0963:                return (set);
0964:            }
0965:
0966:            public Object put(Object key, Object value) {
0967:                if (value == null) {
0968:                    return (remove(key));
0969:                }
0970:                String skey = key(key);
0971:                Object previous = request.getAttribute(skey);
0972:                request.setAttribute(skey, value);
0973:                return (previous);
0974:            }
0975:
0976:            public void putAll(Map map) {
0977:                Iterator keys = map.keySet().iterator();
0978:                while (keys.hasNext()) {
0979:                    String key = (String) keys.next();
0980:                    request.setAttribute(key, map.get(key));
0981:                }
0982:            }
0983:
0984:            public Object remove(Object key) {
0985:                String skey = key(key);
0986:                Object previous = request.getAttribute(skey);
0987:                request.removeAttribute(skey);
0988:                return (previous);
0989:            }
0990:
0991:            public int size() {
0992:                int n = 0;
0993:                Enumeration keys = request.getAttributeNames();
0994:                while (keys.hasMoreElements()) {
0995:                    keys.nextElement();
0996:                    n++;
0997:                }
0998:                return (n);
0999:            }
1000:
1001:            public Collection values() {
1002:                List list = new ArrayList();
1003:                Enumeration keys = request.getAttributeNames();
1004:                while (keys.hasMoreElements()) {
1005:                    list.add(request.getAttribute((String) keys.nextElement()));
1006:                }
1007:                return (list);
1008:            }
1009:
1010:            private String key(Object key) {
1011:                if (key == null) {
1012:                    throw new IllegalArgumentException();
1013:                } else if (key instanceof  String) {
1014:                    return ((String) key);
1015:                } else {
1016:                    return (key.toString());
1017:                }
1018:            }
1019:
1020:        }
1021:
1022:        class PortletRequestParameterMap extends BaseContextMap {
1023:
1024:            public PortletRequestParameterMap(PortletRequest request) {
1025:                this .request = request;
1026:            }
1027:
1028:            private PortletRequest request = null;
1029:
1030:            public void clear() {
1031:                throw new UnsupportedOperationException();
1032:            }
1033:
1034:            public boolean containsKey(Object key) {
1035:                return (request.getParameter(key(key)) != null);
1036:            }
1037:
1038:            public boolean containsValue(Object value) {
1039:                Iterator values = values().iterator();
1040:                while (values.hasNext()) {
1041:                    if (value.equals(values.next())) {
1042:                        return (true);
1043:                    }
1044:                }
1045:                return (false);
1046:            }
1047:
1048:            public Set entrySet() {
1049:                Set entries = new HashSet();
1050:                for (Enumeration e = request.getParameterNames(); e
1051:                        .hasMoreElements();) {
1052:                    String paramName = (String) e.nextElement();
1053:                    entries.add(new Entry(paramName, request
1054:                            .getParameter(paramName)));
1055:                }
1056:                return entries;
1057:            }
1058:
1059:            public boolean equals(Object o) {
1060:                return (request.equals(o));
1061:            }
1062:
1063:            public Object get(Object key) {
1064:                if (key == null) {
1065:                    throw new NullPointerException();
1066:                }
1067:                return (request.getParameter(key(key)));
1068:            }
1069:
1070:            public int hashCode() {
1071:                return (request.hashCode());
1072:            }
1073:
1074:            public boolean isEmpty() {
1075:                return (size() < 1);
1076:            }
1077:
1078:            public Set keySet() {
1079:                Set set = new HashSet();
1080:                Enumeration keys = request.getParameterNames();
1081:                while (keys.hasMoreElements()) {
1082:                    set.add(keys.nextElement());
1083:                }
1084:                return (set);
1085:            }
1086:
1087:            public Object put(Object key, Object value) {
1088:                throw new UnsupportedOperationException();
1089:            }
1090:
1091:            public void putAll(Map map) {
1092:                throw new UnsupportedOperationException();
1093:            }
1094:
1095:            public Object remove(Object key) {
1096:                throw new UnsupportedOperationException();
1097:            }
1098:
1099:            public int size() {
1100:                int n = 0;
1101:                Enumeration keys = request.getParameterNames();
1102:                while (keys.hasMoreElements()) {
1103:                    keys.nextElement();
1104:                    n++;
1105:                }
1106:                return (n);
1107:            }
1108:
1109:            public Collection values() {
1110:                List list = new ArrayList();
1111:                Enumeration keys = request.getParameterNames();
1112:                while (keys.hasMoreElements()) {
1113:                    list.add(request.getParameter((String) keys.nextElement()));
1114:                }
1115:                return (list);
1116:            }
1117:
1118:            private String key(Object key) {
1119:                if (key == null) {
1120:                    throw new IllegalArgumentException();
1121:                } else if (key instanceof  String) {
1122:                    return ((String) key);
1123:                } else {
1124:                    return (key.toString());
1125:                }
1126:            }
1127:
1128:        }
1129:
1130:        class PortletRequestParameterValuesMap extends BaseContextMap {
1131:
1132:            public PortletRequestParameterValuesMap(PortletRequest request) {
1133:                this .request = request;
1134:            }
1135:
1136:            private PortletRequest request = null;
1137:
1138:            public void clear() {
1139:                throw new UnsupportedOperationException();
1140:            }
1141:
1142:            public boolean containsKey(Object key) {
1143:                return (request.getParameter(key(key)) != null);
1144:            }
1145:
1146:            public boolean containsValue(Object value) {
1147:                Iterator values = values().iterator();
1148:                while (values.hasNext()) {
1149:                    if (value.equals(values.next())) {
1150:                        return (true);
1151:                    }
1152:                }
1153:                return (false);
1154:            }
1155:
1156:            public Object get(Object key) {
1157:                if (key == null) {
1158:                    throw new NullPointerException();
1159:                }
1160:                return request.getParameterValues(key.toString());
1161:            }
1162:
1163:            public Set entrySet() {
1164:                Set entries = new HashSet();
1165:                for (Enumeration e = request.getParameterNames(); e
1166:                        .hasMoreElements();) {
1167:                    String paramName = (String) e.nextElement();
1168:                    entries.add(new Entry(paramName, request
1169:                            .getParameterValues(paramName)));
1170:                }
1171:                return entries;
1172:            }
1173:
1174:            public boolean equals(Object obj) {
1175:                if (obj == null
1176:                        || !(obj instanceof  PortletRequestParameterValuesMap))
1177:                    return false;
1178:                return super .equals(obj);
1179:            }
1180:
1181:            public int hashCode() {
1182:                return (request.hashCode());
1183:            }
1184:
1185:            public boolean isEmpty() {
1186:                return (size() < 1);
1187:            }
1188:
1189:            public Set keySet() {
1190:                Set set = new HashSet();
1191:                Enumeration keys = request.getParameterNames();
1192:                while (keys.hasMoreElements()) {
1193:                    set.add(keys.nextElement());
1194:                }
1195:                return (set);
1196:            }
1197:
1198:            public Object put(Object key, Object value) {
1199:                throw new UnsupportedOperationException();
1200:            }
1201:
1202:            public void putAll(Map map) {
1203:                throw new UnsupportedOperationException();
1204:            }
1205:
1206:            public Object remove(Object key) {
1207:                throw new UnsupportedOperationException();
1208:            }
1209:
1210:            public int size() {
1211:                int n = 0;
1212:                Enumeration keys = request.getParameterNames();
1213:                while (keys.hasMoreElements()) {
1214:                    keys.nextElement();
1215:                    n++;
1216:                }
1217:                return (n);
1218:            }
1219:
1220:            public Collection values() {
1221:                List list = new ArrayList();
1222:                Enumeration keys = request.getParameterNames();
1223:                while (keys.hasMoreElements()) {
1224:                    list.add(request.getParameterValues((String) keys
1225:                            .nextElement()));
1226:                }
1227:                return (list);
1228:            }
1229:
1230:            private String key(Object key) {
1231:                if (key == null) {
1232:                    throw new IllegalArgumentException();
1233:                } else if (key instanceof  String) {
1234:                    return ((String) key);
1235:                } else {
1236:                    return (key.toString());
1237:                }
1238:            }
1239:
1240:        }
1241:
1242:        class PortletSessionMap extends BaseContextMap {
1243:
1244:            public PortletSessionMap(PortletRequest request,
1245:                    PortletResponse response, Map requestParamMap) {
1246:                this .session = request.getPortletSession();
1247:                if (response instanceof  ActionResponse) {
1248:                    this .namespace = (String) requestParamMap
1249:                            .get(ViewHandlerImpl.NAME_SPACE_PARAMETER);
1250:                } else if (response instanceof  RenderResponse) {
1251:                    this .namespace = ((RenderResponse) response).getNamespace();
1252:                } else { // May be EventResponse(used in Sun's InterPortletCommunication)
1253:                    this .namespace = "";
1254:                }
1255:            }
1256:
1257:            private PortletSession session;
1258:            private String namespace;
1259:
1260:            public void clear() {
1261:                Iterator keys = keySet().iterator();
1262:                while (keys.hasNext()) {
1263:                    session.removeAttribute(namespace + (String) keys.next());
1264:                }
1265:            }
1266:
1267:            public boolean containsKey(Object key) {
1268:                return (session.getAttribute(namespace + key(key)) != null);
1269:            }
1270:
1271:            public boolean containsValue(Object value) {
1272:                if (value == null) {
1273:                    return (false);
1274:                }
1275:                Enumeration keys = session
1276:                        .getAttributeNames(PortletSession.PORTLET_SCOPE);
1277:                while (keys.hasMoreElements()) {
1278:                    Object next = session.getAttribute(namespace
1279:                            + (String) keys.nextElement());
1280:                    if (next == value) {
1281:                        return (true);
1282:                    }
1283:                }
1284:                return (false);
1285:            }
1286:
1287:            public Set entrySet() {
1288:                Set entries = new HashSet();
1289:                for (Enumeration e = session.getAttributeNames(); e
1290:                        .hasMoreElements();) {
1291:                    String key = (String) e.nextElement();
1292:                    entries.add(new Entry(key, session.getAttribute(namespace
1293:                            + key)));
1294:                }
1295:                return entries;
1296:            }
1297:
1298:            public boolean equals(Object o) {
1299:                return (session.equals(namespace + o));
1300:            }
1301:
1302:            public Object get(Object key) {
1303:                return (session.getAttribute(namespace + key(key)));
1304:            }
1305:
1306:            public int hashCode() {
1307:                return (session.hashCode());
1308:            }
1309:
1310:            public boolean isEmpty() {
1311:                return (size() < 1);
1312:            }
1313:
1314:            public Set keySet() {
1315:                Set set = new HashSet();
1316:                Enumeration keys = session
1317:                        .getAttributeNames(PortletSession.PORTLET_SCOPE);
1318:                while (keys.hasMoreElements()) {
1319:                    set.add(keys.nextElement());
1320:                }
1321:                return (set);
1322:            }
1323:
1324:            public Object put(Object key, Object value) {
1325:                if (value == null) {
1326:                    return (remove(key));
1327:                }
1328:                String skey = key(key);
1329:                Object previous = session.getAttribute(namespace + skey);
1330:                session.setAttribute(namespace + skey, value);
1331:                return (previous);
1332:            }
1333:
1334:            public void putAll(Map map) {
1335:                Iterator keys = map.keySet().iterator();
1336:                while (keys.hasNext()) {
1337:                    String key = (String) keys.next();
1338:                    session.setAttribute(namespace + key, map.get(key));
1339:                }
1340:            }
1341:
1342:            public Object remove(Object key) {
1343:                String skey = key(key);
1344:                Object previous = session.getAttribute(namespace + skey);
1345:                session.removeAttribute(namespace + skey);
1346:                return (previous);
1347:            }
1348:
1349:            public int size() {
1350:                int n = 0;
1351:                Enumeration keys = session
1352:                        .getAttributeNames(PortletSession.PORTLET_SCOPE);
1353:                while (keys.hasMoreElements()) {
1354:                    keys.nextElement();
1355:                    n++;
1356:                }
1357:                return (n);
1358:            }
1359:
1360:            public Collection values() {
1361:                List list = new ArrayList();
1362:                Enumeration keys = session
1363:                        .getAttributeNames(PortletSession.PORTLET_SCOPE);
1364:                while (keys.hasMoreElements()) {
1365:                    list.add(session.getAttribute(namespace
1366:                            + (String) keys.nextElement()));
1367:                }
1368:                return (list);
1369:            }
1370:
1371:            private String key(Object key) {
1372:                if (key == null) {
1373:                    throw new IllegalArgumentException();
1374:                } else if (key instanceof  String) {
1375:                    return ((String) key);
1376:                } else {
1377:                    return (key.toString());
1378:                }
1379:            }
1380:        }
1381:
1382:        class PortletSessionWrapper implements  PortletSession {
1383:
1384:            public PortletSessionWrapper(PortletSession session,
1385:                    PortletResponse response, Map requestParamMap) {
1386:                this .session = session;
1387:                if (response instanceof  ActionResponse) {
1388:                    this .namespace = (String) requestParamMap
1389:                            .get(ViewHandlerImpl.NAME_SPACE_PARAMETER);
1390:                } else if (response instanceof  RenderResponse) {
1391:                    this .namespace = ((RenderResponse) response).getNamespace();
1392:                } else { // May be EventResponse(used in Sun's InterPortletCommunication)
1393:                    this .namespace = "";
1394:                }
1395:            }
1396:
1397:            private PortletSession session;
1398:            private String namespace;
1399:
1400:            public Object getAttribute(java.lang.String name)
1401:                    throws IllegalArgumentException {
1402:                return session.getAttribute(namespace + name);
1403:            }
1404:
1405:            public Object getAttribute(String name, int scope)
1406:                    throws IllegalArgumentException {
1407:                return session.getAttribute(namespace + name, scope);
1408:            }
1409:
1410:            public Enumeration getAttributeNames() {
1411:                return session.getAttributeNames();
1412:            }
1413:
1414:            public Enumeration getAttributeNames(int scope) {
1415:                return session.getAttributeNames(scope);
1416:            }
1417:
1418:            public long getCreationTime() {
1419:                return session.getCreationTime();
1420:            }
1421:
1422:            public String getId() {
1423:                return session.getId();
1424:            }
1425:
1426:            public long getLastAccessedTime() {
1427:                return session.getLastAccessedTime();
1428:            }
1429:
1430:            public int getMaxInactiveInterval() {
1431:                return session.getMaxInactiveInterval();
1432:            }
1433:
1434:            public void invalidate() {
1435:                session.invalidate();
1436:            }
1437:
1438:            public boolean isNew() {
1439:                return session.isNew();
1440:            }
1441:
1442:            public void removeAttribute(String name)
1443:                    throws IllegalArgumentException {
1444:                session.removeAttribute(namespace + name);
1445:            }
1446:
1447:            public void removeAttribute(String name, int scope)
1448:                    throws IllegalArgumentException {
1449:                session.removeAttribute(namespace + name, scope);
1450:            }
1451:
1452:            public void setAttribute(String name, Object value)
1453:                    throws IllegalArgumentException {
1454:                session.setAttribute(namespace + name, value);
1455:            }
1456:
1457:            public void setAttribute(String name, Object value, int scope)
1458:                    throws IllegalArgumentException {
1459:                session.setAttribute(namespace + name, value, scope);
1460:            }
1461:
1462:            public void setMaxInactiveInterval(int interval) {
1463:                session.setMaxInactiveInterval(interval);
1464:            }
1465:
1466:            public PortletContext getPortletContext() {
1467:                return session.getPortletContext();
1468:            }
1469:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.