Clover coverage report - Code Coverage for tapestry-portlet release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:14:58 EST
file stats: LOC: 114   Methods: 12
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PortletWebContext.java 100% 72.2% 58.3% 68.8%
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.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 {@link org.apache.tapestry.web.WebContext}.
 34    *
 35    * @author Howard M. Lewis Ship
 36    * @since 4.0
 37    */
 38    public class PortletWebContext implements WebContext
 39    {
 40    private static final Log LOG = LogFactory.getLog(PortletWebContext.class);
 41   
 42    private final PortletContext _portletContext;
 43   
 44  20 public PortletWebContext(PortletContext portletContext)
 45    {
 46  20 Defense.notNull(portletContext, "portletContext");
 47   
 48  20 _portletContext = portletContext;
 49    }
 50   
 51  16 public URL getResource(String path)
 52    {
 53  16 try
 54    {
 55  16 return _portletContext.getResource(path);
 56    }
 57    catch (MalformedURLException ex)
 58    {
 59  2 LOG.error(PortletMessages.errorGettingResource(path, ex), ex);
 60   
 61  2 return null;
 62    }
 63    }
 64   
 65  2 public List getAttributeNames()
 66    {
 67  2 return WebUtils.toSortedList(_portletContext.getAttributeNames());
 68    }
 69   
 70  2 public Object getAttribute(String name)
 71    {
 72  2 return _portletContext.getAttribute(name);
 73    }
 74   
 75  4 public void setAttribute(String name, Object attribute)
 76    {
 77  4 if (attribute == null)
 78  2 _portletContext.removeAttribute(name);
 79    else
 80  2 _portletContext.setAttribute(name, attribute);
 81    }
 82   
 83  2 public List getInitParameterNames()
 84    {
 85  2 return WebUtils.toSortedList(_portletContext.getInitParameterNames());
 86    }
 87   
 88  2 public String getInitParameterValue(String name)
 89    {
 90  2 return _portletContext.getInitParameter(name);
 91    }
 92   
 93  0 public String getMimeType(String resourcePath)
 94    {
 95  0 return _portletContext.getMimeType(resourcePath);
 96    }
 97   
 98  0 public void describeTo(DescriptionReceiver receiver)
 99    {
 100  0 receiver.describeAlternate(_portletContext);
 101    }
 102   
 103  0 public String getRealPath(String path) {
 104  0 return _portletContext.getRealPath(path);
 105    }
 106   
 107  0 public InputStream getResourceAsStream(String path) {
 108  0 return _portletContext.getResourceAsStream(path);
 109    }
 110   
 111  0 public Set getResourcePaths(String path) {
 112  0 return _portletContext.getResourcePaths(path);
 113    }
 114    }