Coverage Report - org.apache.tapestry.asset.ClasspathAssetFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ClasspathAssetFactory
0%
0/26
0%
0/10
1.857
 
 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 org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.hivemind.ClassResolver;
 19  
 import org.apache.hivemind.Location;
 20  
 import org.apache.hivemind.Resource;
 21  
 import org.apache.hivemind.util.ClasspathResource;
 22  
 import org.apache.tapestry.IAsset;
 23  
 import org.apache.tapestry.engine.IEngineService;
 24  
 import org.apache.tapestry.l10n.ResourceLocalizer;
 25  
 import org.apache.tapestry.spec.IComponentSpecification;
 26  
 
 27  
 import java.util.Locale;
 28  
 
 29  
 /**
 30  
  * Creates instances of {@link org.apache.tapestry.asset.PrivateAsset}, which are the holders of
 31  
  * classpath: resources.
 32  
  * 
 33  
  * @author Howard M. Lewis Ship
 34  
  * @since 4.0
 35  
  */
 36  0
 public class ClasspathAssetFactory implements AssetFactory
 37  
 {
 38  
     private ClassResolver _classResolver;
 39  
 
 40  
     private IEngineService _assetService;
 41  
 
 42  
     private ResourceLocalizer _localizer;
 43  
 
 44  
     private Resource _rootClassPath;
 45  
 
 46  
     public boolean assetExists(IComponentSpecification spec, Resource baseResource, String path, Locale locale)
 47  
     {
 48  0
         Resource assetResource = null;
 49  0
         if (path.startsWith("/")) {
 50  
 
 51  0
             if (_rootClassPath == null) {
 52  0
                 _rootClassPath = new ClasspathResource(_classResolver, "");
 53  
             }
 54  
 
 55  0
             assetResource = _rootClassPath.getRelativeResource(path);
 56  
         } else {
 57  
             
 58  0
             assetResource = baseResource.getRelativeResource(path);
 59  
         }
 60  
 
 61  0
         Resource localized = _localizer.findLocalization(assetResource, locale);
 62  
 
 63  0
         return localized != null;
 64  
     }
 65  
 
 66  
     public IAsset createAsset(Resource baseResource, IComponentSpecification spec, String path, Locale locale, Location location)
 67  
     {
 68  0
         Resource asset = baseResource.getRelativeResource(path);
 69  0
         Resource localized = _localizer.findLocalization(asset, locale);
 70  
 
 71  0
         if (localized == null)
 72  0
             throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource), location, null);
 73  
 
 74  0
         return createAsset(localized, location);
 75  
     }
 76  
 
 77  
     public IAsset createAbsoluteAsset(String path, Locale locale, Location location)
 78  
     {
 79  0
         Resource base = new ClasspathResource(_classResolver, path);
 80  0
         Resource localized = _localizer.findLocalization(base, locale);
 81  
 
 82  0
         if (localized == null)
 83  0
             throw new ApplicationRuntimeException(AssetMessages.missingClasspathResource(path), location, null);
 84  
 
 85  0
         return createAsset(localized, location);
 86  
     }
 87  
 
 88  
     public IAsset createAsset(Resource resource, Location location)
 89  
     {
 90  0
         return new PrivateAsset(resource, _assetService, location);
 91  
     }
 92  
 
 93  
     public void setAssetService(IEngineService assetService)
 94  
     {
 95  0
         _assetService = assetService;
 96  0
     }
 97  
 
 98  
     public void setClassResolver(ClassResolver classResolver)
 99  
     {
 100  0
         _classResolver = classResolver;
 101  0
     }
 102  
 
 103  
     public void setLocalizer(ResourceLocalizer localizer)
 104  
     {
 105  0
         _localizer = localizer;
 106  0
     }
 107  
 }