Coverage report

  %line %branch
org.apache.commons.configuration.web.ServletRequestConfiguration
100% 
100% 

 1  
 /*
 2  
  * Copyright 2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.configuration.web;
 18  
 
 19  
 import java.util.Iterator;
 20  
 import java.util.Arrays;
 21  
 import javax.servlet.ServletRequest;
 22  
 
 23  
 import org.apache.commons.collections.iterators.EnumerationIterator;
 24  
 import org.apache.commons.configuration.AbstractConfiguration;
 25  
 
 26  
 /**
 27  
  * A configuration wrapper to read the parameters of a servlet request. This
 28  
  * configuration is read only, adding or removing a property will throw an
 29  
  * UnsupportedOperationException.
 30  
  *
 31  
  * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
 32  
  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
 33  
  * @since 1.1
 34  
  */
 35  
 public class ServletRequestConfiguration extends AbstractConfiguration
 36  
 {
 37  
     protected ServletRequest request;
 38  
 
 39  
     /**
 40  
      * Create a ServletRequestConfiguration using the request parameters.
 41  
      *
 42  
      * @param request the servlet request
 43  
      */
 44  72
     public ServletRequestConfiguration(ServletRequest request)
 45  184
     {
 46  184
         this.request = request;
 47  112
     }
 48  
 
 49  
     public Object getProperty(String key)
 50  45
     {
 51  98
         String values[] = request.getParameterValues(key);
 52  
 
 53  98
         if (values == null || values.length == 0)
 54  
         {
 55  28
             return null;
 56  
         }
 57  70
         else if (values.length == 1)
 58  
         {
 59  42
             return values[0];
 60  
         }
 61  9
         else
 62  
         {
 63  28
             return Arrays.asList(values);
 64  
         }
 65  
     }
 66  18
 
 67  
     /**
 68  
      * <p><strong>This operation is not supported and will throw an
 69  
      * UnsupportedOperationException.</strong></p>
 70  
      *
 71  18
      * @throws UnsupportedOperationException
 72  
      */
 73  
     protected void addPropertyDirect(String key, Object obj)
 74  
     {
 75  14
         throw new UnsupportedOperationException("Read only configuration");
 76  
     }
 77  
 
 78  
     public boolean isEmpty()
 79  
     {
 80  28
         return !getKeys().hasNext();
 81  
     }
 82  9
 
 83  
     public boolean containsKey(String key)
 84  
     {
 85  28
         return getProperty(key) != null;
 86  
     }
 87  36
 
 88  
     /**
 89  
      * <p><strong>This operation is not supported and will throw an
 90  
      * UnsupportedOperationException.</strong></p>
 91  
      *
 92  
      * @throws UnsupportedOperationException
 93  
      */
 94  
     public void clearProperty(String key)
 95  
     {
 96  14
         throw new UnsupportedOperationException("Read only configuration");
 97  
     }
 98  
 
 99  
     public Iterator getKeys()
 100  
     {
 101  42
         return new EnumerationIterator(request.getParameterNames());
 102  
     }
 103  
 }

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