Search in sources :

Example 16 with Asset

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);
}
Also used : Path(org.apache.tapestry5.annotations.Path) Asset(org.apache.tapestry5.Asset)

Example 17 with Asset

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));
}
Also used : Resource(org.apache.tapestry5.commons.Resource)

Example 18 with Asset

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);
}
Also used : Resource(org.apache.tapestry5.commons.Resource) Asset(org.apache.tapestry5.Asset) AssetNotFoundException(org.apache.tapestry5.services.AssetNotFoundException)

Example 19 with Asset

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();
    }
}
Also used : Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory)

Example 20 with Asset

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;
}
Also used : Asset(org.apache.tapestry5.Asset)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)10 Test (org.testng.annotations.Test)9 AssetFactory (org.apache.tapestry5.services.AssetFactory)8 AssetSource (org.apache.tapestry5.services.AssetSource)8 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Asset (com.google.cloud.asset.v1.Asset)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 OutputStream (java.io.OutputStream)1 SoftReference (java.lang.ref.SoftReference)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1