use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.
the class LinkSourceImplTest method testPageLinkCreation.
private void testPageLinkCreation(String pageName, boolean overrideContext, Object... context) {
PageActivationContextCollector collector = mockPageActivationContextCollector();
LinkCreationListener2 listener = mockLinkCreationListener2();
ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
Link link = mockLink();
ComponentClassResolver resolver = mockComponentClassResolver();
String canonical = "CanonicalPageName";
RequestGlobals globals = mockRequestGlobals();
// Ensure that the loopback logic is off; loopback logic is fully tested via an
// integration test.
expect(globals.getActivePageName()).andReturn("someOtherPage");
train_canonicalizePageName(resolver, pageName, canonical);
if (!overrideContext)
train_collectPageActivationContext(collector, canonical, context);
PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), false);
expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
listener.createdPageRenderLink(link, parameters);
replay();
LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
source.getLinkCreationHub().addListener(listener);
Object[] passedContext = overrideContext ? context : new Object[0];
Link returnedLink = source.createPageRenderLink(pageName, overrideContext, passedContext);
assertSame(returnedLink, link);
verify();
}
use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImpl method decodePageRenderRequest.
public PageRenderRequestParameters decodePageRenderRequest(Request request) {
boolean explicitLocale = false;
// The extended name may include a page activation context. The trick is
// to figure out where the logical page name stops and where the
// activation context begins. Further, strip out the leading slash.
String path = request.getPath();
if (applicationFolderPrefix != null) {
path = removeApplicationPrefix(path);
}
// TAPESTRY-1343: Sometimes path is the empty string (it should always be at least a slash,
// but Tomcat may return the empty string for a root context request).
String extendedName = path.length() == 0 ? path : path.substring(1);
// Ignore trailing slashes in the path.
while (extendedName.endsWith("/")) {
extendedName = extendedName.substring(0, extendedName.length() - 1);
}
int slashx = extendedName.indexOf('/');
// So, what can we have left?
// 1. A page name
// 2. A locale followed by a page name
// 3. A page name followed by activation context
// 4. A locale name, page name, activation context
// 5. Just activation context (for root Index page)
// 6. A locale name followed by activation context
String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName;
if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) {
extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : "";
explicitLocale = true;
}
slashx = extendedName.length();
boolean atEnd = true;
while (slashx > 0) {
String pageName = extendedName.substring(0, slashx);
String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1);
PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext);
if (parameters != null) {
return parameters;
}
// Work backwards, splitting at the next slash.
slashx = extendedName.lastIndexOf('/', slashx - 1);
atEnd = false;
}
// OK, maybe its all page activation context for the root Index page.
PageRenderRequestParameters result = checkIfPage(request, "", extendedName);
if (result != null && !explicitLocale) {
setLocaleFromRequest(request);
}
return result;
}
use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImpl method createPageRenderLink.
public Link createPageRenderLink(PageRenderRequestParameters parameters) {
StringBuilder builder = new StringBuilder(BUFFER_SIZE);
// Build up the absolute URI.
String activePageName = parameters.getLogicalPageName();
builder.append(contextPath);
encodeAppFolderAndLocale(builder);
builder.append(SLASH);
String encodedPageName = encodePageName(activePageName);
builder.append(encodedPageName);
appendContext(encodedPageName.length() > 0, parameters.getActivationContext(), builder);
Link link = new LinkImpl(builder.toString(), false, requestSecurityManager.checkPageSecurity(activePageName), response, contextPathEncoder, baseURLSource);
if (parameters.isLoopback()) {
link.addParameter(TapestryConstants.PAGE_LOOPBACK_PARAMETER_NAME, "t");
}
return link;
}
use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.
the class LinkSourceImpl method createPageRenderLink.
public Link createPageRenderLink(String pageName, boolean override, Object... pageActivationContext) {
// Resolve the page name to its canonical format (the best version for URLs). This also
// validates
// the page name.
String canonical = resolver.canonicalizePageName(pageName);
Object[] context = (override || pageActivationContext.length != 0) ? pageActivationContext : contextCollector.collectPageActivationContext(canonical);
boolean loopback = canonical.equals(requestGlobals.getActivePageName()) && pageCache.get(pageName).hasResetListeners();
PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), loopback);
Link link = linkEncoder.createPageRenderLink(parameters);
for (LinkCreationListener2 listener : listeners) listener.createdPageRenderLink(link, parameters);
return link;
}
use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method just_the_locale_name.
@Test
public void just_the_locale_name() throws Exception {
ComponentClassResolver resolver = mockComponentClassResolver();
Request request = mockRequest();
Response response = mockResponse();
LocalizationSetter ls = mockLocalizationSetter();
train_getPath(request, "/en");
train_setLocaleFromLocaleName(ls, "en", true);
train_isPageName(resolver, "", false);
replay();
ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
assertNull(parameters);
verify();
}
Aggregations