• 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

76.32
/displaytag/src/main/java/org/displaytag/util/MediaUtil.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.util;
8

9
import java.util.ArrayList;
10
import java.util.List;
11
import java.util.Locale;
12

13
import org.apache.commons.lang3.StringUtils;
14
import org.displaytag.properties.MediaTypeEnum;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
/**
19
 * This class provides services for configuring and determining the list of media types an instance of
20
 * <code>SupportsMedia</code> supports. (Background: ColumnTag, FooterTag and CaptionTag can be configured to support a
21
 * set of media types. This class factors the logic for setting and determining the media instances these objects
22
 * support)
23
 */
24
public final class MediaUtil {
25

26
    /**
27
     * logger.
28
     */
29
    private static Logger log = LoggerFactory.getLogger(MediaUtil.class);
1✔
30

31
    /**
32
     * Don't instantiate MediaUtil.
33
     */
34
    private MediaUtil() {
35
    }
36

37
    /**
38
     * Defines a type of object that can support a list of media types.
39
     */
40
    public interface SupportsMedia {
41

42
        /**
43
         * Configure the list of media types this object will support.
44
         *
45
         * @param media
46
         *            The list of media types this object will support.
47
         */
48
        void setSupportedMedia(List<MediaTypeEnum> media);
49

50
        /**
51
         * Obtain the list of media types this object supports.
52
         *
53
         * @return The list of media types this object supports.
54
         */
55
        List<MediaTypeEnum> getSupportedMedia();
56
    }
57

58
    /**
59
     * Configures the media supported by an object that implements <code>SupportsMedia</code>. (Background: factored
60
     * from ColumnTag)
61
     *
62
     * @param mediaSupporter
63
     *            The <code>SupportsMedia</code> instance being configured to support a list of media.
64
     * @param media
65
     *            The media being configured on the given <code>SupportsMedia</code> instance.
66
     */
67
    public static void setMedia(final SupportsMedia mediaSupporter, final String media) {
68
        if (mediaSupporter == null) {
1!
69
            return;
×
70
        }
71

72
        if (StringUtils.isBlank(media) || media.toLowerCase(Locale.ENGLISH).indexOf("all") > -1) {
1!
73
            mediaSupporter.setSupportedMedia(null);
×
74
            return;
×
75
        }
76
        final List<MediaTypeEnum> supportedMedia = new ArrayList<>();
1✔
77
        final String[] values = StringUtils.split(media);
1✔
78
        for (final String value : values) {
1✔
79
            if (!StringUtils.isBlank(value)) {
1!
80
                final MediaTypeEnum type = MediaTypeEnum.fromName(value.toLowerCase(Locale.ENGLISH));
1✔
81
                if (type == null) {
1✔
82
                    MediaUtil.log.warn("Unrecognized value for attribute \"media\" value=\"{}\"", value);
1✔
83
                } else {
84
                    supportedMedia.add(type);
1✔
85
                }
86
            }
87
        }
88
        mediaSupporter.setSupportedMedia(supportedMedia);
1✔
89
    }
1✔
90

91
    /**
92
     * Is this media supporter configured for the media type? (Background: Factored from ColumnTag).
93
     *
94
     * @param mediaSupporter
95
     *            An object that supports various media.
96
     * @param mediaType
97
     *            The currentMedia type
98
     *
99
     * @return true if the media supporter should be displayed for this request
100
     */
101
    public static boolean availableForMedia(final SupportsMedia mediaSupporter, final MediaTypeEnum mediaType) {
102
        if (mediaSupporter == null) {
1!
103
            return false;
×
104
        }
105

106
        final List<MediaTypeEnum> supportedMedia = mediaSupporter.getSupportedMedia();
1✔
107

108
        if (supportedMedia == null) {
1✔
109
            return true;
1✔
110
        }
111

112
        return supportedMedia.contains(mediaType);
1✔
113
    }
114
}
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