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

hazendaz / displaytag / 1558

08 Dec 2025 01:09AM UTC coverage: 77.32% (-0.04%) from 77.358%
1558

push

github

web-flow
Merge pull request #1042 from hazendaz/renovate/javax-support-org.apache.commons-commons-text-1.x

Update dependency org.apache.commons:commons-text to v1.15.0 (javax-support)

1435 of 1999 branches covered (71.79%)

Branch coverage included in aggregate %.

4030 of 5069 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
 * Copyright (C) 2002-2025 Fabrizio Giustina, the Displaytag team
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to deal
6
 * in the Software without restriction, including without limitation the rights
7
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 * copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in
12
 * all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
package org.displaytag.util;
23

24
import java.util.ArrayList;
25
import java.util.List;
26
import java.util.Locale;
27

28
import org.apache.commons.lang3.StringUtils;
29
import org.displaytag.properties.MediaTypeEnum;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

33
/**
34
 * This class provides services for configuring and determining the list of media types an instance of
35
 * <code>SupportsMedia</code> supports. (Background: ColumnTag, FooterTag and CaptionTag can be configured to support a
36
 * set of media types. This class factors the logic for setting and determining the media instances these objects
37
 * support)
38
 */
39
public final class MediaUtil {
40

41
    /**
42
     * logger.
43
     */
44
    private static Logger log = LoggerFactory.getLogger(MediaUtil.class);
1✔
45

46
    /**
47
     * Don't instantiate MediaUtil.
48
     */
49
    private MediaUtil() {
50
    }
51

52
    /**
53
     * Defines a type of object that can support a list of media types.
54
     */
55
    public interface SupportsMedia {
56

57
        /**
58
         * Configure the list of media types this object will support.
59
         *
60
         * @param media
61
         *            The list of media types this object will support.
62
         */
63
        void setSupportedMedia(List<MediaTypeEnum> media);
64

65
        /**
66
         * Obtain the list of media types this object supports.
67
         *
68
         * @return The list of media types this object supports.
69
         */
70
        List<MediaTypeEnum> getSupportedMedia();
71
    }
72

73
    /**
74
     * Configures the media supported by an object that implements <code>SupportsMedia</code>. (Background: factored
75
     * from ColumnTag)
76
     *
77
     * @param mediaSupporter
78
     *            The <code>SupportsMedia</code> instance being configured to support a list of media.
79
     * @param media
80
     *            The media being configured on the given <code>SupportsMedia</code> instance.
81
     */
82
    public static void setMedia(final SupportsMedia mediaSupporter, final String media) {
83
        if (mediaSupporter == null) {
1!
84
            return;
×
85
        }
86

87
        if (StringUtils.isBlank(media) || media.toLowerCase(Locale.ENGLISH).indexOf("all") > -1) {
1!
88
            mediaSupporter.setSupportedMedia(null);
×
89
            return;
×
90
        }
91
        final List<MediaTypeEnum> supportedMedia = new ArrayList<>();
1✔
92
        final String[] values = StringUtils.split(media);
1✔
93
        for (final String value : values) {
1✔
94
            if (!StringUtils.isBlank(value)) {
1!
95
                final MediaTypeEnum type = MediaTypeEnum.fromName(value.toLowerCase(Locale.ENGLISH));
1✔
96
                if (type == null) {
1✔
97
                    MediaUtil.log.warn("Unrecognized value for attribute \"media\" value=\"{}\"", value);
1✔
98
                } else {
99
                    supportedMedia.add(type);
1✔
100
                }
101
            }
102
        }
103
        mediaSupporter.setSupportedMedia(supportedMedia);
1✔
104
    }
1✔
105

106
    /**
107
     * Is this media supporter configured for the media type? (Background: Factored from ColumnTag).
108
     *
109
     * @param mediaSupporter
110
     *            An object that supports various media.
111
     * @param mediaType
112
     *            The currentMedia type
113
     *
114
     * @return true if the media supporter should be displayed for this request
115
     */
116
    public static boolean availableForMedia(final SupportsMedia mediaSupporter, final MediaTypeEnum mediaType) {
117
        if (mediaSupporter == null) {
1!
118
            return false;
×
119
        }
120

121
        final List<MediaTypeEnum> supportedMedia = mediaSupporter.getSupportedMedia();
1✔
122

123
        if (supportedMedia == null) {
1✔
124
            return true;
1✔
125
        }
126

127
        return supportedMedia.contains(mediaType);
1✔
128
    }
129
}
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