• 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/OSDecoratorMapper.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/*
6
 * Title:        OSDecoratorMapper
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.http.HttpServletRequest;
22

23
import java.util.Map;
24
import java.util.Properties;
25

26
/**
27
 * The OSDecoratorMapper will map a suitable decorator based on the operating system of the remote client.
28
 * <p>
29
 * OSDecoratorMapper works by checking to see if the "UA-OS" header was sent with the HTTP request. If it was, the class
30
 * will check the value of the header with all the different os's the user has configured the Decorator Mapper to
31
 * identify and, if a match is found, routes the request accordingly. Configuration is done using the sitemesh.xml file.
32
 * The param name is a string literal (operating system name) you would like to match in the UA-OS header, and the value
33
 * is what will be appended to the decorator name if the user is using that operating system
34
 *
35
 * @author <a href="mailto:schepdawg@yahoo.com">Adam P. Schepis</a>
36
 *
37
 * @see com.opensymphony.module.sitemesh.mapper.AbstractDecoratorMapper
38
 */
39
public class OSDecoratorMapper extends AbstractDecoratorMapper {
×
40
    /**
41
     * Properties holds the parameters that the object was initialized with.
42
     */
43
    protected Properties properties;
44

45
    /**
46
     * Init initializes the OSDecoratorMapper object by setting the parent DecoratorMapper, and loading the
47
     * initialization properties.
48
     *
49
     * @param config
50
     *            The config file
51
     * @param properties
52
     *            An object containing intialization parameters
53
     * @param parent
54
     *            The parent DecoratorMapper object
55
     */
56
    @Override
57
    public void init(Config config, Properties properties, DecoratorMapper parent)
58
            throws java.lang.InstantiationException {
59
        this.properties = properties;
×
60
        this.parent = parent;
×
61
    }
×
62

63
    /**
64
     * Attempts to find the correct decorator for Page page based on the UA-OS HTTP header in the request.
65
     *
66
     * @param request
67
     *            The HTTP request sent to the server
68
     * @param page
69
     *            The page SiteMesh is trying to find a decorator for
70
     *
71
     * @return A Decorator object that is either the decorator for the identified OS, or the parent DecoratorMapper's
72
     *         decorator
73
     */
74
    @Override
75
    public Decorator getDecorator(HttpServletRequest request, Page page) {
76
        String osHeader = request.getHeader("UA-OS");
×
77
        if (osHeader == null) {
×
78
            return parent.getDecorator(request, page);
×
79
        }
80

81
        // run through the list of operating systems the application developer listed
82
        // in sitemesh.xml to see if we have a match to the user's current OS
83
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
×
84
            String os = (String) entry.getKey();
×
85

86
            // see if the name matches the user's operating system name
87
            if (osHeader.toLowerCase().indexOf(os.toLowerCase()) != -1) {
×
88
                String decoratorName = parent.getDecorator(request, page).getName();
×
89
                if (decoratorName != null) {
×
90
                    decoratorName += '-' + properties.getProperty(os);
×
91
                }
92
                return getNamedDecorator(request, decoratorName);
×
93
            }
94
        }
×
95

96
        return parent.getDecorator(request, page);
×
97
    }
98
}
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