• 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

87.61
/displaytag/src/main/java/org/displaytag/export/BaseExportView.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.export;
8

9
import java.io.IOException;
10
import java.io.Writer;
11
import java.util.Iterator;
12

13
import javax.servlet.jsp.JspException;
14

15
import org.apache.commons.lang3.StringUtils;
16
import org.displaytag.model.Column;
17
import org.displaytag.model.ColumnIterator;
18
import org.displaytag.model.HeaderCell;
19
import org.displaytag.model.Row;
20
import org.displaytag.model.RowIterator;
21
import org.displaytag.model.TableModel;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

25
/**
26
 * Base abstract class for simple export views.
27
 * <p>
28
 * A class that extends BaseExportView simply need to provide delimiters for rows and columns.
29
 */
30
public abstract class BaseExportView implements TextExportView {
1✔
31

32
    /**
33
     * logger.
34
     */
35
    private static Logger log = LoggerFactory.getLogger(BaseExportView.class);
1✔
36

37
    /**
38
     * TableModel to render.
39
     */
40
    private TableModel model;
41

42
    /** export full list?. */
43
    private boolean exportFull;
44

45
    /** include header in export?. */
46
    private boolean header;
47

48
    /** decorate export?. */
49
    private boolean decorated;
50

51
    /**
52
     * Sets the parameters.
53
     *
54
     * @param tableModel
55
     *            the table model
56
     * @param exportFullList
57
     *            the export full list
58
     * @param includeHeader
59
     *            the include header
60
     * @param decorateValues
61
     *            the decorate values
62
     *
63
     * @see org.displaytag.export.ExportView#setParameters(org.displaytag.model.TableModel, boolean, boolean, boolean)
64
     */
65
    @Override
66
    public void setParameters(final TableModel tableModel, final boolean exportFullList, final boolean includeHeader,
67
            final boolean decorateValues) {
68
        this.model = tableModel;
1✔
69
        this.exportFull = exportFullList;
1✔
70
        this.header = includeHeader;
1✔
71
        this.decorated = decorateValues;
1✔
72
    }
1✔
73

74
    /**
75
     * String to add before a row.
76
     *
77
     * @return String
78
     */
79
    protected String getRowStart() {
80
        return null;
1✔
81
    }
82

83
    /**
84
     * String to add after a row.
85
     *
86
     * @return String
87
     */
88
    protected String getRowEnd() {
89
        return null;
×
90
    }
91

92
    /**
93
     * String to add before a cell.
94
     *
95
     * @return String
96
     */
97
    protected String getCellStart() {
98
        return null;
1✔
99
    }
100

101
    /**
102
     * String to add after a cell.
103
     *
104
     * @return String
105
     */
106
    protected abstract String getCellEnd();
107

108
    /**
109
     * String to add to the top of document.
110
     *
111
     * @return String
112
     */
113
    protected String getDocumentStart() {
114
        return null;
1✔
115
    }
116

117
    /**
118
     * String to add to the end of document.
119
     *
120
     * @return String
121
     */
122
    protected String getDocumentEnd() {
123
        return null;
1✔
124
    }
125

126
    /**
127
     * always append cell end string?.
128
     *
129
     * @return boolean
130
     */
131
    protected abstract boolean getAlwaysAppendCellEnd();
132

133
    /**
134
     * always append row end string?.
135
     *
136
     * @return boolean
137
     */
138
    protected abstract boolean getAlwaysAppendRowEnd();
139

140
    /**
141
     * can be implemented to escape values for different output.
142
     *
143
     * @param value
144
     *            original column value
145
     *
146
     * @return escaped column value
147
     */
148
    protected abstract String escapeColumnValue(Object value);
149

150
    /**
151
     * Write table header.
152
     *
153
     * @return String rendered header
154
     */
155
    protected String doHeaders() {
156

157
        final String ROW_START = this.getRowStart();
1✔
158
        final String ROW_END = this.getRowEnd();
1✔
159
        final String CELL_START = this.getCellStart();
1✔
160
        final String CELL_END = this.getCellEnd();
1✔
161
        final boolean ALWAYS_APPEND_CELL_END = this.getAlwaysAppendCellEnd();
1✔
162

163
        final StringBuilder buffer = new StringBuilder(1000);
1✔
164

165
        final Iterator<HeaderCell> iterator = this.model.getHeaderCellList().iterator();
1✔
166

167
        // start row
168
        if (ROW_START != null) {
1!
169
            buffer.append(ROW_START);
×
170
        }
171

172
        while (iterator.hasNext()) {
1✔
173
            final HeaderCell headerCell = iterator.next();
1✔
174

175
            String columnHeader = headerCell.getTitle();
1✔
176

177
            if (columnHeader == null) {
1!
178
                columnHeader = StringUtils.capitalize(headerCell.getBeanPropertyName());
×
179
            }
180

181
            columnHeader = this.escapeColumnValue(columnHeader);
1✔
182

183
            if (CELL_START != null) {
1!
184
                buffer.append(CELL_START);
×
185
            }
186

187
            if (columnHeader != null) {
1!
188
                buffer.append(columnHeader);
1✔
189
            }
190

191
            if (CELL_END != null && (ALWAYS_APPEND_CELL_END || iterator.hasNext())) {
1!
192
                buffer.append(CELL_END);
1✔
193
            }
194
        }
1✔
195

196
        // end row
197
        if (ROW_END != null) {
1!
198
            buffer.append(ROW_END);
1✔
199
        }
200

201
        return buffer.toString();
1✔
202

203
    }
204

205
    /**
206
     * Do export.
207
     *
208
     * @param out
209
     *            the out
210
     * @param characterEncoding
211
     *            the character encoding
212
     *
213
     * @throws IOException
214
     *             Signals that an I/O exception has occurred.
215
     * @throws JspException
216
     *             the jsp exception
217
     *
218
     * @see org.displaytag.export.TextExportView#doExport(java.io.Writer,java.lang.String)
219
     */
220
    @Override
221
    public void doExport(final Writer out, final String characterEncoding) throws IOException, JspException {
222
        if (BaseExportView.log.isDebugEnabled()) {
1!
223
            BaseExportView.log.debug(this.getClass().getName());
×
224
        }
225

226
        final String DOCUMENT_START = this.getDocumentStart();
1✔
227
        final String DOCUMENT_END = this.getDocumentEnd();
1✔
228
        final String ROW_START = this.getRowStart();
1✔
229
        final String ROW_END = this.getRowEnd();
1✔
230
        final String CELL_START = this.getCellStart();
1✔
231
        final String CELL_END = this.getCellEnd();
1✔
232
        final boolean ALWAYS_APPEND_CELL_END = this.getAlwaysAppendCellEnd();
1✔
233
        final boolean ALWAYS_APPEND_ROW_END = this.getAlwaysAppendRowEnd();
1✔
234

235
        // document start
236
        this.write(out, DOCUMENT_START);
1✔
237

238
        if (this.header) {
1✔
239
            this.write(out, this.doHeaders());
1✔
240
        }
241

242
        // get the correct iterator (full or partial list according to the exportFull field)
243
        final RowIterator rowIterator = this.model.getRowIterator(this.exportFull);
1✔
244

245
        // iterator on rows
246
        while (rowIterator.hasNext()) {
1✔
247
            final Row row = rowIterator.next();
1✔
248

249
            if (this.model.getTableDecorator() != null) {
1✔
250

251
                final String stringStartRow = this.model.getTableDecorator().startRow();
1✔
252
                this.write(out, stringStartRow);
1✔
253
            }
254

255
            // iterator on columns
256
            final ColumnIterator columnIterator = row.getColumnIterator(this.model.getHeaderCellList());
1✔
257

258
            this.write(out, ROW_START);
1✔
259

260
            while (columnIterator.hasNext()) {
1✔
261
                final Column column = columnIterator.nextColumn();
1✔
262

263
                // Get the value to be displayed for the column
264
                final String value = this.escapeColumnValue(column.getValue(this.decorated));
1✔
265

266
                this.write(out, CELL_START);
1✔
267

268
                this.write(out, value);
1✔
269

270
                if (ALWAYS_APPEND_CELL_END || columnIterator.hasNext()) {
1✔
271
                    this.write(out, CELL_END);
1✔
272
                }
273

274
            }
1✔
275
            if (ALWAYS_APPEND_ROW_END || rowIterator.hasNext()) {
1✔
276
                this.write(out, ROW_END);
1✔
277
            }
278
        }
1✔
279

280
        // document end
281
        this.write(out, DOCUMENT_END);
1✔
282

283
    }
1✔
284

285
    /**
286
     * Write a String, checking for nulls value.
287
     *
288
     * @param out
289
     *            output writer
290
     * @param string
291
     *            String to be written
292
     *
293
     * @throws IOException
294
     *             thrown by out.write
295
     */
296
    private void write(final Writer out, final String string) throws IOException {
297
        if (string != null) {
1✔
298
            out.write(string);
1✔
299
        }
300
    }
1✔
301

302
    /**
303
     * Output page.
304
     *
305
     * @return true, if successful
306
     *
307
     * @see org.displaytag.export.TextExportView#outputPage()
308
     */
309
    @Override
310
    public boolean outputPage() {
311
        return false;
×
312
    }
313
}
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