Clover coverage report - Code Coverage for tapestry-portlet release 4.0-beta-6
Coverage timestamp: Wed Sep 7 2005 18:46:01 EDT
file stats: LOC: 114   Methods: 7
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PortletApplicationSpecificationInitializer.java 100% 100% 100% 100%
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.PortletConfig;
 18   
 19    import org.apache.hivemind.Resource;
 20    import org.apache.tapestry.parse.ISpecificationParser;
 21    import org.apache.tapestry.services.ApplicationGlobals;
 22    import org.apache.tapestry.spec.ApplicationSpecification;
 23    import org.apache.tapestry.spec.IApplicationSpecification;
 24    import org.apache.tapestry.web.WebContext;
 25    import org.apache.tapestry.web.WebContextResource;
 26   
 27    /**
 28    * Locates and reads the application specification for the portlet and stores it into
 29    * {@link org.apache.tapestry.services.ApplicationGlobals}.
 30    * <p>
 31    * TODO: Merge this code with
 32    * {@link org.apache.tapestry.services.impl.ApplicationSpecificationInitializer}, they're very
 33    * similar. This would probably be an additional service that would do the lookup based on the
 34    * {@link org.apache.tapestry.web.WebActivator}&nbsp;and the {@link org.apache.tapestry.web.WebContext}.
 35    *
 36    * @author Howard M. Lewis Ship
 37    * @since 4.0
 38    * @see org.apache.tapestry.services.impl.ApplicationSpecificationInitializer
 39    */
 40    public class PortletApplicationSpecificationInitializer implements PortletApplicationInitializer
 41    {
 42    private WebContext _context;
 43   
 44    private ApplicationGlobals _globals;
 45   
 46    private ISpecificationParser _parser;
 47   
 48  4 public void initialize(PortletConfig portletConfig)
 49    {
 50  4 String name = portletConfig.getPortletName();
 51   
 52  4 Resource resource = findApplicationSpecification(name);
 53   
 54  4 IApplicationSpecification specification = resource == null ? constructStandinSpecification(name)
 55    : _parser.parseApplicationSpecification(resource);
 56   
 57  4 _globals.storeSpecification(specification);
 58    }
 59   
 60  4 private Resource findApplicationSpecification(String name)
 61    {
 62  4 String expectedName = name + ".application";
 63   
 64  4 Resource webInfLocation = new WebContextResource(_context, "/WEB-INF/");
 65  4 Resource webInfAppLocation = webInfLocation.getRelativeResource(name + "/");
 66   
 67  4 Resource result = check(webInfAppLocation, expectedName);
 68  4 if (result != null)
 69  1 return result;
 70   
 71  3 return check(webInfLocation, expectedName);
 72    }
 73   
 74  7 private Resource check(Resource resource, String name)
 75    {
 76  7 Resource result = resource.getRelativeResource(name);
 77   
 78  7 if (result.getResourceURL() != null)
 79  2 return result;
 80   
 81  5 return null;
 82    }
 83   
 84  2 private IApplicationSpecification constructStandinSpecification(String name)
 85    {
 86  2 ApplicationSpecification result = new ApplicationSpecification();
 87   
 88    // Pretend the file exists in the most common expected location.
 89   
 90  2 Resource virtualLocation = new WebContextResource(_context, "/WEB-INF/" + name
 91    + ".application");
 92   
 93  2 result.setSpecificationLocation(virtualLocation);
 94   
 95  2 result.setName(name);
 96   
 97  2 return result;
 98    }
 99   
 100  4 public void setContext(WebContext context)
 101    {
 102  4 _context = context;
 103    }
 104   
 105  4 public void setGlobals(ApplicationGlobals globals)
 106    {
 107  4 _globals = globals;
 108    }
 109   
 110  3 public void setParser(ISpecificationParser parser)
 111    {
 112  3 _parser = parser;
 113    }
 114    }