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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations