Search in sources :

Example 6 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class AssetSourceImplTest method unknown_asset_prefix.

@Test
public void unknown_asset_prefix() {
    ThreadLocale threadLocale = mockThreadLocale();
    Map<String, AssetFactory> configuration = Collections.emptyMap();
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    try {
        source.getAsset(baseResource, "classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK);
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Unknown prefix for asset path 'classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties'.");
    }
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 7 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class AssetSourceImpl method getAssetForResource.

private Asset getAssetForResource(Resource resource) {
    try {
        acquireReadLock();
        Asset result = TapestryInternalUtils.getAndDeref(cache, resource);
        if (result == null) {
            result = createAssetFromResource(resource);
            cache.put(resource, new SoftReference(result));
        }
        return result;
    } finally {
        releaseReadLock();
    }
}
Also used : SoftReference(java.lang.ref.SoftReference) Asset(org.apache.tapestry5.Asset)

Example 8 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class AbstractAssetFactory method createAsset.

protected Asset createAsset(final Resource resource, final String folder, final String resourcePath) {
    assert resource != null;
    assert InternalUtils.isNonBlank(folder);
    assert InternalUtils.isNonBlank(resourcePath);
    return new AbstractAsset(false) {

        public String toClientURL() {
            try {
                // Get the uncompressed version, so that we can identify its content type (and remember, the extension is not enough,
                // as some types get translated to new content types by the SRS).
                StreamableResource uncompressed = streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_DISABLED, resourceChangeTracker);
                StreamableResource forRequest = isCompressable(uncompressed) ? streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_ENABLED, resourceChangeTracker) : uncompressed;
                return assetPathConstructor.constructAssetPath(folder, resourcePath, forRequest);
            } catch (IOException ex) {
                throw new RuntimeException(String.format("Unable to construct asset path for %s: %s", resource, ExceptionUtils.toMessage(ex)), ex);
            }
        }

        public Resource getResource() {
            return resource;
        }
    };
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) IOException(java.io.IOException)

Example 9 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class AssetInjectionProvider method provideInjection.

public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Path path = field.getAnnotation(Path.class);
    if (path == null) {
        return false;
    }
    final String assetPath = path.value();
    final String libraryName = componentModel.getLibraryName();
    ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() {

        public Asset get(InstanceContext context) {
            ComponentResources resources = context.get(ComponentResources.class);
            // a different library name than the subclass).
            return assetSource.getComponentAsset(resources, assetPath, libraryName);
        }
    };
    field.injectComputed(computedAsset);
    return true;
}
Also used : Path(org.apache.tapestry5.annotations.Path) ComputedValue(org.apache.tapestry5.plastic.ComputedValue) InstanceContext(org.apache.tapestry5.plastic.InstanceContext) Asset(org.apache.tapestry5.Asset) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 10 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class SubmitTest method test_imagesubmit_event_fired.

@Test
public void test_imagesubmit_event_fired() {
    Request request = mockRequest();
    final ComponentResources resources = mockComponentResources();
    FormSupport formSupport = mockFormSupport();
    Asset image = mockAsset();
    String elementName = "myname";
    train_getParameter(request, Form.SUBMITTING_ELEMENT_ID, null);
    train_getParameter(request, elementName + ".x", "15");
    formSupport.defer(isA(Runnable.class));
    replay();
    Submit submit = new Submit(request);
    TestBase.set(submit, "resources", resources, "formSupport", formSupport, "image", image);
    submit.processSubmission("xyz", elementName);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Asset(org.apache.tapestry5.Asset) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

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