com.opensymphony.module.sitemesh.mapper
public final class: LanguageDecoratorMapper [javadoc |
source]
java.lang.Object
com.opensymphony.module.sitemesh.mapper.AbstractDecoratorMapper
com.opensymphony.module.sitemesh.mapper.LanguageDecoratorMapper
All Implemented Interfaces:
DecoratorMapper
The LanguageDecoratorMapper can determine the preferred language set in the
browser requesting a page, and map to a suitable Decorator (using the
"Accept-Language" HTTP header).
This can be useful for supplying different versions of the same content
for different languages.
When LanguageDecoratorMapper is in the chain, it will request the appropriate Decorator
from its parent. It will then add an extention to the filename of the Decorator, and
if that file exists it shall be used as the Decorator instead. For example, if the
Decorator path is /blah.jsp and the detected preferred language is en,
the path /blah-en.jsp shall be used.
The language mappings are configured by passing properties with match. as a prefix.
For example: 'match.en'=engl , 'match.nl'=dutch .
| Method from com.opensymphony.module.sitemesh.mapper.LanguageDecoratorMapper Summary: |
|---|
|
getDecorator, init |
| Method from com.opensymphony.module.sitemesh.mapper.LanguageDecoratorMapper Detail: |
public Decorator getDecorator(HttpServletRequest request,
Page page) {
try {
Decorator result = null;
final Decorator d = super.getDecorator(request, page);
String path = modifyPath(d.getPage(), getExt(request.getHeader("Accept-Language")));
File decFile = new File(config.getServletContext().getRealPath(path));
if (decFile.isFile()) {
result = new DefaultDecorator(d.getName(), path, null) {
public String getInitParameter(String paramName) {
return d.getInitParameter(paramName);
}
};
}
return result == null ? super.getDecorator(request, page) : result;
}
catch (NullPointerException e) {
return super.getDecorator(request, page);
}
}
|
public void init(Config config,
Properties properties,
DecoratorMapper parent) throws InstantiationException {
super.init(config, properties, parent);
map = new HashMap();
initMap(properties);
}
|