use of org.apache.tapestry5.services.ContextPathEncoder 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.services.ContextPathEncoder in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method root_index_page_gone.
@Test
public void root_index_page_gone() {
RequestSecurityManager manager = mockRequestSecurityManager();
Response response = mockResponse();
ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
expect(manager.checkPageSecurity("Index")).andReturn(LinkSecurity.INSECURE);
train_encodeURL(response, "/", "MAGIC");
replay();
ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("Index", new EmptyEventContext());
Link link = encoder.createPageRenderLink(parameters);
assertEquals(link.toURI(), "MAGIC");
verify();
}
use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method page_requires_whitelist_and_client_on_whitelist.
@Test
public void page_requires_whitelist_and_client_on_whitelist() throws Exception {
ComponentClassResolver resolver = mockComponentClassResolver();
Request request = mockRequest(false);
LocalizationSetter ls = mockLocalizationSetter();
MetaDataLocator metaDataLocator = mockMetaDataLocator();
ClientWhitelist whitelist = newMock(ClientWhitelist.class);
String path = "/foo/Bar";
train_getPath(request, path);
train_setLocaleFromLocaleName(ls, "foo", false);
train_isPageName(resolver, "foo/Bar", true);
train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, "foo/bar", boolean.class)).andReturn(true);
expect(whitelist.isClientRequestOnWhitelist()).andReturn(true);
replay();
ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, whitelist);
PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
assertEquals(parameters.getLogicalPageName(), "foo/bar");
assertEquals(parameters.getActivationContext().getCount(), 0);
assertFalse(parameters.isLoopback());
verify();
}
use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method index_stripped_off.
@Test
public void index_stripped_off() {
RequestSecurityManager manager = mockRequestSecurityManager();
Response response = mockResponse();
ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
train_encodeURL(response, "/admin/abc", "MAGIC");
replay();
ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
Link link = encoder.createPageRenderLink(parameters);
assertEquals(link.toURI(), "MAGIC");
verify();
}
use of org.apache.tapestry5.services.ContextPathEncoder in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method illegal_activation_context_leads_to_http_404.
@Test
public // TAP5-2436
void illegal_activation_context_leads_to_http_404() throws Exception {
ComponentClassResolver resolver = mockComponentClassResolver();
Request request = mockRequest();
Response response = mockResponse();
LocalizationSetter ls = mockLocalizationSetter();
MetaDataLocator metaDataLocator = neverWhitelistProtected();
train_getPath(request, "/foo/pageid=123");
train_setLocaleFromLocaleName(ls, "foo", false);
train_isPageName(resolver, "foo/pageid=123", false);
train_isPageName(resolver, "foo", false);
train_isPageName(resolver, "", true);
train_canonicalizePageName(resolver, "", "Index");
replay();
ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null);
PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
assertNull(parameters);
verify();
}
Aggregations