use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.
the class PageContentTypeAnalyzerImpl method findContentType.
public ContentType findContentType(Page page) {
ComponentResources pageResources = page.getRootComponent().getComponentResources();
String contentTypeString = metaDataLocator.findMeta(MetaDataConstants.RESPONSE_CONTENT_TYPE, pageResources, String.class);
return new ContentType(contentTypeString).withCharset(outputCharset);
}
use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.
the class PageElementFactoryImpl method parseAttributeExpansionExpression.
private StringProvider parseAttributeExpansionExpression(String expression, ComponentResources resources, final Location location) {
final List<StringProvider> providers = newList();
int startx = 0;
while (true) {
int expansionx = expression.indexOf(InternalConstants.EXPANSION_START, startx);
if (expansionx < 0) {
if (startx < expression.length())
providers.add(new LiteralStringProvider(expression.substring(startx)));
break;
}
if (startx != expansionx)
providers.add(new LiteralStringProvider(expression.substring(startx, expansionx)));
int endx = expression.indexOf("}", expansionx);
if (endx < 0)
throw new TapestryException(String.format("Attribute expression '%s' is missing a closing brace.", expression), location, null);
String expansion = expression.substring(expansionx + 2, endx);
final Binding binding = bindingSource.newBinding("attribute expansion", resources, resources, BindingConstants.PROP, expansion, location);
final StringProvider provider = new StringProvider() {
public String provideString() {
try {
Object raw = binding.get();
return typeCoercer.coerce(raw, String.class);
} catch (Exception ex) {
throw new TapestryException(ex.getMessage(), location, ex);
}
}
};
providers.add(provider);
// Restart the search after '}'
startx = endx + 1;
}
if (providers.size() == 1)
return providers.get(0);
return new StringProvider() {
public String provideString() {
StringBuilder builder = new StringBuilder();
for (StringProvider provider : providers) builder.append(provider.provideString());
return builder.toString();
}
};
}
use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.
the class PersistentFieldManagerImpl method postChange.
public void postChange(String pageName, ComponentResources resources, String fieldName, Object newValue) {
String strategyName = findStrategy(resources, fieldName);
PersistentFieldStrategy strategy = getStrategy(strategyName);
strategy.postChange(pageName, resources.getNestedId(), fieldName, newValue);
}
use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_translator.
@Test
public void default_translator() {
ComponentResources resources = mockComponentResources();
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
train_createDefaultTranslator(source, resources, "object", translator);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
assertSame(provider.defaultTranslator("object", resources), translator);
verify();
}
use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_label_key_missing.
@Test
public void default_label_key_missing() {
ComponentResources resources = mockComponentResources();
ComponentResources container = mockComponentResources();
Messages messages = mockMessages();
String componentId = "myField";
String key = componentId + "-label";
train_getId(resources, componentId);
train_getContainerResources(resources, container);
train_getMessages(container, messages);
train_contains(messages, key, false);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null);
assertEquals(provider.defaultLabel(resources), "My Field");
verify();
}
Aggregations