use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.
the class SaxTemplateParser method element.
/**
* Processes an element through to its matching end tag.
*
* An element can be:
*
* a Tapestry component via <t:type>
*
* a Tapestry component via t:type="type" and/or t:id="id"
*
* a Tapestry component via a library namespace
*
* A parameter element via <t:parameter>
*
* A parameter element via <p:name>
*
* A <t:remove> element (in the 5.1 schema)
*
* A <t:content> element (in the 5.1 schema)
*
* A <t:block> element
*
* The body <t:body>
*
* An ordinary element
*/
void element(TemplateParserState initialState) {
TemplateParserState state = setupForElement(initialState);
String uri = tokenStream.getNamespaceURI();
String name = tokenStream.getLocalName();
Version version = NAMESPACE_URI_TO_VERSION.get(uri);
if (T_5_1.sameOrEarlier(version)) {
if (name.equalsIgnoreCase("remove")) {
removeContent();
return;
}
if (name.equalsIgnoreCase("content")) {
limitContent(state);
return;
}
if (name.equalsIgnoreCase("extension-point")) {
extensionPoint(state);
return;
}
if (name.equalsIgnoreCase("replace")) {
throw new RuntimeException("The <replace> element may only appear directly within an extend element.");
}
if (MUST_BE_ROOT.contains(name))
mustBeRoot(name);
}
if (version != null) {
if (name.equalsIgnoreCase("body")) {
body();
return;
}
if (name.equalsIgnoreCase("container")) {
mustBeRoot(name);
}
if (name.equalsIgnoreCase("block")) {
block(state);
return;
}
if (name.equalsIgnoreCase("parameter")) {
if (T_5_3.sameOrEarlier(version)) {
throw new RuntimeException(String.format("The <parameter> element has been deprecated in Tapestry 5.3 in favour of '%s' namespace.", TAPESTRY_PARAMETERS_URI));
}
classicParameter(state);
return;
}
possibleTapestryComponent(state, null, tokenStream.getLocalName().replace('.', '/'));
return;
}
if (uri != null && uri.startsWith(LIB_NAMESPACE_URI_PREFIX)) {
libraryNamespaceComponent(state);
return;
}
if (TAPESTRY_PARAMETERS_URI.equals(uri)) {
parameterElement(state);
return;
}
// Just an ordinary element ... unless it has t:id or t:type
possibleTapestryComponent(state, tokenStream.getLocalName(), null);
}
use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.
the class SaxTemplateParser method possibleTapestryComponent.
/**
* @param elementName
* @param identifiedType
* the type of the element, usually null, but may be the
* component type derived from element
*/
private void possibleTapestryComponent(TemplateParserState state, String elementName, String identifiedType) {
String id = null;
String type = identifiedType;
String mixins = null;
int count = tokenStream.getAttributeCount();
Location location = getLocation();
List<TemplateToken> attributeTokens = CollectionFactory.newList();
for (int i = 0; i < count; i++) {
QName qname = tokenStream.getAttributeName(i);
if (isXMLSpaceAttribute(qname))
continue;
// 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);
Version version = NAMESPACE_URI_TO_VERSION.get(uri);
if (version != null) {
if (T_5_4.sameOrEarlier(version)) {
strictMixinParameters = true;
}
if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME)) {
id = nullForBlank(value);
validateId(id, "Component id '%s' is not valid; component ids must be valid Java identifiers: start with a letter, and consist of letters, numbers and underscores.");
continue;
}
if (type == null && localName.equalsIgnoreCase(TYPE_ATTRIBUTE_NAME)) {
type = nullForBlank(value);
continue;
}
if (localName.equalsIgnoreCase(MIXINS_ATTRIBUTE_NAME)) {
mixins = nullForBlank(value);
continue;
}
// Anything else is the name of a Tapestry component parameter
// that is simply
// not part of the template's doctype for the element being
// instrumented.
}
attributeTokens.add(new AttributeToken(uri, localName, value, location));
}
boolean isComponent = (id != null || type != null);
if (mixins != null && !isComponent)
throw new TapestryException(String.format("You may not specify mixins for element <%s> because it does not represent a component (which requires either an id attribute or a type attribute).", elementName), location, null);
if (isComponent) {
tokenAccumulator.add(new StartComponentToken(elementName, id, type, mixins, location));
} else {
tokenAccumulator.add(new StartElementToken(tokenStream.getNamespaceURI(), elementName, location));
}
addDefineNamespaceTokens();
tokenAccumulator.addAll(attributeTokens);
if (id != null)
componentIds.put(id, location);
processBody(state.insideComponent(isComponent));
}
use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.
the class AbstractBeanModelSourceImplTest method default_model_for_bean.
/**
* Tests defaults for property names, labels and conduits.
*/
@Test
public void default_model_for_bean() {
Messages messages = mockMessages();
stub_contains(messages, false);
replay();
BeanModel model = source.create(SimpleBean.class, true, messages);
assertSame(model.getBeanType(), SimpleBean.class);
// Based on order of the getter methods (no longer alphabetical)
assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
assertEquals(model.toString(), "BeanModel[org.apache.tapestry5.internal.services.SimpleBean properties:firstName, lastName, age]");
PropertyModel age = model.get("age");
assertEquals(age.getLabel(), "Age");
assertSame(age.getPropertyType(), int.class);
assertEquals(age.getDataType(), "number");
PropertyModel firstName = model.get("firstName");
assertEquals(firstName.getLabel(), "First Name");
assertEquals(firstName.getPropertyType(), String.class);
assertEquals(firstName.getDataType(), "text");
assertEquals(model.get("lastName").getLabel(), "Last Name");
PropertyConduit conduit = model.get("lastName").getConduit();
SimpleBean instance = new SimpleBean();
instance.setLastName("Lewis Ship");
assertEquals(conduit.get(instance), "Lewis Ship");
conduit.set(instance, "TapestryDude");
assertEquals(instance.getLastName(), "TapestryDude");
// Now, one with some type coercion.
age.getConduit().set(instance, "40");
assertEquals(instance.getAge(), 40);
verify();
}
use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.
the class BeanBlockSourceImplTest method display_block_not_found.
@Test
public void display_block_not_found() {
RequestPageCache cache = mockRequestPageCache();
Collection<BeanBlockContribution> configuration = newList();
replay();
BeanBlockSource source = new BeanBlockSourceImpl(cache, createBeanBlockOverrideSource(cache), configuration);
try {
assertFalse(source.hasDisplayBlock("MyData"));
source.getDisplayBlock("MyData");
unreachable();
} catch (RuntimeException ex) {
assertEquals(ex.getMessage(), "There is no defined way to display data of type \'MyData\'. Make a contribution to the BeanBlockSource service for this type.");
}
verify();
}
use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.
the class UploadTest method begin_render_writes_input_tag.
@Test
public void begin_render_writes_input_tag() throws Exception {
MarkupWriter writer = createMarkupWriter();
writer.element("form");
FormSupport formSupport = mockFormSupport();
ComponentResources resources = mockComponentResources();
FieldValidator validator = mockFieldValidator();
Request request = mockRequest();
train_isXHR(request, false);
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
validator.render(writer);
resources.renderInformalParameters(writer);
replay();
Upload component = new Upload(null, null, null, null, resources, null);
component.injectDecorator(new BaseValidationDecorator()).injectFormSupport(formSupport).injectFieldValidator(validator).injectRequest(request);
component.beginRender(writer);
Element element = writer.getElement();
assertNotNull(element);
assertEquals(element.getName(), "input");
assertEquals(element.getAttribute("type"), "file");
// assertEquals(element.getAttribute("name"),null);
// assertEquals(element.getAttribute("id"),null);
verify();
}
Aggregations