I got link transformation working. For those of you who are interested
in it's basically something like this:
public class YourLinkTransformer implements PageRenderLinkTransformer,
ComponentEventLinkTransformer
{
private final ComponentEventLinkEncoder _cele;
private final ObjectLocator _objectLocator;
public YourLinkTransformer(final ObjectLocator objectLocator,
@Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH) boolean
encodeLocaleIntoPath)
{
_objectLocator = objectLocator;
_cele =
objectLocator.autobuild(ComponentEventLinkEncoderImpl.class);
}
public Link transformPageRenderLink(final Link defaultLink, final
PageRenderRequestParameters parameters)
{
return _cele.createPageRenderLink(parameters);
}
public Link transformComponentEventLink(final Link defaultLink,
final ComponentEventRequestParameters parameters)
{
return _cele.createComponentEventLink(parameters, false);
}
public PageRenderRequestParameters decodePageRenderRequest(final
Request request)
{
final Request request1 = modifyRequest(request);
return _cele.decodePageRenderRequest(request1);
}
public ComponentEventRequestParameters
decodeComponentEventRequest(final Request request)
{
final Request request1 = modifyRequest(request);
return _cele.decodeComponentEventRequest(request1);
}
//
//
//
private Request modifyRequest(final Request request)
{
final String[] pathElements =
StringUtils.split(request.getPath(), '/');
// do whatever you need to change your pathelement and create a
new URL. this code does nothing at all as in == out
final StringBuilder sb = new StringBuilder("/");
for (int i = 0; i < pathElements.length; ++i) {
sb.append("/").append(pathElements[i]);
}
return new ChangedRequest(request, sb.toString());
}
private static class ChangedRequest implements Request
{
private final Request _request;
private final String _newPath;
private ChangedRequest(final Request request, final String newPath)
{
_request = request;
_newPath = newPath;
}
public Session getSession(final boolean create)
{
return _request.getSession(create);
}
public String getContextPath()
{
return _request.getContextPath();
}
public List<String> getParameterNames()
{
return _request.getParameterNames();
}
public String getParameter(final String name)
{
return _request.getParameter(name);
}
public String[] getParameters(final String name)
{
return _request.getParameters(name);
}
public String getPath()
{
return _newPath;
}
public Locale getLocale()
{
return _request.getLocale();
}
public List<String> getHeaderNames()
{
return _request.getHeaderNames();
}
public long getDateHeader(final String name)
{
return _request.getDateHeader(name);
}
public String getHeader(final String name)
{
return _request.getHeader(name);
}
public boolean isXHR()
{
return _request.isXHR();
}
public boolean isSecure()
{
return _request.isSecure();
}
public String getServerName()
{
return _request.getServerName();
}
public boolean isRequestedSessionIdValid()
{
return _request.isRequestedSessionIdValid();
}
public Object getAttribute(final String name)
{
return _request.getAttribute(name);
}
public void setAttribute(final String name, final Object value)
{
_request.setAttribute(name, value);
}
public String getMethod()
{
return _request.getMethod();
}
public int getLocalPort()
{
return _request.getLocalPort();
}
public int getServerPort()
{
return _request.getServerPort();
}
}
}
Am 11.08.11 12:28, schrieb Jens Breitenstein:
Hi All!
I am stuck with URL transformation and hopefully someone can point me
into the right direction...
Basically I have something like this:
http://localhost:8080/MYCONTEXT/de/whatever
In case the user sets a global filtering criteria I want to
transparently make it appear in the URL like:
http//localhost:8080/MYCONTEXT/de/MYFILTER/whatever
As T5 sees MYFILTER it tries to find a page MYFILTER which fails.
When looking at decodePageRenderRequest I am able to detect the
filter, but removing it and passing the modified URL fails (browser
detects a recursion). To create a PageRenderRequestParameters or
ComponentRenderRequestParameter I need an logical page name, but the
request does not provide it. Maybe this is a wrong attempt at all and
there is an easier solution?
Thanks in advance
Jens
public PageRenderRequestParameters decodePageRenderRequest(final
Request request)
{
final String[] pathElements =
StringUtils.split(request.getPath(), '/');
if (pathElements.length >= 2) {
final String filterName = pathElements[1];
if ("MYFILTER".equals(filterName)) {
// missing: store filter in Thread to avoid passing it
as activation/passivation context
// TODO-1: how to correctly remove the filter from the
request before passing to T5?
final String[] newPathElements = new
String[pathElements.length - 1];
newPathElements[0] = pathElements[0];
System.arraycopy(pathElements, 2, newPathElements, 1,
pathElements.length - 2);
final ArrayEventContext aec = new
ArrayEventContext(_tc, newPathElements);
// TODO-2: how to retrieve the logical page name which
is hard coded to "Index" here?
return new PageRenderRequestParameters("Index", aec,
false);
}
}
return null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org