• 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

65.88
/displaytag/src/main/java/org/displaytag/util/PostHref.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.net.URLDecoder;
25
import java.nio.charset.StandardCharsets;
26
import java.util.Iterator;
27
import java.util.Map;
28
import java.util.Map.Entry;
29
import java.util.Set;
30

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

34
/**
35
 * The Class PostHref.
36
 */
37
public class PostHref implements Href {
38

39
    /**
40
     * Serial ID.
41
     */
42
    private static final long serialVersionUID = 899149338534L;
43

44
    /** The parent. */
45
    private Href parent;
46

47
    /** The form. */
48
    private final String form;
49

50
    /**
51
     * Instantiates a new post href.
52
     *
53
     * @param parent
54
     *            the parent
55
     * @param form
56
     *            the form
57
     */
58
    public PostHref(final Href parent, final String form) {
1✔
59
        this.parent = parent;
1✔
60
        this.form = form;
1✔
61
    }
1✔
62

63
    /**
64
     * Adds the parameter.
65
     *
66
     * @param name
67
     *            the name
68
     * @param value
69
     *            the value
70
     *
71
     * @return the href
72
     *
73
     * @see org.displaytag.util.Href#addParameter(java.lang.String, java.lang.Object)
74
     */
75
    @Override
76
    public Href addParameter(final String name, final Object value) {
77
        this.parent.addParameter(name, value);
1✔
78
        return this;
1✔
79
    }
80

81
    /**
82
     * Adds the parameter.
83
     *
84
     * @param name
85
     *            the name
86
     * @param value
87
     *            the value
88
     *
89
     * @return the href
90
     *
91
     * @see org.displaytag.util.Href#addParameter(java.lang.String, int)
92
     */
93
    @Override
94
    public Href addParameter(final String name, final int value) {
95
        this.parent.addParameter(name, value);
×
96
        return this;
×
97
    }
98

99
    /**
100
     * Adds the parameter map.
101
     *
102
     * @param parametersMap
103
     *            the parameters map
104
     *
105
     * @see org.displaytag.util.Href#addParameterMap(java.util.Map)
106
     */
107
    @Override
108
    public void addParameterMap(final Map<String, String[]> parametersMap) {
109
        this.parent.addParameterMap(parametersMap);
×
110
    }
×
111

112
    /**
113
     * Equals.
114
     *
115
     * @param object
116
     *            the object
117
     *
118
     * @return true, if successful
119
     *
120
     * @see org.displaytag.util.Href#equals(java.lang.Object)
121
     */
122
    @Override
123
    public boolean equals(final Object object) {
124
        return this.parent.equals(object);
×
125
    }
126

127
    /**
128
     * Gets the anchor.
129
     *
130
     * @return the anchor
131
     *
132
     * @see org.displaytag.util.Href#getAnchor()
133
     */
134
    @Override
135
    public String getAnchor() {
136
        return this.parent.getAnchor();
×
137
    }
138

139
    /**
140
     * Gets the base url.
141
     *
142
     * @return the base url
143
     *
144
     * @see org.displaytag.util.Href#getBaseUrl()
145
     */
146
    @Override
147
    public String getBaseUrl() {
148
        return this.parent.getBaseUrl();
×
149
    }
150

151
    /**
152
     * Gets the parameter map.
153
     *
154
     * @return the parameter map
155
     *
156
     * @see org.displaytag.util.Href#getParameterMap()
157
     */
158
    @Override
159
    public Map<String, String[]> getParameterMap() {
160
        return this.parent.getParameterMap();
1✔
161
    }
162

163
    /**
164
     * Removes the parameter.
165
     *
166
     * @param name
167
     *            the name
168
     *
169
     * @see org.displaytag.util.Href#removeParameter(java.lang.String)
170
     */
171
    @Override
172
    public void removeParameter(final String name) {
173
        this.parent.removeParameter(name);
×
174
    }
×
175

176
    /**
177
     * Sets the anchor.
178
     *
179
     * @param name
180
     *            the new anchor
181
     *
182
     * @see org.displaytag.util.Href#setAnchor(java.lang.String)
183
     */
184
    @Override
185
    public void setAnchor(final String name) {
186
        this.parent.setAnchor(name);
×
187
    }
×
188

189
    /**
190
     * Sets the full url.
191
     *
192
     * @param url
193
     *            the new full url
194
     *
195
     * @see org.displaytag.util.Href#setFullUrl(java.lang.String)
196
     */
197
    @Override
198
    public void setFullUrl(final String url) {
199
        this.parent.setFullUrl(url);
×
200
    }
×
201

202
    /**
203
     * Sets the parameter map.
204
     *
205
     * @param parametersMap
206
     *            the parameters map
207
     *
208
     * @see org.displaytag.util.Href#setParameterMap(java.util.Map)
209
     */
210
    @Override
211
    public void setParameterMap(final Map<String, String[]> parametersMap) {
212
        this.parent.setParameterMap(parametersMap);
×
213
    }
×
214

215
    /**
216
     * To string.
217
     *
218
     * @return the string
219
     *
220
     * @see org.displaytag.util.Href#toString()
221
     */
222
    @Override
223
    public String toString() {
224

225
        final StringBuilder buffer = new StringBuilder(30);
1✔
226

227
        buffer.append("javascript:displaytagform('");
1✔
228
        buffer.append(this.form);
1✔
229
        buffer.append("',[");
1✔
230

231
        final Map<String, String[]> parameters = this.getParameterMap();
1✔
232

233
        final Set<Entry<String, String[]>> parameterSet = parameters.entrySet();
1✔
234

235
        final Iterator<Entry<String, String[]>> iterator = parameterSet.iterator();
1✔
236

237
        while (iterator.hasNext()) {
1✔
238
            // {f:'param1',v:'1'},
239
            final Entry<String, String[]> entry = iterator.next();
1✔
240

241
            final Object key = entry.getKey();
1✔
242
            final Object value = entry.getValue();
1✔
243

244
            buffer.append("{f:'");
1✔
245
            buffer.append(this.esc(key));
1✔
246
            buffer.append("',v:");
1✔
247

248
            if (value != null && value.getClass().isArray()) {
1!
249
                final Object[] values = (Object[]) value;
1✔
250

251
                if (values.length > 1) {
1!
252
                    buffer.append("[");
×
253
                }
254
                for (int i = 0; i < values.length; i++) {
1✔
255
                    if (i > 0) {
1!
256
                        buffer.append(",");
×
257
                    }
258

259
                    buffer.append("'");
1✔
260
                    buffer.append(this.esc(values[i]));
1✔
261
                    buffer.append("'");
1✔
262
                }
263
                if (values.length > 1) {
1!
264
                    buffer.append("]");
×
265
                }
266
            } else {
1✔
267
                buffer.append("'");
×
268
                buffer.append(this.esc(value));
×
269
                buffer.append("'");
×
270
            }
271

272
            buffer.append("}");
1✔
273

274
            if (iterator.hasNext()) {
1✔
275
                buffer.append(",");
1✔
276
            }
277
        }
1✔
278

279
        buffer.append("])");
1✔
280
        return buffer.toString();
1✔
281
    }
282

283
    /**
284
     * Esc.
285
     *
286
     * @param value
287
     *            the value
288
     *
289
     * @return the string
290
     */
291
    private String esc(final Object value) {
292
        String param = URLDecoder.decode(value != null ? value.toString() : StringUtils.EMPTY, StandardCharsets.UTF_8);
1!
293
        param = Strings.CS.replace(param, "'", "\\'");
1✔
294
        return Strings.CS.replace(param, "\"", "%22");
1✔
295
    }
296

297
    /**
298
     * Clone.
299
     *
300
     * @return the object
301
     *
302
     * @see java.lang.Object#clone()
303
     */
304
    @Override
305
    public Object clone() {
306
        final PostHref href;
307
        try {
308
            href = (PostHref) super.clone();
1✔
309
        } catch (final CloneNotSupportedException e) {
×
310
            throw new RuntimeException(e);
×
311
        }
1✔
312
        href.parent = (Href) this.parent.clone();
1✔
313

314
        return href;
1✔
315
    }
316

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