Is it possible to use another decorator file for certain requests (Java based configuration)?

74 views
Skip to first unread message

Ilyas Patel

unread,
Jun 4, 2012, 5:38:34 PM6/4/12
to SiteMesh 3 Users
I use SiteMesh 2 xml configuration to add specific headers and footers
to a page depending on a URL (for our main site).

I would like to now add a different header and footer if the HTTP
Referer is within a specific list and I don’t want to use the
decorators.xml we use for the main site. I am trying to use Java based
configuration as documented on the SiteMesh site.

To keep things simple this is what I have so far:

public class PartnerFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder
builder) {
builder.setCustomDecoratorSelector(new
SomeDecoratorSelector());
}
@Override
public void init(FilterConfig filterConfig) throws
ServletException {
SiteMeshFilterBuilder builder = new SiteMeshFilterBuilder();
applyCustomConfiguration(builder);
}
@Override
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain)throws IOException, ServletException {
chain.doFilter(request, response);
}

class SomeDecoratorSelector implements
DecoratorSelector<WebAppContext> {
String decorator;

@Override
public String[] selectDecoratorPaths(Content content,
WebAppContext context) throws IOException {
decorator = "/WEB-INF/decoratorsPartnerSites.xml";
return decorator.split(",");
}
}
}

The decoratorsPartnerSites.xml file specified in the class file is not
being recognised. I have tried decorators.html and this does not work
either. Is there a way to not use the normal decorators.xml on a per
request basis?

I am fairly new to Java so any assistance would be grateful.



Tin Pham

unread,
Jun 7, 2012, 9:33:11 AM6/7/12
to sitemes...@googlegroups.com
Hi Illyas,

Yes it is possible to use decorators on a per request basis. Based on your description, I suggest you may be better of applying a different decorator (which is pretty easy to get going) rather than trying to load a different file.

I suggest detect the referrer and set a session variable,

Have a look at this article which shows how to change decorators using parameters. Using sessions should not be that big of a jump,

http://wiki.sitemesh.org/display/sitemesh/Decorating+with+Parameters


Tin

Ilyas Patel

unread,
Jun 8, 2012, 6:59:52 AM6/8/12
to SiteMesh 3 Users
Thank you, that's perfect.
Reply all
Reply to author
Forward
0 new messages