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

18
import jakarta.servlet.http.HttpServletRequest;
19

20
import javax.naming.Context;
21
import javax.naming.InitialContext;
22
import javax.naming.NamingException;
23

24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
/**
28
 * The EnvEntryDecoratorMapper allows the reference to a web-app environment entry for the decorator name, and falls
29
 * back to ConfigDecoratorMapper's behavior if no matching environment entry is found.
30
 * <p>
31
 * In some cases, it's desirable to allow a deployer, as opposed to a developer, to specify a decorator. In a .WAR file,
32
 * this can be very difficult, since decorator mappings are specified in <code>decorators.xml</code> (more or less).
33
 * This mapper corrects that by allowing two types of mapping. If the decorator name is found in an
34
 * <code>&lt;env-entry&gt;</code>, the entry's value is used as the decorator reference.
35
 * <p>
36
 * Known Issues:
37
 * <ol>
38
 * <li>It still uses the decorator path (from <code>decorators.xml</code>). This needs to be corrected for full
39
 * functionality. If anyone has a suggestion on how...</li>
40
 * </ol>
41
 *
42
 * @author <a href="mailto:joeo@enigmastation.com">Joseph B. Ottinger</a>
43
 *
44
 * @see com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper
45
 */
46
public class EnvEntryDecoratorMapper extends ConfigDecoratorMapper {
×
47

48
    /** The Logger. */
49
    private static final Logger logger = LoggerFactory.getLogger(EnvEntryDecoratorMapper.class);
×
50

51
    /**
52
     * Retrieves the {@link com.opensymphony.module.sitemesh.Decorator} specified by the decorator name. If it's not in
53
     * the environment entries of the web application, assume it's a named decorator from <code>decorators.xml</code>.
54
     */
55
    @Override
56
    public Decorator getNamedDecorator(HttpServletRequest request, String name) {
57
        String resourceValue = getStringResource(name);
×
58
        if (resourceValue == null) {
×
59
            return super.getNamedDecorator(request, name);
×
60
        }
61
        return new DefaultDecorator(name, resourceValue, null);
×
62
    }
63

64
    /**
65
     * This pulls a value out of the web-app environment. If the value isn't there, returns null.
66
     *
67
     * @param name
68
     *            the name
69
     *
70
     * @return the string resource
71
     */
72
    public static String getStringResource(String name) {
73
        String value = null;
×
74
        Context ctx = null;
×
75
        try {
76
            ctx = new InitialContext();
×
77
            Object o = ctx.lookup("java:comp/env/" + name);
×
78
            if (o != null) {
×
79
                value = o.toString();
×
80
            }
81
        } catch (NamingException e) {
×
82
            logger.error("", e);
×
83
        } finally {
84
            try {
85
                if (ctx != null) {
×
86
                    ctx.close();
×
87
                }
88
            } catch (NamingException e) {
×
89
                logger.error("", e);
×
90
            }
×
91
        }
92
        return value;
×
93
    }
94
}
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