use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class PageRenderLinkSourceImplTest method override_passivate_context.
@Test
public void override_passivate_context() {
ComponentClassResolver resolver = mockComponentClassResolver();
LinkSource source = mockLinkSource();
Link link = mockLink();
EventContext eventContext = mockEventContext();
train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
expect(source.createPageRenderLink(PAGE_NAME, true, "fred", "barney")).andReturn(link);
train_resolvePageClassNameToPageName(resolver, PAGE_CLASS.getName(), PAGE_NAME);
train_getCount(eventContext, 2);
train_get(eventContext, Object.class, 0, "ted");
train_get(eventContext, Object.class, 1, "barney");
expect(source.createPageRenderLink(PAGE_NAME, true, "ted", "barney")).andReturn(link);
replay();
PageRenderLinkSource service = new PageRenderLinkSourceImpl(source, resolver);
assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, "fred", "barney"), link);
assertSame(service.createPageRenderLinkWithContext(PAGE_CLASS, eventContext), link);
verify();
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class PageRenderRequestHandlerImplTest method loopback_request.
@Test
public void loopback_request() throws Exception {
RequestPageCache cache = mockRequestPageCache();
ComponentEventResultProcessor processor = mockComponentEventResultProcessor();
PageResponseRenderer renderer = mockPageResponseRenderer();
Page page = mockPage();
EventContext context = mockEventContext();
ComponentPageElement root = mockComponentPageElement();
InternalComponentResources pageResources = mockInternalComponentResources();
PageActivator activator = newMock(PageActivator.class);
Request request = mockRequest();
train_getAttribute(request, InternalConstants.BYPASS_ACTIVATION, null);
train_get(cache, "foo/Bar", page);
train_getRootElement(page, root);
train_getComponentResources(root, pageResources);
expect(activator.activatePage(pageResources, context, processor)).andReturn(false);
// Skips the pageReset()
renderer.renderPageResponse(page);
replay();
PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer, activator, request);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("foo/Bar", context, true);
handler.handle(parameters);
verify();
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImpl method createComponentEventLink.
public Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm) {
StringBuilder builder = new StringBuilder(BUFFER_SIZE);
// Build up the absolute URI.
String activePageName = parameters.getActivePageName();
String containingPageName = parameters.getContainingPageName();
String eventType = parameters.getEventType();
String nestedComponentId = parameters.getNestedComponentId();
boolean hasComponentId = InternalUtils.isNonBlank(nestedComponentId);
builder.append(contextPath);
encodeAppFolderAndLocale(builder);
builder.append(SLASH);
builder.append(activePageName.toLowerCase());
if (hasComponentId) {
builder.append('.');
builder.append(nestedComponentId);
}
if (!hasComponentId || !eventType.equals(EventConstants.ACTION)) {
builder.append(':');
builder.append(encodePageName(eventType));
}
appendContext(true, parameters.getEventContext(), builder);
Link result = new LinkImpl(builder.toString(), forForm, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
EventContext pageActivationContext = parameters.getPageActivationContext();
if (pageActivationContext.getCount() != 0) {
// Reuse the builder
builder.setLength(0);
appendContext(true, pageActivationContext, builder);
// Omit that first slash
result.addParameter(InternalConstants.PAGE_CONTEXT_NAME, builder.substring(1));
}
if (!containingPageName.equalsIgnoreCase(activePageName))
result.addParameter(InternalConstants.CONTAINER_PAGE_NAME, encodePageName(containingPageName));
return result;
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class StreamPageContentResultProcessor method processResultValue.
public void processResultValue(StreamPageContent value) throws IOException {
Class<?> pageClass = value.getPageClass();
Object[] activationContext = value.getPageActivationContext();
final String pageName = pageClass == null ? requestGlobals.getActivePageName() : resolver.resolvePageClassNameToPageName(pageClass.getName());
final EventContext context = activationContext == null ? new EmptyEventContext() : new ArrayEventContext(typeCoercer, activationContext);
if (value.isBypassActivation()) {
request.setAttribute(InternalConstants.BYPASS_ACTIVATION, true);
}
request.setAttribute(TapestryConstants.RESPONSE_RENDERER, new IOOperation<Void>() {
public Void perform() throws IOException {
handler.handle(new PageRenderRequestParameters(pageName, context, false));
return null;
}
});
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class UnknownActivationContextHandlerImpl method handleUnknownContext.
public void handleUnknownContext(ComponentResources pageResources, EventContext activationContext) throws IOException {
logger.warn("Activate event on page {} was fired with context {} but was not handled", pageResources.getPage().getClass(), activationContext);
String message = String.format("Activation context %s unrecognized for page %s", activationContext, pageResources.getPage().getClass());
resultProcessor.processResultValue(new HttpError(HttpServletResponse.SC_NOT_FOUND, message));
}
Aggregations