Source Code Cross Referenced for ServletRequestImpl.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » engine » servlet » 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 » jetspeed 2.1.3 » org.apache.jetspeed.engine.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.engine.servlet;
018:
019:        import java.io.BufferedReader;
020:        import java.io.IOException;
021:        import java.io.UnsupportedEncodingException;
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Collections;
025:        import java.util.Enumeration;
026:        import java.util.HashMap;
027:        import java.util.HashSet;
028:        import java.util.Iterator;
029:        import java.util.Locale;
030:        import java.util.Map;
031:
032:        import javax.portlet.PortletRequest;
033:        import javax.servlet.ServletInputStream;
034:        import javax.servlet.ServletRequest;
035:        import javax.servlet.http.HttpServletRequest;
036:        import javax.servlet.http.HttpServletRequestWrapper;
037:
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:        import org.apache.jetspeed.Jetspeed;
041:        import org.apache.jetspeed.PortalReservedParameters;
042:        import org.apache.jetspeed.aggregator.CurrentWorkerContext;
043:        import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
044:        import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapper;
045:        import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapperFactory;
046:        import org.apache.jetspeed.container.state.NavigationalState;
047:        import org.apache.jetspeed.container.url.PortalURL;
048:        import org.apache.jetspeed.om.common.GenericMetadata;
049:        import org.apache.jetspeed.om.common.LocalizedField;
050:        import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
051:        import org.apache.jetspeed.request.JetspeedRequestContext;
052:        import org.apache.jetspeed.request.RequestContext;
053:        import org.apache.pluto.om.entity.PortletEntity;
054:        import org.apache.pluto.om.portlet.PortletApplicationDefinition;
055:        import org.apache.pluto.om.window.PortletWindow;
056:        import org.apache.pluto.util.Enumerator;
057:
058:        /**
059:         * This request wrappers the servlet request and is used within the container to
060:         * communicate to the invoked servlet.
061:         * 
062:         * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
063:         * @version $Id: ServletRequestImpl.java 587064 2007-10-22 11:54:11Z woonsan $
064:         */
065:        public class ServletRequestImpl extends HttpServletRequestWrapper
066:                implements  PortletDispatcherIncludeAware {
067:            public static final String ACCEPT_LANGUAGE = "Accept-Language";
068:            /** Logger */
069:            private static final Log log = LogFactory
070:                    .getLog(ServletRequestImpl.class);
071:
072:            PortletWindow portletWindow = null;
073:            private JetspeedNamespaceMapper nameSpaceMapper = null;
074:            private ServletRequest currentRequest = null;
075:
076:            private Map portletParameters;
077:
078:            private boolean included;
079:
080:            private static Boolean mergePortalParametersWithPortletParameters;
081:            private static Boolean mergePortalParametersBeforePortletParameters;
082:
083:            private boolean portletMergePortalParametersWithPortletParameters;
084:            private boolean portletMergePortalParametersBeforePortletParameters;
085:
086:            private Map portalParameters;
087:
088:            private String currentIncludeQueryString;
089:            private String currentForwardQueryString;
090:
091:            // request attributes map which is cached for each paralleled worker.
092:            // this should be re-created when it is called for the first time or when some attributes are added/modified/removed.
093:            private Map cachedAttributes;
094:
095:            public ServletRequestImpl(HttpServletRequest servletRequest,
096:                    PortletWindow window) {
097:                super (servletRequest);
098:                nameSpaceMapper = ((JetspeedNamespaceMapperFactory) Jetspeed
099:                        .getComponentManager().getComponent(
100:                                org.apache.pluto.util.NamespaceMapper.class))
101:                        .getJetspeedNamespaceMapper();
102:                this .portletWindow = window;
103:
104:                String encoding = (String) servletRequest
105:                        .getAttribute(PortalReservedParameters.PREFERED_CHARACTERENCODING_ATTRIBUTE);
106:                boolean decode = servletRequest
107:                        .getAttribute(PortalReservedParameters.PARAMETER_ALREADY_DECODED_ATTRIBUTE) == null
108:                        && encoding != null;
109:                if (decode) {
110:                    servletRequest
111:                            .setAttribute(
112:                                    PortalReservedParameters.PARAMETER_ALREADY_DECODED_ATTRIBUTE,
113:                                    new Boolean(true));
114:                }
115:
116:                //get portal servlet params
117:                portalParameters = new HashMap();
118:                for (Enumeration parameters = servletRequest
119:                        .getParameterNames(); parameters.hasMoreElements();) {
120:                    String paramName = (String) parameters.nextElement();
121:                    String[] paramValues = servletRequest
122:                            .getParameterValues(paramName);
123:
124:                    if (decode) {
125:                        for (int i = 0; i < paramValues.length; i++) {
126:                            try {
127:                                paramValues[i] = new String(paramValues[i]
128:                                        .getBytes("ISO-8859-1"), encoding);
129:                            } catch (UnsupportedEncodingException e) {
130:                                ;
131:                            }
132:                        }
133:                    }
134:                    portalParameters.put(paramName, paramValues);
135:                }
136:
137:                if (mergePortalParametersWithPortletParameters == null) {
138:                    mergePortalParametersWithPortletParameters = new Boolean(
139:                            Jetspeed
140:                                    .getContext()
141:                                    .getConfiguration()
142:                                    .getBoolean(
143:                                            "merge.portal.parameters.with.portlet.parameters",
144:                                            false));
145:                }
146:
147:                if (mergePortalParametersBeforePortletParameters == null) {
148:                    mergePortalParametersBeforePortletParameters = new Boolean(
149:                            Jetspeed
150:                                    .getContext()
151:                                    .getConfiguration()
152:                                    .getBoolean(
153:                                            "merge.portal.parameters.before.portlet.parameters",
154:                                            false));
155:                }
156:
157:                PortletDefinitionComposite portletDef = (PortletDefinitionComposite) portletWindow
158:                        .getPortletEntity().getPortletDefinition();
159:                if (portletDef != null) {
160:                    GenericMetadata metaData = portletDef.getMetadata();
161:
162:                    portletMergePortalParametersWithPortletParameters = getMetaDataBooleanValue(
163:                            metaData,
164:                            PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_MERGE_PORTAL_PARAMETERS_WITH_PORTLET_PARAMETERS,
165:                            mergePortalParametersWithPortletParameters
166:                                    .booleanValue());
167:                    portletMergePortalParametersBeforePortletParameters = getMetaDataBooleanValue(
168:                            metaData,
169:                            PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_MERGE_PORTAL_PARAMETERS_BEFORE_PORTLET_PARAMETERS,
170:                            mergePortalParametersBeforePortletParameters
171:                                    .booleanValue());
172:
173:                } else {
174:                    // This happens when an entity is referencing a non-existent portlet
175:                    portletMergePortalParametersWithPortletParameters = mergePortalParametersWithPortletParameters
176:                            .booleanValue();
177:                    portletMergePortalParametersBeforePortletParameters = mergePortalParametersBeforePortletParameters
178:                            .booleanValue();
179:                }
180:            }
181:
182:            private boolean getMetaDataBooleanValue(GenericMetadata metaData,
183:                    String fieldName, boolean defaultValue) {
184:                String value = null;
185:                if (metaData != null) {
186:                    Collection fields = metaData.getFields(fieldName);
187:                    if (fields != null && !fields.isEmpty()) {
188:                        value = ((LocalizedField) fields.iterator().next())
189:                                .getValue();
190:                    }
191:                }
192:                if (value != null) {
193:                    return Boolean.valueOf(value).booleanValue();
194:                }
195:                return defaultValue;
196:            }
197:
198:            protected HttpServletRequest _getHttpServletRequest() {
199:                return (HttpServletRequest) super .getRequest();
200:            }
201:
202:            //  ServletRequestWrapper overlay
203:
204:            public String getParameter(String name) {
205:                Object value = this .getParameterMap().get(name);
206:                if (value == null) {
207:                    return (null);
208:                } else if (value instanceof  String[]) {
209:                    return (((String[]) value)[0]);
210:                } else if (value instanceof  String) {
211:                    return ((String) value);
212:                } else {
213:                    return (value.toString());
214:                }
215:            }
216:
217:            private boolean isEqual(String one, String two) {
218:                return (one == null && two == null)
219:                        || (one != null && two != null && one.equals(two));
220:            }
221:
222:            private boolean checkQueryStringChanged() {
223:                boolean changed = false;
224:                ServletRequest request = getRequest();
225:                String includeQueryString = (String) request
226:                        .getAttribute("javax.servlet.include.query_string");
227:                String forwardQueryString = (String) request
228:                        .getAttribute("javax.servlet.forward.query_string");
229:
230:                if (!isEqual(currentIncludeQueryString, includeQueryString)) {
231:                    currentIncludeQueryString = includeQueryString;
232:                    changed = true;
233:                }
234:                if (!isEqual(currentForwardQueryString, forwardQueryString)) {
235:                    currentForwardQueryString = forwardQueryString;
236:                    changed = true;
237:                }
238:                return changed;
239:            }
240:
241:            public Map getParameterMap() {
242:                // if included or forwarded with a query string, parameterMap might have changed
243:                // this is/should be the only check needed, and the other "tricky" check below probably
244:                // can be removed.
245:                // I'll keep it in for now though as it hasn't been tested enough on other app servers
246:                boolean queryStringChanged = checkQueryStringChanged();
247:
248:                if (queryStringChanged || currentRequest == null
249:                        || currentRequest != getRequest()) {
250:                    // Cache the parameters for as long as the wrapped request stays the same.
251:                    // According to Servlet 2.3 SRV.6.2.2 the passed on ServletRequest object
252:                    // to an dispatched Servlet must remain the same (this one).
253:                    // Tomcat solves this by injecting a new ServletRequest of its own above
254:                    // this one (the getRequest() object).
255:                    // So, when that one has changed since the last time the parameters have 
256:                    // been accessed, flush the cache and rebuild the map.
257:                    currentRequest = getRequest();
258:
259:                    boolean postAllowed = false;
260:
261:                    // determine the possible additional query string parameters provided on the RequestDispatcher include path
262:                    // per the specs, these are prepended to existing parameters or altogether new parameters
263:                    // as we save the original "portal" parameters, we can find those query string parameters by comparing against those
264:                    HashMap queryParameters = new HashMap();
265:                    for (Iterator iter = getRequest().getParameterMap()
266:                            .entrySet().iterator(); iter.hasNext();) {
267:                        Map.Entry entry = (Map.Entry) iter.next();
268:                        String[] values = (String[]) entry.getValue();
269:                        String[] original = (String[]) portalParameters
270:                                .get(entry.getKey());
271:                        String[] diff = null;
272:                        if (original == null) {
273:                            // a new parameter
274:                            diff = new String[values.length];
275:                            System.arraycopy(values, 0, diff, 0, values.length);
276:                        } else if (values.length > original.length) {
277:                            // we've got some additional query string parameter value(s)
278:                            diff = new String[values.length - original.length];
279:                            System.arraycopy(values, 0, diff, 0, values.length
280:                                    - original.length);
281:                        }
282:                        if (diff != null) {
283:                            queryParameters.put(entry.getKey(), diff);
284:                        }
285:                    }
286:
287:                    // get portlet navigational params
288:                    HashMap navParameters = new HashMap();
289:                    JetspeedRequestContext context = (JetspeedRequestContext) getAttribute("org.apache.jetspeed.request.RequestContext");
290:                    if (context != null) {
291:                        NavigationalState ns = context.getPortalURL()
292:                                .getNavigationalState();
293:                        postAllowed = ns.getPortletWindowOfAction() != null
294:                                || ns.getPortletWindowOfResource() != null;
295:                        Iterator iter = ns.getParameterNames(portletWindow);
296:                        while (iter.hasNext()) {
297:                            String name = (String) iter.next();
298:                            String[] values = ns.getParameterValues(
299:                                    portletWindow, name);
300:                            navParameters.put(name, values);
301:                        }
302:                    }
303:
304:                    // now first merge the keys we have into one unique set
305:                    HashSet keys = new HashSet();
306:                    keys.addAll(portalParameters.keySet());
307:                    keys.addAll(queryParameters.keySet());
308:                    keys.addAll(navParameters.keySet());
309:
310:                    // now "merge" the parameters
311:                    // there are three different options:
312:                    // 1) query parameters + nav parameters:
313:                    //        portletMergePortalParametersWithPortletParameters == false && !actionRequest
314:                    // 2) query parameters + nav parameters + portal parameters
315:                    //           portletMergePortalParametersWithPortletParameters == true || actionRequest
316:                    //        && portletMergePortalParametersBeforePortletParameters == false
317:                    // 3) query parameters + portal parameters + nav parameters (odd use-case but provided because this was the "old" pre-2.1 behavior
318:                    //           portletMergePortalParametersWithPortletParameters == true || actionRequest
319:                    //        && portletMergePortalParametersBeforePortletParameters == true
320:                    portletParameters = new HashMap();
321:                    for (Iterator iter = keys.iterator(); iter.hasNext();) {
322:                        String key = (String) iter.next();
323:                        String[] first = (String[]) queryParameters.get(key);
324:                        String[] next = null, last = null, result = null;
325:
326:                        if (portletMergePortalParametersWithPortletParameters == false
327:                                && !postAllowed) {
328:                            next = (String[]) navParameters.get(key);
329:                        } else if (portletMergePortalParametersBeforePortletParameters) {
330:                            next = (String[]) portalParameters.get(key);
331:                            last = (String[]) navParameters.get(key);
332:                        } else {
333:                            next = (String[]) navParameters.get(key);
334:                            last = (String[]) portalParameters.get(key);
335:                        }
336:                        if (first == null) {
337:                            if (next == null) {
338:                                first = last;
339:                                last = null;
340:                            } else {
341:                                first = next;
342:                                next = last;
343:                                last = null;
344:                            }
345:                        } else if (next == null) {
346:                            next = last;
347:                            last = null;
348:                        }
349:
350:                        if (last == null) {
351:                            if (next == null && first != null) {
352:                                result = new String[first.length];
353:                                System.arraycopy(first, 0, result, 0,
354:                                        first.length);
355:                            } else if (next != null) {
356:                                result = new String[first.length + next.length];
357:                                System.arraycopy(first, 0, result, 0,
358:                                        first.length);
359:                                System.arraycopy(next, 0, result, first.length,
360:                                        next.length);
361:                            }
362:                        } else {
363:                            result = new String[first.length + next.length
364:                                    + last.length];
365:                            System.arraycopy(first, 0, result, 0, first.length);
366:                            System.arraycopy(next, 0, result, first.length,
367:                                    next.length);
368:                            System.arraycopy(last, 0, result, first.length
369:                                    + next.length, last.length);
370:
371:                        }
372:                        if (result != null) {
373:                            portletParameters.put(key, result);
374:                        }
375:                    }
376:                }
377:                return Collections.unmodifiableMap(portletParameters);
378:
379:            }
380:
381:            public Enumeration getParameterNames() {
382:                return Collections.enumeration(this .getParameterMap().keySet());
383:            }
384:
385:            public String[] getParameterValues(String name) {
386:                return (String[]) this .getParameterMap().get(name);
387:            }
388:
389:            /**
390:             * @see javax.servlet.http.HttpServletRequest#getAttributeNames()
391:             */
392:            public Enumeration getAttributeNames() {
393:                Enumeration attrNames = super .getAttributeNames();
394:
395:                // In parallel mode, adjust attributes by the values of the current thread
396:
397:                if (CurrentWorkerContext.getParallelRenderingMode()) {
398:                    // If cached attributes map is null, it should be re-created.
399:
400:                    if (cachedAttributes == null) {
401:                        HashMap adjustedAttrMap = new HashMap();
402:
403:                        // first, add all attributes of original request.
404:
405:                        while (attrNames.hasMoreElements()) {
406:                            String key = (String) attrNames.nextElement();
407:                            adjustedAttrMap.put(key, super .getAttribute(key));
408:                        }
409:
410:                        // second, add or override all attributes by the current worker context.
411:
412:                        Enumeration cwAttrNames = CurrentWorkerContext
413:                                .getAttributeNames();
414:
415:                        while (cwAttrNames.hasMoreElements()) {
416:                            String key = (String) cwAttrNames.nextElement();
417:                            adjustedAttrMap.put(key, CurrentWorkerContext
418:                                    .getAttribute(key));
419:                        }
420:
421:                        cachedAttributes = Collections
422:                                .unmodifiableMap(adjustedAttrMap);
423:                    }
424:
425:                    attrNames = Collections.enumeration(cachedAttributes
426:                            .keySet());
427:                }
428:
429:                return attrNames;
430:            }
431:
432:            /**
433:             * @see javax.servlet.http.HttpServletRequest#getAttribute(java.lang.String)
434:             */
435:            public Object getAttribute(String name) {
436:                Object value = null;
437:
438:                // In parallel mode, first look up from the worker.
439:
440:                if (CurrentWorkerContext.getParallelRenderingMode()) {
441:                    value = CurrentWorkerContext.getAttribute(name);
442:
443:                    // Because PortletRequestImpl class of pluto encodes the name of attribute before calling setAttribute(), 
444:                    // we have to check the encoded name also.
445:                    if (null == value) {
446:                        // Extra code (2 lines) from Nicolas... not clear to me why this is needed, as "pr" is not used. Commenting out for now...
447:                        //PortletRequest pr = (PortletRequest) super.getAttribute("javax.portlet.request");
448:                        //if (pr != null)
449:                        value = CurrentWorkerContext
450:                                .getAttribute(nameSpaceMapper.encode(
451:                                        portletWindow.getId(), name));
452:                    }
453:                }
454:
455:                // If no attribute found, then look up from the request
456:                if (null == value) {
457:                    value = getAttributeInternal(name);
458:                }
459:
460:                return value;
461:            }
462:
463:            private Object getAttributeInternal(String name) {
464:                Object value = super .getAttribute(name);
465:                if (name.equals(PortletRequest.USER_INFO)) {
466:                    JetspeedRequestContext context = (JetspeedRequestContext) getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
467:                    if (null != context) {
468:                        String entityID = "--NULL--";
469:                        PortletEntity entity = portletWindow.getPortletEntity();
470:                        if (entity != null) {
471:                            entityID = entity.getId().toString();
472:                        }
473:                        PortletApplicationDefinition portletAppDef = entity
474:                                .getPortletDefinition()
475:                                .getPortletApplicationDefinition();
476:
477:                        if (null != portletAppDef) {
478:                            value = context.getUserInfoMap(portletAppDef
479:                                    .getId());
480:                            if (log.isDebugEnabled() && (null != value))
481:                                log.debug(PortletRequest.USER_INFO
482:                                        + " map size: " + ((Map) value).size());
483:                        } else {
484:                            log.error("Entity is null:" + entityID);
485:                        }
486:
487:                    }
488:                } else {
489:                    if (null == value) {
490:                        PortletRequest pr = (PortletRequest) super 
491:                                .getAttribute("javax.portlet.request");
492:                        if (pr != null) {
493:                            value = super .getAttribute(nameSpaceMapper.encode(
494:                                    portletWindow.getId(), name));
495:                        }
496:                    }
497:                }
498:                return value;
499:            }
500:
501:            /**
502:             * @see javax.servlet.ServletRequest#getLocale()
503:             */
504:            public Locale getLocale() {
505:                //Locale preferedLocale = (Locale) getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
506:                RequestContext requestContext = (RequestContext) _getHttpServletRequest()
507:                        .getAttribute(
508:                                PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
509:                Locale preferedLocale = requestContext.getLocale();
510:                if (preferedLocale != null) {
511:                    return preferedLocale;
512:                }
513:
514:                return super .getLocale();
515:            }
516:
517:            /**
518:             * @see javax.servlet.ServletRequest#getLocales()
519:             */
520:            public Enumeration getLocales() {
521:                RequestContext requestContext = (RequestContext) _getHttpServletRequest()
522:                        .getAttribute(
523:                                PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
524:                Locale preferedLocale = requestContext.getLocale();
525:                if (preferedLocale != null) {
526:                    return getLocaleEnum(preferedLocale);
527:                }
528:
529:                return super .getLocales();
530:            }
531:
532:            /**
533:             * <p>
534:             * getLocaleEnum
535:             * </p>
536:             *
537:             * @param preferedLocale
538:             * @return
539:             */
540:            protected Enumeration getLocaleEnum(Locale preferedLocale) {
541:                ArrayList locales = new ArrayList();
542:                locales.add(preferedLocale);
543:                Enumeration localeEnums = super .getLocales();
544:                while (localeEnums.hasMoreElements()) {
545:                    locales.add(localeEnums.nextElement());
546:                }
547:                return new Enumerator(locales);
548:            }
549:
550:            /**
551:             * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
552:             */
553:            public String getHeader(String name) {
554:                if (name.equals(ACCEPT_LANGUAGE)) {
555:                    return getLocale().getLanguage();
556:                } else {
557:                    return super .getHeader(name);
558:                }
559:            }
560:
561:            /**
562:             * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
563:             */
564:            public Enumeration getHeaders(String name) {
565:                if (name.equals(ACCEPT_LANGUAGE)) {
566:                    return getLocaleEnum(getLocale());
567:                } else {
568:                    return super .getHeaders(name);
569:                }
570:
571:            }
572:
573:            /**
574:             * <p>
575:             * setAttribute
576:             * </p>
577:             * 
578:             * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
579:             *      java.lang.Object)
580:             * @param arg0
581:             * @param arg1
582:             */
583:            public void setAttribute(String name, Object value) {
584:                if (name == null) {
585:                    throw new IllegalArgumentException("Attribute name == null");
586:                }
587:
588:                // In parallel mode, put attribute into worker.
589:
590:                if (CurrentWorkerContext.getParallelRenderingMode()) {
591:                    // when it is parallel rendering, the cached request attributes should be re-created later by setting it to null.
592:                    cachedAttributes = null;
593:
594:                    if (null == value) {
595:                        CurrentWorkerContext.removeAttribute(name);
596:                    } else {
597:                        CurrentWorkerContext.setAttribute(name, value);
598:                    }
599:
600:                    if (name.startsWith("org.apache.jetspeed")) {
601:                        setAttributeInternal(name, value);
602:                    }
603:                } else {
604:                    // put attribute into request.
605:                    setAttributeInternal(name, value);
606:                }
607:            }
608:
609:            private void setAttributeInternal(String name, Object value) {
610:                // This allows us to make jetpseed objects avaiable to portlets
611:                // This makes the portlet non-portable but is a must admin portlets
612:                if (name.startsWith("org.apache.jetspeed")) {
613:                    if (value == null) {
614:                        this .removeAttribute(name);
615:                    } else {
616:                        String encodedKey = nameSpaceMapper.encode(
617:                                portletWindow.getId(), name);
618:                        this ._getHttpServletRequest().setAttribute(encodedKey,
619:                                value);
620:                    }
621:                }
622:                super .setAttribute(name, value);
623:            }
624:
625:            /**
626:             * <p>
627:             * removeAttribute
628:             * </p>
629:             * 
630:             * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
631:             * @param arg0
632:             */
633:            public void removeAttribute(String name) {
634:                if (name == null) {
635:                    throw new IllegalArgumentException("Attribute name == null");
636:                }
637:
638:                // In parallel mode, remove attribute from worker.
639:
640:                if (CurrentWorkerContext.getParallelRenderingMode()) {
641:                    // when it is parallel rendering, the cached request attributes should be re-created later by setting it to null.
642:                    cachedAttributes = null;
643:
644:                    CurrentWorkerContext.removeAttribute(name);
645:
646:                    if (name.startsWith("org.apache.jetspeed")) {
647:                        super .removeAttribute(name);
648:                    }
649:                } else {
650:                    // remove attribute from request.
651:                    super .removeAttribute(name);
652:                }
653:            }
654:
655:            /**
656:             * <p>
657:             * getHeaderNames
658:             * </p>
659:             *
660:             * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
661:             * @return
662:             */
663:            public Enumeration getHeaderNames() {
664:                return super .getHeaderNames();
665:            }
666:
667:            /**
668:             * @param included when true, JSR-168 PLT.16.3.3 rules need to be enforced
669:             */
670:            public void setPortletDispatcherIncluded(boolean included) {
671:                this .included = included;
672:            }
673:
674:            /*
675:             * JSR-168 PLT.16.3.3 cxxix
676:             */
677:            public String getProtocol() {
678:                return (included ? null : super .getProtocol());
679:            }
680:
681:            /*
682:             * JSR-168 PLT.16.3.3 cxxix
683:             */
684:            public String getRemoteAddr() {
685:                return (included ? null : super .getRemoteAddr());
686:            }
687:
688:            /*
689:             * JSR-168 PLT.16.3.3 cxxix
690:             */
691:            public String getRemoteHost() {
692:                return (included ? null : super .getRemoteHost());
693:            }
694:
695:            /*
696:             * JSR-168 PLT.16.3.3 cxxix
697:             */
698:            public StringBuffer getRequestURL() {
699:                return (included ? null : super .getRequestURL());
700:            }
701:
702:            /*
703:             * JSR-168 PLT.16.3.3 cxxx
704:             */
705:            public String getPathInfo() {
706:                return (included ? (String) super 
707:                        .getAttribute("javax.servlet.include.path_info")
708:                        : super .getPathInfo());
709:            }
710:
711:            /*
712:             * JSR-168 PLT.16.3.3 cxxx
713:             */
714:            public String getPathTranslated() {
715:                return (included ? null : super .getPathTranslated());
716:            }
717:
718:            /*
719:             * JSR-168 PLT.16.3.3 cxxx
720:             */
721:            public String getQueryString() {
722:                return (included ? (String) super 
723:                        .getAttribute("javax.servlet.include.query_string")
724:                        : super .getQueryString());
725:            }
726:
727:            /*
728:             * JSR-168 PLT.16.3.3 cxxx
729:             */
730:            public String getRequestURI() {
731:                return (included ? (String) super 
732:                        .getAttribute("javax.servlet.include.request_uri")
733:                        : super .getRequestURI());
734:            }
735:
736:            /*
737:             * JSR-168 PLT.16.3.3 cxxx
738:             */
739:            public String getServletPath() {
740:                return (included ? (String) super 
741:                        .getAttribute("javax.servlet.include.servlet_path")
742:                        : super .getServletPath());
743:            }
744:
745:            /*
746:             * JSR-168 PLT.16.3.3 cxxxi
747:             */
748:            public String getContextPath() {
749:                return (included ? (String) super 
750:                        .getAttribute("javax.servlet.include.context_path")
751:                        : super .getContextPath());
752:            }
753:
754:            /*
755:             * JSR-168 PLT.16.3.3 cxxxiv
756:             */
757:            public int getContentLength() {
758:                return (included ? 0 : super .getContentLength());
759:            }
760:
761:            /*
762:             * JSR-168 PLT.16.3.3 cxxix
763:             */
764:            public String getRealPath(String arg0) {
765:                return (included ? null : super .getRealPath(arg0));
766:            }
767:
768:            /*
769:             * JSR-168 PLT.16.3.3 cxxxii
770:             */
771:            public BufferedReader getReader() throws IOException {
772:                return (included ? null : super .getReader());
773:            }
774:
775:            /*
776:             * JSR-168 PLT.16.3.3 cxxxii
777:             */
778:            public String getCharacterEncoding() {
779:                return (included ? null : super .getCharacterEncoding());
780:            }
781:
782:            /*
783:             * JSR-168 PLT.16.3.3 cxxxii
784:             */
785:            public String getContentType() {
786:                return (included ? null : super .getContentType());
787:            }
788:
789:            /*
790:             * JSR-168 PLT.16.3.3 cxxxii
791:             */
792:            public ServletInputStream getInputStream() throws IOException {
793:                return (included ? null : super .getInputStream());
794:            }
795:
796:            /*
797:             * JSR-168 PLT.16.3.3 cxxxii
798:             */
799:            public void setCharacterEncoding(String arg0)
800:                    throws UnsupportedEncodingException {
801:                if (!included) {
802:                    super.setCharacterEncoding(arg0);
803:                }
804:            }
805:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.