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

hazendaz / displaytag / 1792

14 Feb 2026 05:47PM UTC coverage: 76.939% (-0.06%) from 76.997%
1792

push

github

web-flow
Merge pull request #1110 from hazendaz/renovate/master-logback-monorepo

Update dependency ch.qos.logback:logback-classic to v1.5.30 (master)

1380 of 1939 branches covered (71.17%)

Branch coverage included in aggregate %.

3898 of 4921 relevant lines covered (79.21%)

0.79 hits per line

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

55.17
/displaytag/src/main/java/org/displaytag/export/ExportViewFactory.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.lang.reflect.InvocationTargetException;
10
import java.util.HashMap;
11
import java.util.Map;
12

13
import org.apache.commons.lang3.ArrayUtils;
14
import org.displaytag.Messages;
15
import org.displaytag.exception.WrappedRuntimeException;
16
import org.displaytag.model.TableModel;
17
import org.displaytag.properties.MediaTypeEnum;
18
import org.displaytag.properties.TableProperties;
19
import org.displaytag.util.ReflectHelper;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

23
/**
24
 * Factory for export views.
25
 */
26
public final class ExportViewFactory {
27

28
    /**
29
     * Singleton.
30
     */
31
    private static ExportViewFactory instance;
32

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

38
    /**
39
     * Map containing MediaTypeEnum - View class.
40
     */
41
    private final Map<MediaTypeEnum, Class<ExportView>> viewClasses = new HashMap<>();
1✔
42

43
    /**
44
     * Private constructor.
45
     */
46
    private ExportViewFactory() {
1✔
47
        final TableProperties properties = TableProperties.getInstance(null);
1✔
48
        final String[] exportTypes = properties.getExportTypes();
1✔
49

50
        if (ExportViewFactory.log.isInfoEnabled()) {
1!
51
            ExportViewFactory.log.info(Messages.getString("ExportViewFactory.initializing", //$NON-NLS-1$
×
52
                    new Object[] { ArrayUtils.toString(exportTypes) }));
×
53
        }
54
        for (final String exportType : exportTypes) {
1✔
55
            final String className = properties.getExportClass(exportType);
1✔
56
            this.registerExportView(exportType, className);
1✔
57
        }
58
    }
1✔
59

60
    /**
61
     * Returns the simgleton for this class.
62
     *
63
     * @return ExportViewFactory instance
64
     */
65
    public static synchronized ExportViewFactory getInstance() {
66
        if (ExportViewFactory.instance == null) {
1✔
67
            ExportViewFactory.instance = new ExportViewFactory();
1✔
68
        }
69
        return ExportViewFactory.instance;
1✔
70
    }
71

72
    /**
73
     * Register a new Export View, associated with a Media Type. If another export view is currently associated with the
74
     * given media type it's replaced.
75
     *
76
     * @param name
77
     *            media name
78
     * @param viewClassName
79
     *            export view class name
80
     */
81
    public void registerExportView(final String name, final String viewClassName) {
82
        Class<ExportView> exportClass;
83
        try {
84
            exportClass = (Class<ExportView>) ReflectHelper.classForName(viewClassName);
1✔
85
        } catch (final ClassNotFoundException e) {
×
86
            ExportViewFactory.log.error(Messages.getString("ExportViewFactory.classnotfound", //$NON-NLS-1$
×
87
                    new Object[] { name, viewClassName }));
88
            return;
×
89
        } catch (final NoClassDefFoundError e) {
×
90
            ExportViewFactory.log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
×
91
                    , new Object[] { name, viewClassName, e.getMessage() }));
×
92
            return;
×
93
        }
1✔
94

95
        try {
96
            exportClass.getDeclaredConstructor().newInstance();
1✔
97
        } catch (final InstantiationException | IllegalArgumentException | InvocationTargetException
×
98
                | NoSuchMethodException | SecurityException e) {
99
            ExportViewFactory.log.error(Messages.getString("ExportViewFactory.instantiationexception", //$NON-NLS-1$
×
100
                    new Object[] { name, viewClassName, e.getMessage() }));
×
101
            return;
×
102
        } catch (final IllegalAccessException e) {
×
103
            ExportViewFactory.log.error(Messages.getString("ExportViewFactory.illegalaccess", //$NON-NLS-1$
×
104
                    new Object[] { name, viewClassName, e.getMessage() }));
×
105
            return;
×
106
        } catch (final NoClassDefFoundError e) {
×
107
            ExportViewFactory.log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
×
108
                    , new Object[] { name, viewClassName, e.getMessage() }));
×
109
            return;
×
110
        }
1✔
111

112
        final MediaTypeEnum media = MediaTypeEnum.registerMediaType(name);
1✔
113
        this.viewClasses.put(media, exportClass);
1✔
114

115
        if (ExportViewFactory.log.isDebugEnabled()) {
1!
116
            ExportViewFactory.log.debug(Messages.getString("ExportViewFactory.added", //$NON-NLS-1$
×
117
                    new Object[] { media, viewClassName }));
118
        }
119
    }
1✔
120

121
    /**
122
     * returns an instance of export view associated with the given export type.
123
     *
124
     * @param exportType
125
     *            MediaTypeEnum
126
     * @param tableModel
127
     *            table model containing data to render
128
     * @param exportFullList
129
     *            should the complete list be exported?
130
     * @param includeHeader
131
     *            should header be included in export?
132
     * @param decorateValues
133
     *            should ouput be decorated?
134
     *
135
     * @return specialized instance of BaseExportView
136
     */
137
    public ExportView getView(final MediaTypeEnum exportType, final TableModel tableModel, final boolean exportFullList,
138
            final boolean includeHeader, final boolean decorateValues) {
139
        ExportView view;
140

141
        final Class<ExportView> viewClass = this.viewClasses.get(exportType);
1✔
142

143
        try {
144
            view = viewClass.getDeclaredConstructor().newInstance();
1✔
145
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
×
146
                | NoSuchMethodException | SecurityException e) {
147
            // should not happen (class has already been instantiated before)
148
            throw new WrappedRuntimeException(this.getClass(), e);
×
149
        }
1✔
150

151
        view.setParameters(tableModel, exportFullList, includeHeader, decorateValues);
1✔
152
        return view;
1✔
153
    }
154

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