Clover coverage report - Code Coverage for tapestry-portlet release 4.0-beta-12
Coverage timestamp: Sun Oct 30 2005 16:27:32 EST
file stats: LOC: 100   Methods: 9
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PortletWebContext.java 100% 86.7% 77.8% 84.6%
coverage coverage
 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.net.MalformedURLException;
 18    import java.net.URL;
 19    import java.util.List;
 20   
 21    import javax.portlet.PortletContext;
 22   
 23    import org.apache.commons.logging.Log;
 24    import org.apache.commons.logging.LogFactory;
 25    import org.apache.hivemind.util.Defense;
 26    import org.apache.tapestry.describe.DescriptionReceiver;
 27    import org.apache.tapestry.web.WebContext;
 28    import org.apache.tapestry.web.WebUtils;
 29   
 30    /**
 31    * Adapts {@link javax.portlet.PortletContext}as {@link org.apache.tapestry.web.WebContext}.
 32    *
 33    * @author Howard M. Lewis Ship
 34    * @since 4.0
 35    */
 36    public class PortletWebContext implements WebContext
 37    {
 38    private static final Log LOG = LogFactory.getLog(PortletWebContext.class);
 39   
 40    private final PortletContext _portletContext;
 41   
 42  10 public PortletWebContext(PortletContext portletContext)
 43    {
 44  10 Defense.notNull(portletContext, "portletContext");
 45   
 46  10 _portletContext = portletContext;
 47    }
 48   
 49  8 public URL getResource(String path)
 50    {
 51  8 try
 52    {
 53  8 return _portletContext.getResource(path);
 54    }
 55    catch (MalformedURLException ex)
 56    {
 57  1 LOG.error(PortletMessages.errorGettingResource(path, ex), ex);
 58   
 59  1 return null;
 60    }
 61    }
 62   
 63  1 public List getAttributeNames()
 64    {
 65  1 return WebUtils.toSortedList(_portletContext.getAttributeNames());
 66    }
 67   
 68  1 public Object getAttribute(String name)
 69    {
 70  1 return _portletContext.getAttribute(name);
 71    }
 72   
 73  2 public void setAttribute(String name, Object attribute)
 74    {
 75  2 if (attribute == null)
 76  1 _portletContext.removeAttribute(name);
 77    else
 78  1 _portletContext.setAttribute(name, attribute);
 79    }
 80   
 81  1 public List getInitParameterNames()
 82    {
 83  1 return WebUtils.toSortedList(_portletContext.getInitParameterNames());
 84    }
 85   
 86  1 public String getInitParameterValue(String name)
 87    {
 88  1 return _portletContext.getInitParameter(name);
 89    }
 90   
 91  0 public String getMimeType(String resourcePath)
 92    {
 93  0 return _portletContext.getMimeType(resourcePath);
 94    }
 95   
 96  0 public void describeTo(DescriptionReceiver receiver)
 97    {
 98  0 receiver.describeAlternate(_portletContext);
 99    }
 100    }