use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class SaxTemplateParser method parse.
public ComponentTemplate parse(boolean compressWhitespace) {
try {
tokenStream.parse();
TemplateParserState initialParserState = new TemplateParserState().compressWhitespace(compressWhitespace);
root(initialParserState);
return new ComponentTemplateImpl(resource, tokens, componentIds, extension, strictMixinParameters, overrides);
} catch (Exception ex) {
throw new TapestryException(String.format("Failure parsing template %s: %s", resource, ExceptionUtils.toMessage(ex)), tokenStream.getLocation(), ex);
}
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class SaxTemplateParser method parameterElement.
/**
* Tapestry 5.1 uses a special namespace (usually mapped to "p:") and the
* name becomes the parameter element.
*/
private void parameterElement(TemplateParserState state) {
ensureParameterWithinComponent(state);
if (tokenStream.getAttributeCount() > 0)
throw new TapestryException("A block parameter element does not allow any additional attributes. The element name defines the parameter name.", getLocation(), null);
tokenAccumulator.add(new ParameterToken(tokenStream.getLocalName(), getLocation()));
processBody(state.insideComponent(false));
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class Form method executeStoredActions.
/**
* Pulls the stored actions out of the request, converts them from MIME
* stream back to object stream and then
* objects, and executes them.
*/
private void executeStoredActions(boolean forFormCancel) {
String[] values = request.getParameters(FORM_DATA);
if (!request.getMethod().equals("POST") || values == null)
throw new RuntimeException(messages.format("core-invalid-form-request", FORM_DATA));
for (String clientEncodedActions : values) {
if (InternalUtils.isBlank(clientEncodedActions))
continue;
logger.debug("Processing actions: {}", clientEncodedActions);
ObjectInputStream ois = null;
Component component = null;
try {
ois = clientDataEncoder.decodeClientData(clientEncodedActions);
while (!eventCallback.isAborted()) {
String componentId = ois.readUTF();
boolean cancelAction = ois.readBoolean();
ComponentAction action = (ComponentAction) ois.readObject();
// based on whether the form was submitted or cancelled.
if (forFormCancel != cancelAction) {
continue;
}
component = source.getComponent(componentId);
logger.debug("Processing: {} {}", componentId, action);
action.execute(component);
component = null;
}
} catch (EOFException ex) {
// Expected
} catch (Exception ex) {
Location location = component == null ? null : component.getComponentResources().getLocation();
throw new TapestryException(ex.getMessage(), location, ex);
} finally {
InternalUtils.close(ois);
}
}
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class PropertyEditor method beginRender.
/**
* Returns a Block for rendering the property. The Block will be able to access the {@link PropertyEditContext} via
* the {@link Environmental} annotation.
*/
Block beginRender() {
Block override = overrides.getOverrideBlock(propertyModel.getId());
if (override != null) {
return override;
}
String dataType = propertyModel.getDataType();
if (dataType == null)
throw new RuntimeException(String.format("The data type for property '%s' of %s is null.", propertyModel.getPropertyName(), object));
try {
return beanBlockSource.getEditBlock(dataType);
} catch (RuntimeException ex) {
String message = messages.format("core-block-error", propertyModel.getPropertyName(), dataType, object, ex);
throw new TapestryException(message, resources.getLocation(), ex);
}
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class BindingFactoryTest method literal_binding.
@Test
public void literal_binding() {
ComponentResources res = mockInternalComponentResources();
Location l = mockLocation();
replay();
BindingFactory factory = new LiteralBindingFactory();
Binding b = factory.newBinding("test binding", res, null, "Tapestry5", l);
assertSame(InternalUtils.locationOf(b), l);
assertEquals(b.get(), "Tapestry5");
assertTrue(b.isInvariant());
assertSame(b.getBindingType(), String.class);
try {
b.set(null);
unreachable();
} catch (TapestryException ex) {
assertSame(ex.getLocation(), l);
}
verify();
}
Aggregations