Clover coverage report - Code Coverage for tapestry release 4.0-beta-8
Coverage timestamp: Sat Sep 24 2005 11:50:34 EDT
file stats: LOC: 120   Methods: 5
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AssetSourceImpl.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.asset;
 16   
 17    import java.util.HashMap;
 18    import java.util.Iterator;
 19    import java.util.List;
 20    import java.util.Locale;
 21    import java.util.Map;
 22   
 23    import org.apache.hivemind.Location;
 24    import org.apache.hivemind.Resource;
 25    import org.apache.hivemind.util.Defense;
 26    import org.apache.tapestry.IAsset;
 27   
 28    /**
 29    * Implementation of the {@link org.apache.tapestry.asset.AssetSource}service interface.
 30    *
 31    * @author Howard M. Lewis Ship
 32    * @since 4.0
 33    */
 34    public class AssetSourceImpl implements AssetSource
 35    {
 36    private Map _assetFactoryByPrefix = new HashMap();
 37   
 38    private List _contributions;
 39   
 40    private AssetFactory _defaultAssetFactory;
 41   
 42    private AssetFactory _lookupAssetFactory;
 43   
 44  41 public void initializeService()
 45    {
 46  41 Iterator i = _contributions.iterator();
 47  41 while (i.hasNext())
 48    {
 49  81 AssetFactoryContribution c = (AssetFactoryContribution) i.next();
 50   
 51  81 _assetFactoryByPrefix.put(c.getPrefix(), c.getFactory());
 52    }
 53    }
 54   
 55  426 public IAsset findAsset(Resource base, String path, Locale locale, Location location)
 56    {
 57  426 Defense.notNull(base, "base");
 58  426 Defense.notNull(path, "path");
 59  426 Defense.notNull(location, "location");
 60   
 61  426 int colonx = path.indexOf(':');
 62   
 63  426 if (colonx < 0)
 64  412 return _lookupAssetFactory.createAsset(base, path, locale, location);
 65   
 66  14 String prefix = path.substring(0, colonx);
 67  14 String truePath = path.substring(colonx + 1);
 68   
 69  14 AssetFactory factory = (AssetFactory) _assetFactoryByPrefix.get(prefix);
 70   
 71    // Unknown prefix is expected to happen when an external asset (using an established
 72    // prefix such as http:) is referenced.
 73   
 74  14 if (factory == null)
 75    {
 76  2 factory = _defaultAssetFactory;
 77   
 78    // Path is the full path, including the prefix (which is really the scheme
 79    // of the URL).
 80   
 81  2 truePath = path;
 82    }
 83   
 84  14 if (truePath.startsWith("/"))
 85  9 return factory.createAbsoluteAsset(truePath, locale, location);
 86   
 87    // This can happen when a 3.0 DTD is read in
 88   
 89  5 return factory.createAsset(base, truePath, locale, location);
 90    }
 91   
 92    /**
 93    * Factory used when the path has no prefix, and the type of asset must be inferred from the
 94    * type of resource.
 95    */
 96   
 97  41 public void setLookupAssetFactory(AssetFactory lookupAssetFactory)
 98    {
 99  41 _lookupAssetFactory = lookupAssetFactory;
 100    }
 101   
 102    /**
 103    * List of {@link org.apache.tapestry.asset.AssetFactoryContribution}.
 104    */
 105   
 106  41 public void setContributions(List contributions)
 107    {
 108  41 _contributions = contributions;
 109    }
 110   
 111    /**
 112    * Factory used when an unrecognized prefix (typically, an arbitrary URL's scheme) is provided.
 113    */
 114   
 115  41 public void setDefaultAssetFactory(AssetFactory defaultAssetFactory)
 116    {
 117  41 _defaultAssetFactory = defaultAssetFactory;
 118    }
 119   
 120    }