1 15 package org.apache.tapestry.asset; 16 17 import java.util.Locale ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Location; 21 import org.apache.hivemind.Resource; 22 import org.apache.tapestry.IAsset; 23 import org.apache.tapestry.web.WebContext; 24 import org.apache.tapestry.web.WebContextResource; 25 26 33 public class ContextAssetFactory implements AssetFactory 34 { 35 private WebContext _context; 36 37 private String _contextPath; 38 39 private Resource _servletRoot; 40 41 public void initializeService() 42 { 43 _servletRoot = new WebContextResource(_context, "/"); 44 } 45 46 public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location) 47 { 48 Resource assetResource = _servletRoot.getRelativeResource(path); 49 Resource localized = assetResource.getLocalization(locale); 50 51 if (localized == null) 52 throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, _servletRoot), 53 location, null); 54 55 return new ContextAsset(_contextPath, localized, location); 56 } 57 58 public IAsset createAsset(Resource resource, Location location) 59 { 60 return new ContextAsset(resource.getPath(), resource, location); 61 } 62 63 public void setContext(WebContext context) 64 { 65 _context = context; 66 } 67 68 public void setContextPath(String contextPath) 69 { 70 _contextPath = contextPath; 71 } 72 } | Popular Tags |