Search in sources :

Example 6 with MultiKey

use of org.apache.tapestry5.commons.util.MultiKey in project tapestry-5 by apache.

the class ComponentTemplateSourceImpl method getTemplate.

public ComponentTemplate getTemplate(ComponentModel componentModel, ComponentResourceSelector selector) {
    String componentName = componentModel.getComponentClassName();
    MultiKey key = new MultiKey(componentName, selector);
    // First cache is key to resource.
    Resource resource = templateResources.get(key);
    if (resource == null) {
        resource = locateTemplateResource(componentModel, selector);
        templateResources.put(key, resource);
    }
    // If we haven't yet parsed the template into the cache, do so now.
    ComponentTemplate result = templates.get(resource);
    if (result == null) {
        result = parseTemplate(resource);
        templates.put(resource, result);
    }
    return result;
}
Also used : MultiKey(org.apache.tapestry5.commons.util.MultiKey) Resource(org.apache.tapestry5.commons.Resource) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate)

Example 7 with MultiKey

use of org.apache.tapestry5.commons.util.MultiKey in project tapestry-5 by apache.

the class MessagesSourceImpl method findBundleProperties.

/**
 * Assembles a set of properties appropriate for the bundle in question, and the desired locale. The properties
 * reflect the properties of the bundles' parent (if any) for the locale, overalyed with any properties defined for
 * this bundle and its locale.
 */
private Map<String, String> findBundleProperties(MessagesBundle bundle, ComponentResourceSelector selector) {
    if (bundle == null)
        return emptyMap;
    MultiKey key = new MultiKey(bundle.getId(), selector);
    Map<String, String> existing = cookedProperties.get(key);
    if (existing != null)
        return existing;
    // What would be cool is if we could maintain a cache of bundle id + locale -->
    // Resource. That would optimize quite a bit of this; may need to use an alternative to
    // LocalizedNameGenerator.
    Resource propertiesResource = bundle.getBaseResource().withExtension("properties");
    List<Resource> localizations = resourceLocator.locateMessageCatalog(propertiesResource, selector);
    // Localizations are now in least-specific to most-specific order.
    Map<String, String> previous = findBundleProperties(bundle.getParent(), selector);
    for (Resource localization : F.flow(localizations).reverse()) {
        Map<String, String> rawProperties = getRawProperties(localization);
        // Woould be nice to write into the cookedProperties cache here,
        // but we can't because we don't know the selector part of the MultiKey.
        previous = extend(previous, rawProperties);
    }
    cookedProperties.put(key, previous);
    return previous;
}
Also used : MultiKey(org.apache.tapestry5.commons.util.MultiKey) Resource(org.apache.tapestry5.commons.Resource)

Example 8 with MultiKey

use of org.apache.tapestry5.commons.util.MultiKey in project tapestry-5 by apache.

the class MultiKeyTest method comparisons_against_not_multi_key.

@Test
public void comparisons_against_not_multi_key() {
    MultiKey key = new MultiKey(1, 3, "foo");
    assertFalse(key.equals(null));
    assertFalse(key.equals("foo"));
}
Also used : MultiKey(org.apache.tapestry5.commons.util.MultiKey) Test(org.testng.annotations.Test)

Aggregations

MultiKey (org.apache.tapestry5.commons.util.MultiKey)8 Test (org.testng.annotations.Test)4 Resource (org.apache.tapestry5.commons.Resource)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)1 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)1 Messages (org.apache.tapestry5.commons.Messages)1 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)1