Search in sources :

Example 6 with StreamableResource

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

Example 7 with StreamableResource

use of org.apache.tapestry5.services.assets.StreamableResource 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;
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource)

Example 8 with StreamableResource

use of org.apache.tapestry5.services.assets.StreamableResource 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);
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) Matcher(java.util.regex.Matcher) JavaScriptStack(org.apache.tapestry5.services.javascript.JavaScriptStack) IOException(java.io.IOException)

Example 9 with StreamableResource

use of org.apache.tapestry5.services.assets.StreamableResource 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;
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) ContentType(org.apache.tapestry5.http.ContentType)

Aggregations

StreamableResource (org.apache.tapestry5.services.assets.StreamableResource)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)2 Asset (org.apache.tapestry5.Asset)2 ContentType (org.apache.tapestry5.http.ContentType)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Matcher (java.util.regex.Matcher)1 Resource (org.apache.tapestry5.commons.Resource)1 BytestreamCache (org.apache.tapestry5.internal.services.assets.BytestreamCache)1 StreamableResourceImpl (org.apache.tapestry5.internal.services.assets.StreamableResourceImpl)1 JavaScriptStack (org.apache.tapestry5.services.javascript.JavaScriptStack)1