use of org.apache.tapestry5.Asset in project tapestry-5 by apache.
the class AssetObjectProvider method provide.
/**
* Provides the asset. If the expression does not identify an asset domain, with a prefix, it is assumed to be a
* path on the classpath, relative to the root of the classpath.
*
* @param objectType the type of object (which must be Object or Asset)
* @param locator not used
*/
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Path path = annotationProvider.getAnnotation(Path.class);
if (path == null)
return null;
String expanded = symbolSource.expandSymbols(path.value());
Asset asset = source.getAsset(null, expanded, null);
return typeCoercer.coerce(asset, objectType);
}
use of org.apache.tapestry5.Asset in project tapestry-5 by apache.
the class AssetSourceImpl method findResource.
/**
* @param baseResource
* the base resource (or null for classpath root) that path will extend from
* @param path
* extension path from the base resource
* @return the resource, unlocalized, which may not exist (may be for a path with no actual resource)
*/
private Resource findResource(Resource baseResource, String path) {
assert path != null;
int colonx = path.indexOf(':');
if (colonx < 0) {
Resource root = baseResource != null ? baseResource : prefixToRootResource.get(AssetConstants.CLASSPATH);
return root.forFile(path);
}
String prefix = path.substring(0, colonx);
Resource root = prefixToRootResource.get(prefix);
if (root == null)
throw new IllegalArgumentException(String.format("Unknown prefix for asset path '%s'.", path));
return root.forFile(path.substring(colonx + 1));
}
use of org.apache.tapestry5.Asset in project tapestry-5 by apache.
the class AssetSourceImpl method getLocalizedAssetFromResource.
private Asset getLocalizedAssetFromResource(Resource unlocalized, Locale locale) {
final Resource localized;
if (locale == null) {
localized = unlocalized;
} else {
Reference<Asset> reference = cache.get(unlocalized);
if (reference != null) {
Asset asset = reference.get();
if (asset != null) {
// Prefer resource from cache to use its cache
unlocalized = asset.getResource();
}
}
localized = unlocalized.forLocale(locale);
}
if (localized == null || !localized.exists()) {
throw new AssetNotFoundException(String.format("Unable to locate asset '%s' (the file does not exist).", unlocalized), unlocalized);
}
return getAssetForResource(localized);
}
use of org.apache.tapestry5.Asset in project tapestry-5 by apache.
the class AssetSourceImpl method createAssetFromResource.
private Asset createAssetFromResource(Resource resource) {
try {
upgradeReadLockToWriteLock();
// Check for competing thread beat us to it (not very likely!):
Asset result = TapestryInternalUtils.getAndDeref(cache, resource);
if (result != null) {
return result;
}
Class resourceClass = resource.getClass();
AssetFactory factory = registry.get(resourceClass);
return factory.createAsset(resource);
} finally {
downgradeWriteLockToReadLock();
}
}
use of org.apache.tapestry5.Asset in project tapestry-5 by apache.
the class ResourceStreamerImpl method findAssetInsideWebapp.
private Asset findAssetInsideWebapp(Resource resource) {
Asset asset;
asset = findAssetFromClasspath(resource);
if (asset == null) {
asset = findAssetFromContext(resource);
}
return asset;
}
Aggregations