1 15 package org.apache.tapestry.asset; 16 17 import java.io.InputStream ; 18 import java.net.URL ; 19 20 import org.apache.hivemind.ApplicationRuntimeException; 21 import org.apache.hivemind.Location; 22 import org.apache.hivemind.Resource; 23 import org.apache.hivemind.util.ClasspathResource; 24 import org.apache.tapestry.IRequestCycle; 25 import org.apache.tapestry.Tapestry; 26 import org.apache.tapestry.engine.IEngineService; 27 import org.apache.tapestry.engine.ILink; 28 29 37 38 public class PrivateAsset extends AbstractAsset 39 { 40 private IEngineService _assetService; 41 42 46 public PrivateAsset(ClasspathResource resourceLocation, Location location) 47 { 48 this(resourceLocation, null, location); 49 } 50 51 public PrivateAsset(ClasspathResource resourceLocation, IEngineService assetService, 52 Location location) 53 { 54 super(resourceLocation, location); 55 56 _assetService = assetService; 57 } 58 59 64 65 public String buildURL(IRequestCycle cycle) 66 { 67 String path = getResourceLocation().getPath(); 68 69 73 if (_assetService == null) 74 _assetService = cycle.getEngine().getService(Tapestry.ASSET_SERVICE); 75 76 ILink link = _assetService.getLink(cycle, path); 77 78 return link.getURL(); 79 } 80 81 public InputStream getResourceAsStream(IRequestCycle cycle) 82 { 83 Resource location = getResourceLocation(); 84 85 try 86 { 87 URL url = location.getResourceURL(); 88 89 return url.openStream(); 90 } 91 catch (Exception ex) 92 { 93 throw new ApplicationRuntimeException(Tapestry.format( 94 "PrivateAsset.resource-missing", 95 location), ex); 96 } 97 } 98 99 } | Popular Tags |