Search in sources :

Example 26 with TapestryException

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);
    }
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 27 with TapestryException

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));
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 28 with TapestryException

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);
        }
    }
}
Also used : EOFException(java.io.EOFException) Component(org.apache.tapestry5.runtime.Component) IOException(java.io.IOException) EOFException(java.io.EOFException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ObjectInputStream(java.io.ObjectInputStream) Location(org.apache.tapestry5.commons.Location)

Example 29 with TapestryException

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);
    }
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 30 with TapestryException

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();
}
Also used : Binding(org.apache.tapestry5.Binding) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Aggregations

TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)37 Location (org.apache.tapestry5.commons.Location)12 Test (org.testng.annotations.Test)12 ComponentResources (org.apache.tapestry5.ComponentResources)11 Binding (org.apache.tapestry5.Binding)7 BindingFactory (org.apache.tapestry5.services.BindingFactory)4 IOException (java.io.IOException)3 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)3 Component (org.apache.tapestry5.runtime.Component)3 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 TrackableComponentEventCallback (org.apache.tapestry5.TrackableComponentEventCallback)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2 Link (org.apache.tapestry5.http.Link)2 Instantiator (org.apache.tapestry5.internal.services.Instantiator)2 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)2 Page (org.apache.tapestry5.internal.structure.Page)2 OperationException (org.apache.tapestry5.ioc.internal.OperationException)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 BindingSource (org.apache.tapestry5.services.BindingSource)2