Search in sources :

Example 96 with Resource

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

Example 97 with Resource

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

Example 98 with Resource

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);
}
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 99 with Resource

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

Example 100 with 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");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) PropertiesFileParser(org.apache.tapestry5.services.messages.PropertiesFileParser) Test(org.testng.annotations.Test)

Aggregations

Resource (org.apache.tapestry5.commons.Resource)78 Test (org.testng.annotations.Test)62 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)38 Logger (org.slf4j.Logger)38 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)16 Asset (org.apache.tapestry5.Asset)14 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)10 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 IOException (java.io.IOException)5 AssetSource (org.apache.tapestry5.services.AssetSource)5 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)5 Context (org.apache.tapestry5.http.services.Context)4 BeginRender (org.apache.tapestry5.annotations.BeginRender)3 Location (org.apache.tapestry5.commons.Location)3 AbstractResource (org.apache.tapestry5.ioc.internal.util.AbstractResource)3 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)3 ClasspathAssetAliasManager (org.apache.tapestry5.services.ClasspathAssetAliasManager)3 StreamableResource (org.apache.tapestry5.services.assets.StreamableResource)3