Search in sources :

Example 1 with ComponentResourceSelector

use of org.apache.tapestry5.services.pageload.ComponentResourceSelector in project tapestry-5 by apache.

the class MessagesSourceImpl method getMessages.

public Messages getMessages(MessagesBundle bundle, ComponentResourceSelector selector) {
    MultiKey key = new MultiKey(bundle.getId(), selector);
    Messages result = messagesByBundleIdAndSelector.get(key);
    if (result == null) {
        result = buildMessages(bundle, selector);
        messagesByBundleIdAndSelector.put(key, result);
    }
    return result;
}
Also used : Messages(org.apache.tapestry5.commons.Messages) MultiKey(org.apache.tapestry5.commons.util.MultiKey)

Example 2 with ComponentResourceSelector

use of org.apache.tapestry5.services.pageload.ComponentResourceSelector in project tapestry-5 by apache.

the class ComponentTemplateSourceImpl method locateTemplateResource.

private Resource locateTemplateResource(ComponentModel initialModel, ComponentResourceSelector selector) {
    ComponentModel model = initialModel;
    while (model != null) {
        Resource localized = locator.locateTemplate(model, selector);
        if (localized != null)
            return localized;
        // Otherwise, this component doesn't have its own template ... lets work up to its
        // base class and check there.
        model = model.getParentModel();
    }
    return initialModel.getBaseResource().withExtension(TapestryConstants.TEMPLATE_EXTENSION);
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource)

Example 3 with ComponentResourceSelector

use of org.apache.tapestry5.services.pageload.ComponentResourceSelector 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 4 with ComponentResourceSelector

use of org.apache.tapestry5.services.pageload.ComponentResourceSelector 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 5 with ComponentResourceSelector

use of org.apache.tapestry5.services.pageload.ComponentResourceSelector in project tapestry-5 by apache.

the class MarkupWriterFactoryImpl method hasHTML5Doctype.

private boolean hasHTML5Doctype(Page page) {
    ComponentModel componentModel = page.getRootComponent().getComponentResources().getComponentModel();
    ComponentResourceSelector selector = componentRequestSelectorAnalyzer.buildSelectorForRequest();
    List<TemplateToken> tokens = templateSource.getTemplate(componentModel, selector).getTokens();
    DTDToken dtd = null;
    for (TemplateToken token : tokens) {
        if (token.getTokenType() == TokenType.DTD) {
            dtd = (DTDToken) token;
            break;
        }
    }
    return dtd != null && dtd.name.equalsIgnoreCase("html") && dtd.publicId == null && dtd.systemId == null;
}
Also used : ComponentResourceSelector(org.apache.tapestry5.services.pageload.ComponentResourceSelector) ComponentModel(org.apache.tapestry5.model.ComponentModel) TemplateToken(org.apache.tapestry5.internal.parser.TemplateToken) DTDToken(org.apache.tapestry5.internal.parser.DTDToken)

Aggregations

Resource (org.apache.tapestry5.commons.Resource)3 MultiKey (org.apache.tapestry5.commons.util.MultiKey)3 ComponentResourceSelector (org.apache.tapestry5.services.pageload.ComponentResourceSelector)3 ComponentModel (org.apache.tapestry5.model.ComponentModel)2 Messages (org.apache.tapestry5.commons.Messages)1 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)1 DTDToken (org.apache.tapestry5.internal.parser.DTDToken)1 TemplateToken (org.apache.tapestry5.internal.parser.TemplateToken)1 Page (org.apache.tapestry5.internal.structure.Page)1 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)1 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)1 Test (org.testng.annotations.Test)1