Skip to content

Instantly share code, notes, and snippets.

@joewalnes
Forked from anonymous/MyCustomDecoratorSelector.java
Created December 21, 2012 12:47
Show Gist options
  • Save joewalnes/4352585 to your computer and use it in GitHub Desktop.
Save joewalnes/4352585 to your computer and use it in GitHub Desktop.
Custom SiteMesh 3 configuration - selecting a decorator based on HttpSession.
<web-app>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.blah.MyCustomSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
public class MyCustomSiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setCustomDecoratorSelector(new MyCustomDecoratorSelector());
}
}
public class MyCustomDecoratorSelector extends DecoratorSelector<WebAppContext> {
@Override
public String[] selectDecoratorPaths(Content content, WebAppContext context) throws IOException {
HttpServletRequest request = context.getRequest();
if (request.getSession().getValue("is_admin") != null) {
return new String[] {"/decorators/admin-decorator.html"};
} else {
return new String[] {"/decorators/normal-decorator.html"};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment