use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method no_matching_property_for_default.
@Test
public void no_matching_property_for_default() {
String parameterName = "myparam";
String id = "mycomponentid";
ComponentResources resources = mockComponentResources();
Component container = mockComponent();
PropertyAccess access = mockPropertyAccess();
ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
BindingSource bindingSource = mockBindingSource();
train_getId(resources, id);
train_getContainer(resources, container);
train_getAdapter(access, container, classPropertyAdapter);
train_getPropertyAdapter(classPropertyAdapter, id, null);
replay();
ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
assertNull(source.defaultBinding(parameterName, resources));
verify();
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class BindingSourceImplTest method expression_has_no_prefix.
@Test
public void expression_has_no_prefix() {
BindingFactory factory = mockBindingFactory();
Binding binding = mockBinding();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Location l = mockLocation();
String defaultPrefix = "def";
String description = "descrip";
String expression = "full expression";
train_newBinding(factory, description, container, component, expression, l, binding);
replay();
Map<String, BindingFactory> map = newMap();
map.put(defaultPrefix, factory);
BindingSource source = new BindingSourceImpl(map, interner);
Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
assertSame(actual, binding);
verify();
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class BindingSourceImplTest method expression_prefix_not_in_configuration.
@Test
public void expression_prefix_not_in_configuration() {
BindingFactory factory = mockBindingFactory();
Binding binding = mockBinding();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Location l = mockLocation();
String defaultPrefix = "def";
String description = "descrip";
String expression = "javascript:not-a-known-prefix";
train_newBinding(factory, description, container, component, expression, l, binding);
replay();
Map<String, BindingFactory> map = newMap();
map.put(defaultPrefix, factory);
BindingSource source = new BindingSourceImpl(map, interner);
Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
assertSame(actual, binding);
verify();
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method createExpansionExtractor.
private static Mapper<DynamicDelegate, String> createExpansionExtractor(final String expression, final Location location, final BindingSource bindingSource) {
return new Mapper<DynamicDelegate, String>() {
public String map(DynamicDelegate delegate) {
try {
Binding binding = bindingSource.newBinding("dynamic template binding", delegate.getComponentResources().getContainerResources(), delegate.getComponentResources(), BindingConstants.PROP, expression, location);
Object boundValue = binding.get();
return boundValue == null ? null : boundValue.toString();
} catch (Throwable t) {
throw new TapestryException(ExceptionUtils.toMessage(t), location, t);
}
}
};
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method createCompositeExtractorFromText.
private Mapper<DynamicDelegate, String> createCompositeExtractorFromText(String text, Location location) {
Matcher matcher = EXPANSION_PATTERN.matcher(text);
List<Mapper<DynamicDelegate, String>> extractors = CollectionFactory.newList();
int startx = 0;
while (matcher.find()) {
int matchStart = matcher.start();
if (matchStart != startx) {
String prefix = text.substring(startx, matchStart);
extractors.add(createTextExtractor(prefix));
}
// Group 1 includes the real text of the expansion, with whitespace
// around the
// expression (but inside the curly braces) excluded.
String expression = matcher.group(1);
extractors.add(createExpansionExtractor(expression, location, bindingSource));
startx = matcher.end();
}
if (startx < text.length())
extractors.add(createTextExtractor(text.substring(startx, text.length())));
if (extractors.size() == 1)
return extractors.get(0);
return creatCompositeExtractor(extractors);
}
Aggregations