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

hazendaz / displaytag / 1753

12 Feb 2026 03:17AM UTC coverage: 77.321% (-0.01%) from 77.334%
1753

push

github

web-flow
Merge pull request #1102 from hazendaz/renovate/javax-support-logback-monorepo

Update dependency ch.qos.logback:logback-classic to v1.5.29 (javax-support)

1438 of 2003 branches covered (71.79%)

Branch coverage included in aggregate %.

4034 of 5074 relevant lines covered (79.5%)

0.8 hits per line

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

0.0
/displaytag/src/main/java/org/displaytag/localization/I18nStrutsAdapter.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2002-2026 Fabrizio Giustina, the Displaytag team
6
 */
7
package org.displaytag.localization;
8

9
import java.util.Locale;
10

11
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpSession;
13
import javax.servlet.jsp.PageContext;
14
import javax.servlet.jsp.tagext.Tag;
15

16
import org.apache.struts.Globals;
17
import org.apache.struts.config.ModuleConfig;
18
import org.apache.struts.util.MessageResources;
19

20
/**
21
 * Struts implementation of a resource provider and locale resolver. Uses Struts
22
 * <code>RequestUtils.getUserLocale()</code> and <code>TagUtils.message()</code> for the lookup.
23
 */
24
public class I18nStrutsAdapter implements I18nResourceProvider, LocaleResolver {
×
25

26
    /**
27
     * prefix/suffix for missing entries.
28
     */
29
    public static final String UNDEFINED_KEY = "???"; //$NON-NLS-1$
30

31
    /**
32
     * @see LocaleResolver#resolveLocale(PageContext)
33
     */
34
    @Override
35
    public Locale resolveLocale(PageContext pageContext) {
36
        HttpServletRequest request = ((HttpServletRequest) pageContext.getRequest());
×
37
        Locale userLocale = null;
×
38
        HttpSession session = request.getSession(false);
×
39

40
        // Only check session if sessions are enabled
41
        if (session != null) {
×
42
            userLocale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
×
43
        }
44

45
        if (userLocale == null) {
×
46
            // Returns Locale based on Accept-Language header or the server default
47
            userLocale = request.getLocale();
×
48
        }
49

50
        return userLocale;
×
51
    }
52

53
    /**
54
     * @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
55
     */
56
    @Override
57
    public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext) {
58

59
        // if titleKey isn't defined either, use property
60
        String key = (resourceKey != null) ? resourceKey : defaultValue;
×
61

62
        // retrieve MessageResources. Don't use TagUtils to mantain Struts 1.1 compatibility
63
        MessageResources resources = (MessageResources) pageContext.getAttribute(Globals.MESSAGES_KEY,
×
64
                PageContext.REQUEST_SCOPE);
65

66
        if (resources == null) {
×
67
            ModuleConfig moduleConfig = (ModuleConfig) pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
×
68

69
            if (moduleConfig == null) {
×
70
                moduleConfig = (ModuleConfig) pageContext.getServletContext().getAttribute(Globals.MODULE_KEY);
×
71
                pageContext.getRequest().setAttribute(Globals.MODULE_KEY, moduleConfig);
×
72
            }
73

74
            resources = (MessageResources) pageContext.getAttribute(Globals.MESSAGES_KEY + moduleConfig.getPrefix(),
×
75
                    PageContext.APPLICATION_SCOPE);
76
        }
77

78
        if (resources == null) {
×
79
            resources = (MessageResources) pageContext.getAttribute(Globals.MESSAGES_KEY,
×
80
                    PageContext.APPLICATION_SCOPE);
81
        }
82

83
        String title = null;
×
84
        if (resources != null) {
×
85
            Locale userLocale = resolveLocale(pageContext);
×
86
            title = resources.getMessage(userLocale, key);
×
87
        }
88

89
        // if user explicitely added a titleKey we guess this is an error
90
        if (title == null && resourceKey != null) {
×
91
            title = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY;
×
92
        }
93

94
        return title;
×
95
    }
96

97
}
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