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();
}
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();
}
}
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;
}
};
}
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;
}
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();
}
Aggregations