Coverage Report - org.apache.tapestry.portlet.PortletWebContext
 
Classes in this File Line Coverage Branch Coverage Complexity
PortletWebContext
74% 
100% 
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.portlet;
 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.portlet.PortletContext;
 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  
 import org.apache.tapestry.web.WebContext;
 30  
 import org.apache.tapestry.web.WebUtils;
 31  
 
 32  
 /**
 33  
  * Adapts {@link javax.portlet.PortletContext}as
 34  
  * {@link org.apache.tapestry.web.WebContext}.
 35  
  * 
 36  
  * @author Howard M. Lewis Ship
 37  
  * @since 4.0
 38  
  */
 39  
 public class PortletWebContext implements WebContext
 40  
 {
 41  
 
 42  2
     private static final Log LOG = LogFactory.getLog(PortletWebContext.class);
 43  
 
 44  
     private final PortletContext _portletContext;
 45  
 
 46  
     public PortletWebContext(PortletContext portletContext)
 47  10
     {
 48  10
         Defense.notNull(portletContext, "portletContext");
 49  
 
 50  10
         _portletContext = portletContext;
 51  10
     }
 52  
 
 53  
     public URL getResource(String path)
 54  
     {
 55  
         try
 56  
         {
 57  8
             return _portletContext.getResource(path);
 58  
         }
 59  1
         catch (MalformedURLException ex)
 60  
         {
 61  1
             LOG.error(PortletMessages.errorGettingResource(path, ex), ex);
 62  
 
 63  1
             return null;
 64  
         }
 65  
     }
 66  
 
 67  
     public List getAttributeNames()
 68  
     {
 69  1
         return WebUtils.toSortedList(_portletContext.getAttributeNames());
 70  
     }
 71  
 
 72  
     public Object getAttribute(String name)
 73  
     {
 74  1
         return _portletContext.getAttribute(name);
 75  
     }
 76  
 
 77  
     public void setAttribute(String name, Object attribute)
 78  
     {
 79  2
         if (attribute == null)
 80  1
             _portletContext.removeAttribute(name);
 81  1
         else _portletContext.setAttribute(name, attribute);
 82  2
     }
 83  
 
 84  
     public List getInitParameterNames()
 85  
     {
 86  1
         return WebUtils.toSortedList(_portletContext.getInitParameterNames());
 87  
     }
 88  
 
 89  
     public String getInitParameterValue(String name)
 90  
     {
 91  1
         return _portletContext.getInitParameter(name);
 92  
     }
 93  
 
 94  
     public String getMimeType(String resourcePath)
 95  
     {
 96  0
         return _portletContext.getMimeType(resourcePath);
 97  
     }
 98  
 
 99  
     public void describeTo(DescriptionReceiver receiver)
 100  
     {
 101  0
         receiver.describeAlternate(_portletContext);
 102  0
     }
 103  
 
 104  
     public String getRealPath(String path)
 105  
     {
 106  0
         return _portletContext.getRealPath(path);
 107  
     }
 108  
 
 109  
     public InputStream getResourceAsStream(String path)
 110  
     {
 111  0
         return _portletContext.getResourceAsStream(path);
 112  
     }
 113  
 
 114  
     public Set getResourcePaths(String path)
 115  
     {
 116  0
         return _portletContext.getResourcePaths(path);
 117  
     }
 118  
 }