Coverage report

  %line %branch
org.apache.jetspeed.engine.servlet.ServletRequestImpl
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.engine.servlet;
 18  
 
 19  
 import java.io.BufferedReader;
 20  
 import java.io.IOException;
 21  
 import java.io.UnsupportedEncodingException;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Collection;
 24  
 import java.util.Collections;
 25  
 import java.util.Enumeration;
 26  
 import java.util.HashMap;
 27  
 import java.util.HashSet;
 28  
 import java.util.Iterator;
 29  
 import java.util.Locale;
 30  
 import java.util.Map;
 31  
 
 32  
 import javax.portlet.PortletRequest;
 33  
 import javax.servlet.ServletInputStream;
 34  
 import javax.servlet.ServletRequest;
 35  
 import javax.servlet.http.HttpServletRequest;
 36  
 import javax.servlet.http.HttpServletRequestWrapper;
 37  
 
 38  
 import org.apache.commons.logging.Log;
 39  
 import org.apache.commons.logging.LogFactory;
 40  
 import org.apache.jetspeed.Jetspeed;
 41  
 import org.apache.jetspeed.PortalReservedParameters;
 42  
 import org.apache.jetspeed.aggregator.CurrentWorkerContext;
 43  
 import org.apache.jetspeed.aggregator.Worker;
 44  
 import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
 45  
 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapper;
 46  
 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapperFactory;
 47  
 import org.apache.jetspeed.container.url.PortalURL;
 48  
 import org.apache.jetspeed.om.common.GenericMetadata;
 49  
 import org.apache.jetspeed.om.common.LocalizedField;
 50  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 51  
 import org.apache.jetspeed.request.JetspeedRequestContext;
 52  
 import org.apache.jetspeed.request.RequestContext;
 53  
 import org.apache.pluto.om.entity.PortletEntity;
 54  
 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
 55  
 import org.apache.pluto.om.window.PortletWindow;
 56  
 import org.apache.pluto.util.Enumerator;
 57  
 
 58  
 /**
 59  
  * This request wrappers the servlet request and is used within the container to
 60  
  * communicate to the invoked servlet.
 61  
  * 
 62  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 63  
  * @version $Id: ServletRequestImpl.java 554827 2007-07-10 05:12:23Z taylor $
 64  
  */
 65  
 public class ServletRequestImpl extends HttpServletRequestWrapper implements PortletDispatcherIncludeAware
 66  
 {
 67  
     public static final String ACCEPT_LANGUAGE = "Accept-Language";
 68  
     /** Logger */
 69  0
     private static final Log log = LogFactory.getLog(ServletRequestImpl.class);
 70  
 
 71  0
     PortletWindow portletWindow = null;
 72  0
     private JetspeedNamespaceMapper nameSpaceMapper = null;
 73  0
     private ServletRequest currentRequest = null;
 74  
 
 75  
     private Map portletParameters;
 76  
     
 77  
     private boolean included;
 78  
 
 79  
     private static Boolean mergePortalParametersWithPortletParameters;
 80  
     private static Boolean mergePortalParametersBeforePortletParameters;
 81  
     
 82  
     private boolean portletMergePortalParametersWithPortletParameters;
 83  
     private boolean portletMergePortalParametersBeforePortletParameters;
 84  
     
 85  
     private Map portalParameters;
 86  
     
 87  
     private String currentIncludeQueryString;    
 88  
     private String currentForwardQueryString;    
 89  
     
 90  
     // request attributes map which is cached for each paralleled worker.
 91  
     // this should be re-created when it is called for the first time or when some attributes are added/modified/removed.
 92  
     private Map cachedAttributes;
 93  
 
 94  
     public ServletRequestImpl( HttpServletRequest servletRequest, PortletWindow window )
 95  
     {
 96  0
         super(servletRequest);
 97  0
         nameSpaceMapper = ((JetspeedNamespaceMapperFactory) Jetspeed.getComponentManager().getComponent(
 98  
                 org.apache.pluto.util.NamespaceMapper.class)).getJetspeedNamespaceMapper();
 99  0
         this.portletWindow = window;        
 100  
         
 101  
         
 102  0
         String encoding = (String) servletRequest.getAttribute(PortalReservedParameters.PREFERED_CHARACTERENCODING_ATTRIBUTE);
 103  0
         boolean decode = servletRequest.getAttribute(PortalReservedParameters.PARAMETER_ALREADY_DECODED_ATTRIBUTE) == null
 104  
                 && encoding != null;
 105  0
         if (decode)
 106  
         {
 107  0
             servletRequest.setAttribute(PortalReservedParameters.PARAMETER_ALREADY_DECODED_ATTRIBUTE,
 108  
                     new Boolean(true));
 109  
         }
 110  
 
 111  
         //get portal servlet params
 112  0
         portalParameters = new HashMap();
 113  0
         for (Enumeration parameters = servletRequest.getParameterNames(); parameters.hasMoreElements();)
 114  
         {
 115  0
             String paramName = (String) parameters.nextElement();
 116  0
             String[] paramValues = servletRequest.getParameterValues(paramName);
 117  
 
 118  0
             if (decode)
 119  
             {
 120  0
                 for (int i = 0; i < paramValues.length; i++)
 121  
                 {
 122  
                     try
 123  
                     {
 124  0
                         paramValues[i] = new String(paramValues[i].getBytes("ISO-8859-1"), encoding);
 125  
                     }
 126  0
                     catch (UnsupportedEncodingException e)
 127  
                     {
 128  
                         ;
 129  0
                     }
 130  
                 }
 131  
             }
 132  0
             portalParameters.put(paramName, paramValues);
 133  0
         }
 134  
         
 135  0
         if (mergePortalParametersWithPortletParameters == null )
 136  
         {
 137  0
             mergePortalParametersWithPortletParameters = 
 138  
                 new Boolean(Jetspeed.getContext().getConfiguration().getBoolean("merge.portal.parameters.with.portlet.parameters", false));
 139  0
             mergePortalParametersBeforePortletParameters = 
 140  
                 new Boolean(Jetspeed.getContext().getConfiguration().getBoolean("merge.portal.parameters.before.portlet.parameters", false));
 141  
         }
 142  
                 
 143  
         
 144  0
         PortletDefinitionComposite portletDef = (PortletDefinitionComposite)portletWindow.getPortletEntity().getPortletDefinition();
 145  0
         if(portletDef != null)
 146  
         {
 147  0
             GenericMetadata metaData = portletDef.getMetadata();
 148  
 
 149  0
             portletMergePortalParametersWithPortletParameters = 
 150  
                 getMetaDataBooleanValue(
 151  
                     metaData,
 152  
                     PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_MERGE_PORTAL_PARAMETERS_WITH_PORTLET_PARAMETERS,
 153  
                     mergePortalParametersWithPortletParameters.booleanValue());
 154  0
             portletMergePortalParametersBeforePortletParameters = 
 155  
                 getMetaDataBooleanValue(
 156  
                     metaData,
 157  
                     PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_MERGE_PORTAL_PARAMETERS_BEFORE_PORTLET_PARAMETERS,
 158  
                     mergePortalParametersBeforePortletParameters.booleanValue());
 159  
             
 160  0
         }
 161  
         else
 162  
         {
 163  
             // This happens when an entity is referencing a non-existent portlet
 164  0
             portletMergePortalParametersWithPortletParameters = mergePortalParametersWithPortletParameters.booleanValue();
 165  0
             portletMergePortalParametersBeforePortletParameters = mergePortalParametersBeforePortletParameters.booleanValue();
 166  
         }
 167  0
     }
 168  
     
 169  
     private boolean getMetaDataBooleanValue(GenericMetadata metaData, String fieldName, class="keyword">boolean defaultValue )
 170  
     {
 171  0
         String value = null;
 172  0
         if ( metaData != null )
 173  
         {
 174  0
             Collection fields = metaData.getFields(fieldName);
 175  0
             if ( fields != null && !fields.isEmpty() )
 176  
             {
 177  0
                 value = ((LocalizedField)fields.iterator().next()).getValue();
 178  
             }
 179  
         }
 180  0
         if ( value != null )
 181  
         {
 182  0
             return Boolean.valueOf(value).booleanValue();
 183  
         }
 184  0
         return defaultValue;
 185  
     }
 186  
 
 187  
     protected HttpServletRequest _getHttpServletRequest()
 188  
     {
 189  0
         return (HttpServletRequest) super.getRequest();
 190  
     }
 191  
 
 192  
     //  ServletRequestWrapper overlay
 193  
 
 194  
     public String getParameter( String name )
 195  
     {
 196  0
         Object value = this.getParameterMap().get(name);
 197  0
         if (value == null)
 198  
         {
 199  0
             return (null);
 200  
         }
 201  0
         else if (value instanceof String[])
 202  
         {
 203  0
             return (((String[]) value)[0]);
 204  
         }
 205  0
         else if (value instanceof String)
 206  
         {
 207  0
             return ((String) value);
 208  
         }
 209  
         else
 210  
         {
 211  0
             return (value.toString());
 212  
         }
 213  
     }
 214  
     
 215  
     private boolean isEqual(String one, String two)
 216  
     {
 217  0
         return (one == null && two == class="keyword">null) || (one != class="keyword">null && two != class="keyword">null && one.equals(two));
 218  
     }
 219  
     
 220  
     private boolean checkQueryStringChanged()
 221  
     {
 222  0
         boolean changed = false;
 223  0
         ServletRequest request = getRequest();
 224  0
         String includeQueryString = (String)request.getAttribute("javax.servlet.include.query_string");        
 225  0
         String forwardQueryString = (String)request.getAttribute("javax.servlet.forward.query_string");
 226  
         
 227  0
         if (!isEqual(currentIncludeQueryString,includeQueryString))
 228  
         {
 229  0
             currentIncludeQueryString = includeQueryString;
 230  0
             changed = true;
 231  
         }
 232  0
         if (!isEqual(currentForwardQueryString,forwardQueryString))
 233  
         {
 234  0
             currentForwardQueryString = forwardQueryString;
 235  0
             changed = true;
 236  
         }        
 237  0
         return changed;
 238  
     }
 239  
 
 240  
     public Map getParameterMap()
 241  
     {
 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  0
         boolean queryStringChanged = checkQueryStringChanged();
 247  
         
 248  0
         if (queryStringChanged || currentRequest == null || currentRequest != getRequest() )
 249  
         {
 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  0
             currentRequest = getRequest();
 258  
 
 259  0
             boolean actionRequest = 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  0
             HashMap queryParameters = new HashMap();
 265  0
             for ( Iterator iter = getRequest().getParameterMap().entrySet().iterator(); iter.hasNext(); )
 266  
             {
 267  0
                 Map.Entry entry = (Map.Entry)iter.next();
 268  0
                 String[] values = (String[])entry.getValue();
 269  0
                 String[] original = (String[])portalParameters.get(entry.getKey());
 270  0
                 String[] diff = null;
 271  0
                 if ( original == null )
 272  
                 {
 273  
                     // a new parameter
 274  0
                     diff = new String[values.length];
 275  0
                     System.arraycopy(values,0,diff,0,values.length);
 276  
                 }
 277  0
                 else if ( values.length > original.length )
 278  
                 {
 279  
                     // we've got some additional query string parameter value(s)
 280  0
                     diff = new String[values.length - original.length];
 281  0
                     System.arraycopy(values,0,diff,0,values.length-original.length);
 282  
                 }
 283  0
                 if ( dclass="keyword">iff != null )
 284  
                 {
 285  0
                     queryParameters.put(entry.getKey(), diff);
 286  
                 }
 287  0
             }
 288  
 
 289  
             // get portlet navigational params
 290  0
             HashMap navParameters = new HashMap();
 291  0
             JetspeedRequestContext context = (JetspeedRequestContext) getAttribute("org.apache.jetspeed.request.RequestContext");
 292  0
             if (context != null)
 293  
             {
 294  0
                 PortalURL url = context.getPortalURL();
 295  0
                 actionRequest = context.getActionWindow() != null;
 296  0
                 Iterator iter = url.getNavigationalState().getParameterNames(portletWindow);
 297  0
                 while (iter.hasNext())
 298  
                 {
 299  0
                     String name = (String) iter.next();
 300  0
                     String[] values = url.getNavigationalState().getParameterValues(portletWindow, name);
 301  0
                     navParameters.put(name, values);
 302  0
                 }
 303  
             }
 304  
             
 305  
             // now first merge the keys we have into one unique set
 306  0
             HashSet keys = new HashSet();
 307  0
             keys.addAll(portalParameters.keySet());
 308  0
             keys.addAll(queryParameters.keySet());
 309  0
             keys.addAll(navParameters.keySet());
 310  
             
 311  
             // now "merge" the parameters
 312  
             // there are three different options:
 313  
             // 1) query parameters + nav parameters:
 314  
             //        portletMergePortalParametersWithPortletParameters == false && !actionRequest
 315  
             // 2) query parameters + nav parameters + portal parameters
 316  
             //           portletMergePortalParametersWithPortletParameters == true || actionRequest
 317  
             //        && portletMergePortalParametersBeforePortletParameters == false
 318  
             // 3) query parameters + portal parameters + nav parameters (odd use-case but provided because this was the "old" pre-2.1 behavior
 319  
             //           portletMergePortalParametersWithPortletParameters == true || actionRequest
 320  
             //        && portletMergePortalParametersBeforePortletParameters == true
 321  0
             portletParameters = new HashMap();
 322  0
             for ( Iterator iter = keys.iterator(); iter.hasNext(); )
 323  
             {
 324  0
                 String key = (String)iter.next();
 325  0
                 String[] first = (String[])queryParameters.get(key);
 326  0
                 String[] next = null, last = class="keyword">null, result = class="keyword">null;
 327  
                 
 328  0
                 if ( portletMergePortalParametersWithPortletParameters == false && !actionRequest )
 329  
                 {
 330  0
                     next = (String[])navParameters.get(key);
 331  
                 }
 332  0
                 else if ( portletMergePortalParametersBeforePortletParameters )
 333  
                 {
 334  0
                     next = (String[])portalParameters.get(key);
 335  0
                     last = (String[])navParameters.get(key);
 336  
                 }
 337  
                 else
 338  
                 {
 339  0
                     next = (String[])navParameters.get(key);
 340  0
                     last = (String[])portalParameters.get(key);
 341  
                 }
 342  0
                 if ( first == null )
 343  
                 {
 344  0
                     if ( next == null )
 345  
                     {
 346  0
                         first = last;
 347  0
                         last = null;
 348  
                     }
 349  
                     else
 350  
                     {
 351  0
                         first = next;
 352  0
                         next = last;
 353  0
                         last = null;
 354  
                     }
 355  
                 }
 356  0
                 else if ( next == null )
 357  
                 {
 358  0
                     next = last;
 359  0
                     last = null;
 360  
                 }
 361  
                 
 362  0
                 if ( last == null )
 363  
                 {
 364  0
                     if ( next == null && first != class="keyword">null )
 365  
                     {
 366  0
                         result = new String[first.length];
 367  0
                         System.arraycopy(first,0,result,0,first.length);
 368  
                     }
 369  0
                     else if (next != null )
 370  
                     {
 371  0
                         result = new String[first.length + next.length];
 372  0
                         System.arraycopy(first,0,result,0,first.length);
 373  0
                         System.arraycopy(next,0,result,first.length,next.length);
 374  
                     }
 375  
                 }
 376  
                 else
 377  
                 {
 378  0
                     result = new String[first.length + next.length + last.length];
 379  0
                     System.arraycopy(first,0,result,0,first.length);
 380  0
                     System.arraycopy(next,0,result,first.length,next.length);
 381  0
                     System.arraycopy(last,0,result,first.length+next.length,last.length);
 382  
                     
 383  
                 }
 384  0
                 if ( result != null )
 385  
                 {
 386  0
                     portletParameters.put(key, result);
 387  
                 }
 388  0
             }
 389  
         }
 390  0
         return Collections.unmodifiableMap(portletParameters);
 391  
 
 392  
     }
 393  
 
 394  
     public Enumeration getParameterNames()
 395  
     {
 396  0
         return Collections.enumeration(this.getParameterMap().keySet());
 397  
     }
 398  
 
 399  
     public String[] getParameterValues( String name )
 400  
     {
 401  0
         return (String[]) this.getParameterMap().get(name);
 402  
     }
 403  
 
 404  
     /**
 405  
      * @see javax.servlet.http.HttpServletRequest#getAttributeNames()
 406  
      */
 407  
     public Enumeration getAttributeNames()
 408  
     {
 409  0
         Enumeration attrNames = super.getAttributeNames();
 410  
         
 411  
         // In parallel mode, adjust attributes by the values of the current thread
 412  0
         Thread ct = Thread.currentThread();
 413  
 
 414  0
         if (ct instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed())
 415  
         {
 416  
             // If cached attributes map is null, it should be re-created.
 417  
             
 418  0
             if (cachedAttributes == null)
 419  
             {
 420  0
                 HashMap adjustedAttrMap = new HashMap();
 421  
                 
 422  
                 // first, add all attributes of original request.
 423  
                 
 424  0
                 while (attrNames.hasMoreElements())
 425  
                 {
 426  0
                     String key = (String) attrNames.nextElement();
 427  0
                     adjustedAttrMap.put(key, super.getAttribute(key));
 428  0
                 }
 429  
                 
 430  
                 // second, add or override all attributes by the current worker context.
 431  
                 
 432  0
                 Enumeration cwAttrNames = CurrentWorkerContext.getAttributeNames();
 433  
                 
 434  0
                 while (cwAttrNames.hasMoreElements())
 435  
                 {
 436  0
                     String key = (String) cwAttrNames.nextElement();
 437  0
                     adjustedAttrMap.put(key, CurrentWorkerContext.getAttribute(key));
 438  0
                 }
 439  
                 
 440  0
                 cachedAttributes = Collections.unmodifiableMap(adjustedAttrMap);
 441  
             }
 442  
             
 443  0
             attrNames = Collections.enumeration(cachedAttributes.keySet());
 444  
         }
 445  
         
 446  0
         return attrNames;
 447  
     }
 448  
     
 449  
     /**
 450  
      * @see javax.servlet.http.HttpServletRequest#getAttribute(java.lang.String)
 451  
      */
 452  
     public Object getAttribute( String name )
 453  
     {
 454  0
         Object value = null;
 455  
 
 456  
         // In parallel mode, first look up from the worker.
 457  
 
 458  0
         Thread ct = Thread.currentThread();
 459  
 
 460  0
         if (ct instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed())
 461  
         {            
 462  0
             value = CurrentWorkerContext.getAttribute(name);
 463  
 
 464  
             // Because PortletRequestImpl class of pluto encodes the name of attribute before calling setAttribute(), 
 465  
             // we have to check the encoded name also.
 466  0
             if (null == value)
 467  
             {
 468  
                 // Extra code (2 lines) from Nicolas... not clear to me why this is needed, as "pr" is not used. Commenting out for now...
 469  
                 //PortletRequest pr = (PortletRequest) super.getAttribute("javax.portlet.request");
 470  
                 //if (pr != null)
 471  0
                 value = CurrentWorkerContext.getAttribute(nameSpaceMapper.encode(portletWindow.getId(), name));
 472  
             }
 473  
         }
 474  
 
 475  
         // If no attribute found, then look up from the request
 476  0
         if (null == value) 
 477  
         {
 478  0
             value = getAttributeInternal(name);
 479  
         }
 480  
 
 481  0
         return value;
 482  
     }
 483  
 
 484  
     private Object getAttributeInternal( String name )
 485  
     {
 486  0
         Object value = super.getAttribute(name);
 487  0
         if (name.equals(PortletRequest.USER_INFO))
 488  
         {
 489  0
             JetspeedRequestContext context = (JetspeedRequestContext) getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
 490  0
             if (null != context)
 491  
             {
 492  0
                 String entityID = "--NULL--";
 493  0
                 PortletEntity entity = portletWindow.getPortletEntity();
 494  0
                 if (entity != null)
 495  
                 {
 496  0
                     entityID = entity.getId().toString();
 497  
                 }
 498  0
                 PortletApplicationDefinition portletAppDef = entity.getPortletDefinition()
 499  
                         .getPortletApplicationDefinition();
 500  
 
 501  0
                 if (null != portletAppDef)
 502  
                 {
 503  0
                     value = context.getUserInfoMap(portletAppDef.getId());
 504  0
                     if (log.isDebugEnabled() && (null != value))
 505  0
                         log.debug(PortletRequest.USER_INFO + " map size: " + ((Map) value).size());
 506  
                 }
 507  
                 else
 508  
                 {
 509  0
                     log.error("Entity is null:" + entityID);
 510  
                 }
 511  
 
 512  
             }
 513  0
         }
 514  
         else
 515  
         {
 516  0
             if (null == value)
 517  
             {
 518  0
                 PortletRequest pr = (PortletRequest) super.getAttribute("javax.portlet.request");
 519  0
                 if (pr != null)
 520  
                 {
 521  0
                     value = super.getAttribute(nameSpaceMapper.encode(portletWindow.getId(),
 522  
                             name));
 523  
                 }
 524  
             }
 525  
         }
 526  0
         return value;
 527  
     }
 528  
 
 529  
     /**
 530  
      * @see javax.servlet.ServletRequest#getLocale()
 531  
      */
 532  
     public Locale getLocale()
 533  
     {
 534  
         //Locale preferedLocale = (Locale) getSession().getAttribute(RequestContext.PREFERED_LOCALE_SESSION_KEY);
 535  0
         RequestContext requestContext = (RequestContext) _getHttpServletRequest().getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
 536  0
         Locale preferedLocale = requestContext.getLocale();
 537  0
         if (preferedLocale != null)
 538  
         {
 539  0
             return preferedLocale;
 540  
         }
 541  
 
 542  0
         return super.getLocale();
 543  
     }
 544  
 
 545  
     /**
 546  
      * @see javax.servlet.ServletRequest#getLocales()
 547  
      */
 548  
     public Enumeration getLocales()
 549  
     {
 550  0
         RequestContext requestContext = (RequestContext) _getHttpServletRequest().getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
 551  0
         Locale preferedLocale = requestContext.getLocale();
 552  0
         if (preferedLocale != null)
 553  
         {
 554  0
             return getLocaleEnum(preferedLocale);
 555  
         }
 556  
 
 557  0
         return super.getLocales();
 558  
     }
 559  
 
 560  
     /**
 561  
      * <p>
 562  
      * getLocaleEnum
 563  
      * </p>
 564  
      *
 565  
      * @param preferedLocale
 566  
      * @return
 567  
      */
 568  
     protected Enumeration getLocaleEnum( Locale preferedLocale )
 569  
     {
 570  0
         ArrayList locales = new ArrayList();
 571  0
         locales.add(preferedLocale);
 572  0
         Enumeration localeEnums = super.getLocales();
 573  0
         while (localeEnums.hasMoreElements())
 574  
         {
 575  0
             locales.add(localeEnums.nextElement());
 576  
         }
 577  0
         return new Enumerator(locales);
 578  
     }
 579  
 
 580  
     /**
 581  
      * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
 582  
      */
 583  
     public String getHeader( String name )
 584  
     {
 585  0
         if(name.equals(ACCEPT_LANGUAGE))
 586  
         {
 587  0
             return getLocale().getLanguage();   
 588  
         }
 589  
         else
 590  
         {
 591  0
             return super.getHeader(name);
 592  
         }
 593  
     }
 594  
 
 595  
     /**
 596  
      * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
 597  
      */
 598  
     public Enumeration getHeaders( String name )
 599  
     {
 600  0
         if(name.equals(ACCEPT_LANGUAGE))
 601  
         {      
 602  0
             return getLocaleEnum(getLocale());         
 603  
         }
 604  
         else
 605  
         {
 606  0
             return super.getHeaders(name);
 607  
         }        
 608  
 
 609  
     }
 610  
 
 611  
     /**
 612  
      * <p>
 613  
      * setAttribute
 614  
      * </p>
 615  
      * 
 616  
      * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
 617  
      *      java.lang.Object)
 618  
      * @param arg0
 619  
      * @param arg1
 620  
      */
 621  
     public void setAttribute( String name, Object value )
 622  
     {
 623  0
         if (name == null)
 624  
         {
 625  0
             throw new IllegalArgumentException("Attribute name == null");
 626  
         }
 627  
         
 628  
         // In parallel mode, put attribute into worker.
 629  
 
 630  0
         Thread ct = Thread.currentThread();
 631  0
         boolean currentWorkerContextUsed = CurrentWorkerContext.getCurrentWorkerContextUsed();
 632  
 
 633  0
         if (ct instanceof Worker || currentWorkerContextUsed) 
 634  
         {
 635  
             // when it is parallel rendering, the cached request attributes should be re-created later by setting it to null.
 636  0
             cachedAttributes = null;
 637  
             
 638  0
             if (null == value) 
 639  
             {
 640  0
                 CurrentWorkerContext.removeAttribute(name);
 641  
             } 
 642  
             else 
 643  
             {
 644  0
                 CurrentWorkerContext.setAttribute(name, value);
 645  
             }
 646  
 
 647  0
             if (currentWorkerContextUsed || name.startsWith("org.apache.jetspeed"))
 648  
             {
 649  0
                 setAttributeInternal(name, value);
 650  
             }
 651  
         }
 652  
         else
 653  
         {
 654  
             // put attribute into request.
 655  0
             setAttributeInternal(name, value);
 656  
         }
 657  0
     }
 658  
 
 659  
     private void setAttributeInternal( String name, Object value )
 660  
     {
 661  
         // This allows us to make jetpseed objects avaiable to portlets
 662  
         // This makes the portlet non-portable but is a must admin portlets
 663  0
         if (name.startsWith("org.apache.jetspeed"))
 664  
         {
 665  0
             if (value == null)
 666  
             {
 667  0
                 this.removeAttribute(name);
 668  
             }
 669  
             else
 670  
             {
 671  0
                 String encodedKey = nameSpaceMapper.encode(portletWindow.getId(), name);
 672  0
                 this._getHttpServletRequest().setAttribute(
 673  
                         encodedKey, value);
 674  
             }
 675  
         }
 676  0
         super.setAttribute(name, value);
 677  0
     }
 678  
 
 679  
     /**
 680  
      * <p>
 681  
      * removeAttribute
 682  
      * </p>
 683  
      * 
 684  
      * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
 685  
      * @param arg0
 686  
      */
 687  
     public void removeAttribute( String name )
 688  
     {
 689  0
         if (name == null)
 690  
         {
 691  0
             throw new IllegalArgumentException("Attribute name == null");
 692  
         }
 693  
         
 694  
         // In parallel mode, remove attribute from worker.
 695  
 
 696  0
         Thread ct = Thread.currentThread();
 697  
 
 698  0
         if (ct instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed()) 
 699  
         {
 700  
             // when it is parallel rendering, the cached request attributes should be re-created later by setting it to null.
 701  0
             cachedAttributes = null;
 702  
             
 703  0
             CurrentWorkerContext.removeAttribute(name);
 704  
             
 705  0
             if (name.startsWith("org.apache.jetspeed")) {
 706  0
                 super.removeAttribute(name);
 707  
             }
 708  
         }
 709  
         else
 710  
         {
 711  
             // remove attribute from request.
 712  0
             super.removeAttribute(name);
 713  
         }        
 714  0
     }
 715  
 
 716  
     /**
 717  
      * <p>
 718  
      * getHeaderNames
 719  
      * </p>
 720  
      *
 721  
      * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
 722  
      * @return
 723  
      */
 724  
     public Enumeration getHeaderNames()
 725  
     {
 726  0
         return super.getHeaderNames();
 727  
     }
 728  
     
 729  
     /**
 730  
      * @param included when true, JSR-168 PLT.16.3.3 rules need to be enforced
 731  
      */
 732  
     public void setPortletDispatcherIncluded(boolean included)
 733  
     {
 734  0
         this.included = included;
 735  0
     }
 736  
     
 737  
     /*
 738  
      * JSR-168 PLT.16.3.3 cxxix
 739  
      */
 740  
   	public String getProtocol()
 741  
   	{
 742  0
         return (included ? null : super.getProtocol() );
 743  
   	}
 744  
 
 745  
     /*
 746  
      * JSR-168 PLT.16.3.3 cxxix
 747  
      */
 748  
   	public String getRemoteAddr()
 749  
   	{
 750  0
         return (included ? null : super.getRemoteAddr() );
 751  
   	}
 752  
 
 753  
     /*
 754  
      * JSR-168 PLT.16.3.3 cxxix
 755  
      */
 756  
   	public String getRemoteHost()
 757  
   	{
 758  0
         return (included ? null : super.getRemoteHost() );
 759  
   	}
 760  
 
 761  
     /*
 762  
      * JSR-168 PLT.16.3.3 cxxix
 763  
      */
 764  
   	public StringBuffer getRequestURL()
 765  
   	{
 766  0
         return (included ? null : super.getRequestURL());
 767  
   	}
 768  
 
 769  
     /*
 770  
      * JSR-168 PLT.16.3.3 cxxx
 771  
      */
 772  
     public String getPathInfo()
 773  
   	{
 774  0
         return (included ? (String)super.getAttribute("javax.servlet.include.path_info") : super.getPathInfo());
 775  
   	}
 776  
 
 777  
     /*
 778  
      * JSR-168 PLT.16.3.3 cxxx
 779  
      */
 780  
   	public String getPathTranslated()
 781  
   	{
 782  0
         return (included ? null : super.getPathTranslated());
 783  
   	}
 784  
 
 785  
     /*
 786  
      * JSR-168 PLT.16.3.3 cxxx
 787  
      */
 788  
   	public String getQueryString()
 789  
   	{
 790  0
         return (included ? (String)super.getAttribute("javax.servlet.include.query_string") : super.getQueryString());
 791  
   	}
 792  
 
 793  
     /*
 794  
      * JSR-168 PLT.16.3.3 cxxx
 795  
      */
 796  
   	public String getRequestURI()
 797  
   	{
 798  0
         return (included ? (String)super.getAttribute("javax.servlet.include.request_uri") : super.getRequestURI());
 799  
   	}
 800  
 
 801  
     /*
 802  
      * JSR-168 PLT.16.3.3 cxxx
 803  
      */
 804  
   	public String getServletPath()
 805  
   	{
 806  0
         return (included ? (String)super.getAttribute("javax.servlet.include.servlet_path") : super.getServletPath());
 807  
   	}
 808  
 
 809  
     /*
 810  
      * JSR-168 PLT.16.3.3 cxxxi
 811  
      */
 812  
   	public String getContextPath() 
 813  
   	{
 814  0
         return (included ? (String)super.getAttribute("javax.servlet.include.context_path") : super.getContextPath());
 815  
   	}
 816  
 
 817  
     /*
 818  
      * JSR-168 PLT.16.3.3 cxxxiv
 819  
      */
 820  
     public int getContentLength()
 821  
     {
 822  0
         return (included ? 0 : super.getContentLength());
 823  
     }
 824  
 
 825  
     /*
 826  
      * JSR-168 PLT.16.3.3 cxxix
 827  
      */
 828  
     public String getRealPath(String arg0)
 829  
     {
 830  0
         return (included ? null : super.getRealPath(arg0));
 831  
     }
 832  
 
 833  
     /*
 834  
      * JSR-168 PLT.16.3.3 cxxxii
 835  
      */
 836  
     public BufferedReader getReader() throws IOException
 837  
     {
 838  0
         return (included ? null : super.getReader());
 839  
     }
 840  
 
 841  
     /*
 842  
      * JSR-168 PLT.16.3.3 cxxxii
 843  
      */
 844  
     public String getCharacterEncoding()
 845  
     {
 846  0
         return (included ? null : super.getCharacterEncoding());
 847  
     }
 848  
 
 849  
     /*
 850  
      * JSR-168 PLT.16.3.3 cxxxii
 851  
      */
 852  
     public String getContentType()
 853  
     {
 854  0
         return (included ? null : super.getContentType());
 855  
     }
 856  
 
 857  
     /*
 858  
      * JSR-168 PLT.16.3.3 cxxxii
 859  
      */
 860  
     public ServletInputStream getInputStream() throws IOException
 861  
     {
 862  0
         return (included ? null : super.getInputStream());
 863  
     }
 864  
 
 865  
     /*
 866  
      * JSR-168 PLT.16.3.3 cxxxii
 867  
      */
 868  
     public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
 869  
     {
 870  0
         if ( !included )
 871  
         {
 872  0
             super.setCharacterEncoding(arg0);
 873  
         }
 874  0
     }
 875  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.