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: 117   Methods: 9
NCLOC: 69   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PageResolverContribution.java 83.3% 76.7% 88.9% 80.4%
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 javax.portlet.PortletRequest;
 18   
 19    import org.apache.hivemind.impl.BaseLocatable;
 20    import org.apache.hivemind.util.Defense;
 21    import org.apache.hivemind.util.ToStringBuilder;
 22   
 23    /**
 24    * Contribution used for resolving requests to named pages.
 25    *
 26    * @author Howard M. Lewis Ship
 27    * @since 4.0
 28    */
 29    public class PageResolverContribution extends BaseLocatable implements Comparable
 30    {
 31    private String _portletMode;
 32   
 33    private String _windowState;
 34   
 35    private String _mimeType;
 36   
 37    private String _pageName;
 38   
 39  14 public void setMimeType(String mimeType)
 40    {
 41  14 _mimeType = mimeType;
 42    }
 43   
 44  14 public void setPageName(String pageName)
 45    {
 46  14 _pageName = pageName;
 47    }
 48   
 49  6 public String getPageName()
 50    {
 51  6 return _pageName;
 52    }
 53   
 54  14 public void setPortletMode(String portletMode)
 55    {
 56  14 _portletMode = portletMode;
 57    }
 58   
 59  14 public void setWindowState(String windowState)
 60    {
 61  14 _windowState = windowState;
 62    }
 63   
 64  8 int sortScore()
 65    {
 66  8 int result = 0;
 67   
 68  8 if (_mimeType != null)
 69  0 result += 4;
 70   
 71  8 if (_portletMode != null)
 72  8 result += 2;
 73   
 74  8 if (_windowState != null)
 75  4 result += 1;
 76   
 77  8 return result;
 78    }
 79   
 80  0 public String toString()
 81    {
 82  0 ToStringBuilder builder = new ToStringBuilder(this);
 83   
 84  0 builder.append("mimeType", _mimeType);
 85  0 builder.append("portletMode", _portletMode);
 86  0 builder.append("windowState", _windowState);
 87  0 builder.append("pageName", _pageName);
 88   
 89  0 return builder.toString();
 90    }
 91   
 92  4 public int compareTo(Object o)
 93    {
 94  4 int thisScore = sortScore();
 95  4 int otherScore = ((PageResolverContribution) o).sortScore();
 96   
 97    // End result: sorted descending by specificity
 98   
 99  4 return otherScore - thisScore;
 100    }
 101   
 102  12 public boolean match(PortletRequest request)
 103    {
 104  12 Defense.notNull(request, "request");
 105   
 106  12 if (_mimeType != null && !_mimeType.equals(request.getResponseContentType()))
 107  2 return false;
 108   
 109  10 if (_portletMode != null && !_portletMode.equals(request.getPortletMode().toString()))
 110  2 return false;
 111   
 112  8 if (_windowState != null && !_windowState.equals(request.getWindowState().toString()))
 113  2 return false;
 114   
 115  6 return true;
 116    }
 117    }