• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / sitemesh2 / 59

22 Mar 2026 02:30AM UTC coverage: 40.347%. Remained the same
59

push

github

hazendaz
[mvn] Update maven wrapper

698 of 1891 branches covered (36.91%)

Branch coverage included in aggregate %.

1555 of 3693 relevant lines covered (42.11%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/opensymphony/module/sitemesh/mapper/ConfigDecoratorMapper.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/*
6
 * Title:        ConfigDecoratorMapper
7
 * Description:
8
 *
9
 * This software is published under the terms of the OpenSymphony Software
10
 * License version 1.1, of which a copy has been included with this
11
 * distribution in the LICENSE.txt file.
12
 */
13

14
package com.opensymphony.module.sitemesh.mapper;
15

16
import com.opensymphony.module.sitemesh.Config;
17
import com.opensymphony.module.sitemesh.Decorator;
18
import com.opensymphony.module.sitemesh.DecoratorMapper;
19
import com.opensymphony.module.sitemesh.Page;
20

21
import jakarta.servlet.ServletException;
22
import jakarta.servlet.http.HttpServletRequest;
23

24
import java.util.Properties;
25

26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

29
/**
30
 * Default implementation of DecoratorMapper. Reads decorators and mappings from the <code>config</code> property
31
 * (default '/WEB-INF/decorators.xml').
32
 *
33
 * @author <a href="joe@truemesh.com">Joe Walnes</a>
34
 * @author <a href="mcannon@internet.com">Mike Cannon-Brookes</a>
35
 *
36
 * @see com.opensymphony.module.sitemesh.DecoratorMapper
37
 * @see com.opensymphony.module.sitemesh.mapper.DefaultDecorator
38
 * @see com.opensymphony.module.sitemesh.mapper.ConfigLoader
39
 */
40
public class ConfigDecoratorMapper extends AbstractDecoratorMapper {
×
41

42
    /** The Logger. */
43
    private static final Logger logger = LoggerFactory.getLogger(ConfigDecoratorMapper.class);
×
44

45
    /** The config loader. */
46
    private ConfigLoader configLoader = null;
×
47

48
    /** Create new ConfigLoader using '/WEB-INF/decorators.xml' file. */
49
    @Override
50
    public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
51
        super.init(config, properties, parent);
×
52
        try {
53
            String fileName = properties.getProperty("config", "/WEB-INF/decorators.xml");
×
54
            configLoader = new ConfigLoader(fileName, config);
×
55
        } catch (Exception e) {
×
56
            throw new InstantiationException(e.toString());
×
57
        }
×
58
    }
×
59

60
    /** Retrieve {@link com.opensymphony.module.sitemesh.Decorator} based on 'pattern' tag. */
61
    @Override
62
    public Decorator getDecorator(HttpServletRequest request, Page page) {
63
        String thisPath = request.getServletPath();
×
64

65
        // getServletPath() returns null unless the mapping corresponds to a servlet
66
        if (thisPath == null) {
×
67
            String requestURI = request.getRequestURI();
×
68
            if (request.getPathInfo() != null) {
×
69
                // strip the pathInfo from the requestURI
70
                thisPath = requestURI.substring(0, requestURI.indexOf(request.getPathInfo()));
×
71
            } else {
72
                thisPath = requestURI;
×
73
            }
74
        } else if ("".equals(thisPath)) {
×
75
            // in servlet 2.4, if a request is mapped to '/*', getServletPath returns null (SIM-130)
76
            thisPath = request.getPathInfo();
×
77
        }
78

79
        String name = null;
×
80
        try {
81
            name = configLoader.getMappedName(thisPath);
×
82
        } catch (ServletException e) {
×
83
            logger.error("", e);
×
84
        }
×
85

86
        Decorator result = getNamedDecorator(request, name);
×
87
        return result == null ? super.getDecorator(request, page) : result;
×
88
    }
89

90
    /** Retrieve Decorator named in 'name' attribute. Checks the role if specified. */
91
    @Override
92
    public Decorator getNamedDecorator(HttpServletRequest request, String name) {
93
        Decorator result = null;
×
94
        try {
95
            result = configLoader.getDecoratorByName(name);
×
96
        } catch (ServletException e) {
×
97
            logger.error("", e);
×
98
        }
×
99

100
        if (result == null || result.getRole() != null && !request.isUserInRole(result.getRole())) {
×
101
            // if the result is null or the user is not in the role
102
            return super.getNamedDecorator(request, name);
×
103
        }
104
        return result;
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc