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

hazendaz / displaytag / 1525

05 Dec 2025 01:30AM UTC coverage: 76.996% (-0.04%) from 77.034%
1525

push

github

hazendaz
Cleanup deprecations and various code issues

1377 of 1935 branches covered (71.16%)

Branch coverage included in aggregate %.

22 of 27 new or added lines in 13 files covered. (81.48%)

1 existing line in 1 file now uncovered.

3898 of 4916 relevant lines covered (79.29%)

0.79 hits per line

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

73.68
/displaytag/src/main/java/org/displaytag/export/CsvView.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.export;
23

24
import jakarta.servlet.jsp.JspException;
25

26
import java.io.IOException;
27
import java.io.Writer;
28
import java.nio.charset.StandardCharsets;
29

30
import org.apache.commons.lang3.StringUtils;
31
import org.apache.commons.lang3.Strings;
32

33
/**
34
 * Export view for comma separated value exporting.
35
 */
36
public class CsvView extends BaseExportView {
1✔
37

38
    /** The Constant UTF8_BOM. */
39
    private static final String UTF8_BOM = "\uFEFF";
40

41
    /**
42
     * Do export.
43
     *
44
     * @param out
45
     *            the out
46
     * @param characterEncoding
47
     *            the character encoding
48
     *
49
     * @throws IOException
50
     *             Signals that an I/O exception has occurred.
51
     * @throws JspException
52
     *             the jsp exception
53
     */
54
    @Override
55
    public void doExport(final Writer out, final String characterEncoding) throws IOException, JspException {
56
        if (Strings.CI.equals(characterEncoding, StandardCharsets.UTF_8.name())) {
1!
57
            out.write(CsvView.UTF8_BOM);
×
58
        }
59
        super.doExport(out, characterEncoding);
1✔
60
    }
1✔
61

62
    /**
63
     * Gets the row end.
64
     *
65
     * @return the row end
66
     *
67
     * @see org.displaytag.export.BaseExportView#getRowEnd()
68
     */
69
    @Override
70
    protected String getRowEnd() {
71
        return "\n"; //$NON-NLS-1$
1✔
72
    }
73

74
    /**
75
     * Gets the cell end.
76
     *
77
     * @return the cell end
78
     *
79
     * @see org.displaytag.export.BaseExportView#getCellEnd()
80
     */
81
    @Override
82
    protected String getCellEnd() {
83
        return ","; //$NON-NLS-1$
1✔
84
    }
85

86
    /**
87
     * Gets the always append cell end.
88
     *
89
     * @return the always append cell end
90
     *
91
     * @see org.displaytag.export.BaseExportView#getAlwaysAppendCellEnd()
92
     */
93
    @Override
94
    protected boolean getAlwaysAppendCellEnd() {
95
        return false;
1✔
96
    }
97

98
    /**
99
     * Gets the always append row end.
100
     *
101
     * @return the always append row end
102
     *
103
     * @see org.displaytag.export.BaseExportView#getAlwaysAppendRowEnd()
104
     */
105
    @Override
106
    protected boolean getAlwaysAppendRowEnd() {
107
        return true;
1✔
108
    }
109

110
    /**
111
     * Gets the mime type.
112
     *
113
     * @return the mime type
114
     *
115
     * @see org.displaytag.export.ExportView#getMimeType()
116
     */
117
    @Override
118
    public String getMimeType() {
119
        return "text/csv"; //$NON-NLS-1$
1✔
120
    }
121

122
    /**
123
     * Escaping for csv format.
124
     * <ul>
125
     * <li>Quotes inside quoted strings are escaped with a /</li>
126
     * <li>Fields containings newlines or , are surrounded by "</li>
127
     * </ul>
128
     * Note this is the standard CVS format and it's not handled well by excel.
129
     *
130
     * @param value
131
     *            the value
132
     *
133
     * @return the string
134
     *
135
     * @see org.displaytag.export.BaseExportView#escapeColumnValue(java.lang.Object)
136
     */
137
    @Override
138
    protected String escapeColumnValue(final Object value) {
139
        final String stringValue = StringUtils.trim(value.toString());
1✔
140

141
        if (!StringUtils.containsNone(stringValue, '\r', '\n', ',')) {
1!
142
            return "\"" + //$NON-NLS-1$
×
NEW
143
                    Strings.CS.replace(stringValue, "\"", "\\\"") + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
×
144
        }
145

146
        return stringValue;
1✔
147
    }
148

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