use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class JavaScriptStackAssemblerImpl method assembleStreamableForStack.
private StreamableResource assembleStreamableForStack(String localeName, Parameters parameters, List<Asset> libraries, List<String> moduleNames) throws IOException {
Assembly assembly = new Assembly(String.format("'%s' JavaScript stack, for locale %s, resources=", parameters.stackName, localeName));
for (Asset library : libraries) {
Resource resource = library.getResource();
assembly.add(resource, libraryReader);
}
for (String moduleName : moduleNames) {
Resource resource = moduleManager.findResourceForModule(moduleName);
if (resource == null) {
throw new IllegalArgumentException(String.format("Could not identify a resource for module name '%s'.", moduleName));
}
assembly.add(resource, new ModuleReader(moduleName));
}
StreamableResource streamable = assembly.finish();
if (minificationEnabled && parameters.javascriptAggregationStrategy.enablesMinimize()) {
return resourceMinimizer.minimize(streamable);
}
return streamable;
}
use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class SRSCachingInterceptor method getStreamableResource.
public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing, ResourceDependencies dependencies) throws IOException {
if (!enableCache(processing)) {
return delegate.getStreamableResource(baseResource, processing, dependencies);
}
StreamableResource result = TapestryInternalUtils.getAndDeref(cache, baseResource);
if (result == null) {
result = delegate.getStreamableResource(baseResource, processing, dependencies);
if (isCacheable(result)) {
dependencies.addDependency(baseResource);
cache.put(baseResource, new SoftReference<StreamableResource>(result));
}
}
return result;
}
use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class StackAssetRequestHandler method streamStackResource.
private boolean streamStackResource(String extraPath) throws IOException {
Matcher matcher = pathPattern.matcher(extraPath);
if (!matcher.matches()) {
logger.warn("Unable to parse '{}' as an asset stack path", extraPath);
return false;
}
String checksum = matcher.group(1);
String localeName = matcher.group(2);
final String stackName = matcher.group(3);
final boolean compressed = checksum.startsWith("z");
if (compressed) {
checksum = checksum.substring(1);
}
final JavaScriptStack stack = stackSource.findStack(stackName);
if (stack == null) {
logger.warn("JavaScript stack '{}' not found.", stackName);
return false;
}
// Yes, I have a big regret that the JavaScript stack stuff relies on this global, rather than
// having it passed around properly.
localizationSetter.setNonPersistentLocaleFromLocaleName(localeName);
StreamableResource resource = tracker.perform(String.format("Assembling JavaScript asset stack '%s' (%s)", stackName, localeName), new IOOperation<StreamableResource>() {
public StreamableResource perform() throws IOException {
return javaScriptStackAssembler.assembleJavaScriptResourceForStack(stackName, compressed, stack.getJavaScriptAggregationStrategy());
}
});
if (resource == null) {
return false;
}
return resourceStreamer.streamResource(resource, checksum, ResourceStreamer.DEFAULT_OPTIONS);
}
use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class UTF8ForTextAssets method getStreamableResource.
@Override
public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing, ResourceDependencies dependencies) throws IOException {
StreamableResource resource = delegate.getStreamableResource(baseResource, processing, dependencies);
ContentType contentType = resource.getContentType();
if (contentType.getBaseType().equals("text") && !contentType.hasParameters() && processing != StreamableResourceProcessing.FOR_AGGREGATION) {
return resource.withContentType(contentType.withCharset("utf-8"));
}
return resource;
}
use of org.apache.tapestry5.commons.Resource in project tapestry-5 by apache.
the class PropertiesFileParserImplTest method read_utf.
@Test
public void read_utf() throws Exception {
Resource utf8 = new ClasspathResource("org/apache/tapestry5/internal/services/messages/utf8.properties");
PropertiesFileParser parser = getService(PropertiesFileParser.class);
Map<String, String> properties = parser.parsePropertiesFile(utf8);
assertEquals(properties.get("tapestry"), "\u30bf\u30da\u30b9\u30c8\u30ea\u30fc");
assertEquals(properties.get("version"), "5");
}
Aggregations