use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class LessResourceTransformer method invokeLessCompiler.
private BytestreamCache invokeLessCompiler(Resource source, ResourceDependencies dependencies) throws IOException {
try {
LessSource lessSource = new ResourceLessSource(source, dependencies);
LessCompiler.CompilationResult compilationResult = compile(compiler, lessSource);
return new BytestreamCache(compilationResult.getCss().getBytes("utf-8"));
} catch (Less4jException ex) {
throw new IOException(ex);
} catch (UnsupportedEncodingException ex) {
throw new IOException(ex);
}
}
use of org.apache.tapestry5.commons.Resource 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.commons.Resource 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.commons.Resource in project tapestry-5 by apache.
the class TemplateParserImplTest method namespaced_element.
@Test
public void namespaced_element() {
Resource resource = getResource("namespaced_element.tml");
ComponentTemplate template = getParser().parseTemplate(resource);
assertSame(template.getResource(), resource);
List<TemplateToken> tokens = template.getTokens();
// They add up quick ...
assertEquals(tokens.size(), 8);
StartElementToken t0 = get(tokens, 0);
String expectedURI = "http://foo.com";
assertEquals(t0.namespaceURI, expectedURI);
assertEquals(t0.name, "bar");
DefineNamespacePrefixToken t1 = get(tokens, 1);
assertEquals(t1.namespacePrefix, "foo");
assertEquals(t1.namespaceURI, expectedURI);
AttributeToken t2 = get(tokens, 2);
assertEquals(t2.name, "biff");
assertEquals(t2.value, "baz");
assertEquals(t2.namespaceURI, expectedURI);
StartElementToken t4 = get(tokens, 4);
assertEquals(t4.namespaceURI, "");
assertEquals(t4.name, "gnip");
// The rest are close tokens
}
use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class TemplateParserImplTest method resource_that_throws_exception.
@Test
public // TAP5-2516
void resource_that_throws_exception() throws Exception {
Resource resource = new AbstractResource("throwfoo") {
@Override
public URL toURL() {
return null;
}
@Override
public boolean exists() {
return true;
}
@Override
protected Resource newResource(String path) {
return null;
}
@Override
public InputStream openStream() throws IOException {
throw new IOException("foo");
}
};
try {
getParser().parseTemplate(resource);
unreachable();
} catch (RuntimeException ex) {
if (ex.getCause() instanceof TapestryException && ex.getCause().getCause() instanceof IOException) {
assertMessageContains(ex, "foo");
} else {
throw ex;
}
}
}
Aggregations