use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class BeanBlockSourceImplTest method found_edit_block.
@Test
public void found_edit_block() {
Block block = mockBlock();
RequestPageCache cache = mockRequestPageCache();
Page page = mockPage();
BeanBlockContribution contribution = new EditBlockContribution("mydata", "MyPage", "mydisplay");
Collection<BeanBlockContribution> configuration = newList(contribution);
train_get(cache, "MyPage", page);
train_getBlock(page, "mydisplay", block);
replay();
BeanBlockSource source = new BeanBlockSourceImpl(cache, createBeanBlockOverrideSource(cache), configuration);
// Check case insensitivity while we are at it.
Block actual = source.getEditBlock("MyData");
assertSame(actual, block);
verify();
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class BeanBlockSourceImplTest method found_display_block.
@Test
public void found_display_block() {
Block block = mockBlock();
RequestPageCache cache = mockRequestPageCache();
Page page = mockPage();
BeanBlockContribution contribution = new DisplayBlockContribution("mydata", "MyPage", "mydisplay");
Collection<BeanBlockContribution> configuration = newList(contribution);
train_get(cache, "MyPage", page);
train_getBlock(page, "mydisplay", block);
replay();
BeanBlockSource source = new BeanBlockSourceImpl(cache, createBeanBlockOverrideSource(cache), configuration);
// Check case insensitivity while we are at it.
assertTrue(source.hasDisplayBlock("MyData"));
Block actual = source.getDisplayBlock("MyData");
assertSame(actual, block);
verify();
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method element.
private DynamicTemplateElement element() {
String elementURI = tokenStream.getNamespaceURI();
String elementName = tokenStream.getLocalName();
String blockId = null;
int count = tokenStream.getAttributeCount();
List<DynamicTemplateAttribute> attributes = CollectionFactory.newList();
Location location = getLocation();
for (int i = 0; i < count; i++) {
QName qname = tokenStream.getAttributeName(i);
// The name will be blank for an xmlns: attribute
String localName = qname.getLocalPart();
if (InternalUtils.isBlank(localName))
continue;
String uri = qname.getNamespaceURI();
String value = tokenStream.getAttributeValue(i);
if (localName.equals("id")) {
Matcher matcher = PARAM_ID_PATTERN.matcher(value);
if (matcher.matches()) {
blockId = matcher.group(1);
continue;
}
}
Mapper<DynamicDelegate, String> attributeValueExtractor = createCompositeExtractorFromText(value, location);
attributes.add(new DynamicTemplateAttribute(uri, localName, attributeValueExtractor));
}
if (blockId != null)
return block(blockId);
List<DynamicTemplateElement> body = CollectionFactory.newList();
boolean atEnd = false;
while (!atEnd) {
switch(tokenStream.next()) {
case START_ELEMENT:
// Recurse into this new element
body.add(element());
break;
case END_ELEMENT:
body.add(END);
atEnd = true;
break;
default:
addTextContent(body);
}
}
return createElementWriterElement(elementURI, elementName, attributes, body);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class PageLoaderImpl method parameter.
private void parameter(AssemblerContext context) {
final ParameterToken token = context.next(ParameterToken.class);
context.add(new PageAssemblyAction() {
public void execute(PageAssembly pageAssembly) {
String parameterName = token.name;
ComponentPageElement element = pageAssembly.createdElement.peek();
Location location = token.getLocation();
BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
if (binder == null) {
throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
}
binder.bind(pageAssembly.createdElement.peek(), binding);
pageAssembly.bodyElement.push(block);
}
});
consumeToEndElementAndPopBodyElement(context);
}
use of org.apache.tapestry5.Block in project tapestry-5 by apache.
the class PropertyEditorTest method no_editor_block_available.
@Test
public void no_editor_block_available() {
PropertyModel model = mockPropertyModel();
PropertyOverrides overrides = mockPropertyOverrides();
ComponentResources resources = mockComponentResources();
BeanBlockSource source = newMock(BeanBlockSource.class);
RuntimeException exception = new RuntimeException("Simulated failure.");
Messages messages = mockMessages();
Location l = mockLocation();
String propertyId = "foo";
String dataType = "unk";
String propertyName = "fooProp";
Object object = "[OBJECT]";
String formattedMessage = "formatted-message";
expect(model.getId()).andReturn(propertyId);
train_getOverrideBlock(overrides, propertyId, null);
expect(model.getDataType()).andReturn(dataType);
expect(source.getEditBlock(dataType)).andThrow(exception);
expect(model.getPropertyName()).andReturn(propertyName);
train_getLocation(resources, l);
expect(messages.format("core-block-error", propertyName, dataType, object, exception)).andReturn(formattedMessage);
replay();
PropertyEditor pe = new PropertyEditor();
pe.inject(resources, overrides, model, source, messages, object);
try {
pe.beginRender();
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), formattedMessage);
assertSame(ex.getLocation(), l);
}
}
Aggregations