Coverage Report - org.apache.tapestry.web.ServletWebContext
 
Classes in this File Line Coverage Branch Coverage Complexity
ServletWebContext
0%
0/23
0%
0/2
1.25
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.web;
 16  
 
 17  
 import java.io.InputStream;
 18  
 import java.net.MalformedURLException;
 19  
 import java.net.URL;
 20  
 import java.util.List;
 21  
 import java.util.Set;
 22  
 
 23  
 import javax.servlet.ServletContext;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 import org.apache.hivemind.util.Defense;
 28  
 import org.apache.tapestry.describe.DescriptionReceiver;
 29  
 
 30  
 /**
 31  
  * Adapts {@link javax.servlet.ServletContext} as
 32  
  * {@link org.apache.tapestry.web.WebContext}.
 33  
  * 
 34  
  * @author Howard M. Lewis Ship
 35  
  * @since 4.0
 36  
  */
 37  
 public class ServletWebContext implements WebContext
 38  
 {
 39  
 
 40  0
     private static final Log LOG = LogFactory.getLog(ServletWebContext.class);
 41  
 
 42  
     private final ServletContext _servletContext;
 43  
 
 44  
     public ServletWebContext(ServletContext context)
 45  0
     {
 46  0
         Defense.notNull(context, "context");
 47  
 
 48  0
         _servletContext = context;
 49  0
     }
 50  
 
 51  
     public void describeTo(DescriptionReceiver receiver)
 52  
     {
 53  0
         receiver.describeAlternate(_servletContext);
 54  0
     }
 55  
 
 56  
     public List getAttributeNames()
 57  
     {
 58  0
         return WebUtils.toSortedList(_servletContext.getAttributeNames());
 59  
     }
 60  
 
 61  
     public Object getAttribute(String name)
 62  
     {
 63  0
         return _servletContext.getAttribute(name);
 64  
     }
 65  
 
 66  
     public void setAttribute(String name, Object attribute)
 67  
     {
 68  0
         if (attribute == null)
 69  0
             _servletContext.removeAttribute(name);
 70  0
         else _servletContext.setAttribute(name, attribute);
 71  
 
 72  0
     }
 73  
 
 74  
     public URL getResource(String path)
 75  
     {
 76  
         try
 77  
         {
 78  0
             return _servletContext.getResource(path);
 79  
         }
 80  0
         catch (MalformedURLException ex)
 81  
         {
 82  0
             LOG.error(WebMessages.errorGettingResource(path, ex), ex);
 83  
 
 84  0
             return null;
 85  
         }
 86  
     }
 87  
 
 88  
     public String getInitParameterValue(String name)
 89  
     {
 90  0
         return _servletContext.getInitParameter(name);
 91  
     }
 92  
 
 93  
     public List getInitParameterNames()
 94  
     {
 95  0
         return WebUtils.toSortedList(_servletContext.getInitParameterNames());
 96  
     }
 97  
 
 98  
     public String getMimeType(String resourcePath)
 99  
     {
 100  0
         return _servletContext.getMimeType(resourcePath);
 101  
     }
 102  
 
 103  
     public String getRealPath(String path)
 104  
     {
 105  0
         return _servletContext.getRealPath(path);
 106  
     }
 107  
 
 108  
     public InputStream getResourceAsStream(String path)
 109  
     {
 110  0
         return _servletContext.getResourceAsStream(path);
 111  
     }
 112  
 
 113  
     public Set getResourcePaths(String path)
 114  
     {
 115  0
         return _servletContext.getResourcePaths(path);
 116  
     }
 117  
 }