*/
private void initPageResourceMapper() {
// Add page resources mapper
Mapper pageResourceMapper = new Mapper() {
public MediaResource handle(String relPath, HttpServletRequest request) {
ClasspathMediaResource mr = null;
// relPath: myimage.png
int suffixPos = relPath.lastIndexOf(".");
if (suffixPos > 0) {
String mediaName = relPath.substring(0, suffixPos);
String postfix = relPath.substring(suffixPos);
// 1) try it with current language
String fileName = mediaName + "_" + getLocale().toString() + postfix;
mr = new ClasspathMediaResource(Package.getPackage(bundleName), ContextHelpModule.CHELP_STATIC_DIR + fileName);
// 2) try it with default language
if (!mr.resourceExists()) {
fileName = mediaName + "_" + I18nModule.getDefaultLocale().toString() + postfix;
mr = new ClasspathMediaResource(Package.getPackage(bundleName), ContextHelpModule.CHELP_STATIC_DIR + fileName);
}
// 3) try it with fallback language
if (!mr.resourceExists()) {
fileName = mediaName + "_" + I18nModule.getFallbackLocale().toString() + postfix;
mr = new ClasspathMediaResource(Package.getPackage(bundleName), ContextHelpModule.CHELP_STATIC_DIR + fileName);
}
}
// If not even a fallback image is found, serve a not-found resource
if (!mr.resourceExists()) {
return new NotFoundMediaResource(relPath);
}
return mr;
}
};