1
2
3
4
5
6
7
8
9
10
11 package psiprobe.mappers;
12
13 import com.opensymphony.module.sitemesh.Config;
14 import com.opensymphony.module.sitemesh.Decorator;
15 import com.opensymphony.module.sitemesh.DecoratorMapper;
16 import com.opensymphony.module.sitemesh.Page;
17 import com.opensymphony.module.sitemesh.mapper.AbstractDecoratorMapper;
18
19 import jakarta.servlet.http.HttpServletRequest;
20
21 import java.util.Properties;
22
23
24
25
26
27 public class AjaxDecoratorMapper extends AbstractDecoratorMapper {
28
29
30 private String ajaxExtension = ".ajax";
31
32 @Override
33 public void init(Config config, Properties properties, DecoratorMapper decoratorMapper)
34 throws InstantiationException {
35
36 super.init(config, properties, decoratorMapper);
37 if (properties.get("ajaxExtension") != null) {
38 ajaxExtension = (String) properties.get("ajaxExtension");
39 }
40 }
41
42 @Override
43 public Decorator getDecorator(HttpServletRequest request, Page page) {
44
45 boolean callMapperChain;
46 String originalUri = (String) request.getAttribute("jakarta.servlet.error.request_uri");
47 if (originalUri != null) {
48
49
50
51 int queryStringIndex = originalUri.indexOf('?');
52 if (queryStringIndex != -1) {
53 originalUri = originalUri.substring(0, queryStringIndex);
54 }
55 }
56 callMapperChain = (originalUri == null || !originalUri.endsWith(ajaxExtension))
57 && !request.getServletPath().endsWith(ajaxExtension);
58
59 return callMapperChain ? super.getDecorator(request, page) : null;
60 }
61
62 }