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

knowledgepixels / nanodash / 22660601761

04 Mar 2026 08:08AM UTC coverage: 15.94% (-0.09%) from 16.03%
22660601761

Pull #369

github

web-flow
Merge a19d3ced6 into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5319 branches covered (13.14%)

Branch coverage included in aggregate %.

1721 of 9863 relevant lines covered (17.45%)

2.39 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/component/QueryParamField.java
1
package com.knowledgepixels.nanodash.component;
2

3
import org.apache.wicket.markup.html.basic.Label;
4
import org.apache.wicket.markup.html.form.FormComponent;
5
import org.apache.wicket.markup.html.form.TextArea;
6
import org.apache.wicket.markup.html.form.TextField;
7
import org.apache.wicket.markup.html.panel.Panel;
8
import org.apache.wicket.model.Model;
9
import org.apache.wicket.validation.INullAcceptingValidator;
10
import org.apache.wicket.validation.IValidatable;
11
import org.apache.wicket.validation.ValidationError;
12
import org.eclipse.rdf4j.common.net.ParsedIRI;
13

14
import java.net.URISyntaxException;
15

16
/**
17
 * A field for entering query parameters, with validation for required fields and IRIs.
18
 */
19
public class QueryParamField extends Panel {
20

21
    private final FormComponent<String> formComponent;
22
    private final String paramId;
23

24
    /**
25
     * Constructs a QueryParamField with the given ID and parameter ID.
26
     *
27
     * @param id      the Wicket component ID
28
     * @param paramId the parameter ID, which may start with underscores and end with "_iri"
29
     */
30
    public QueryParamField(String id, String paramId) {
31
        super(id);
×
32
        this.paramId = paramId;
×
33
        add(new Label("paramname", getParamName()));
×
34
        if (isMultiPlaceholder()) {
×
35
            add(new Label("textfield").setVisible(false));
×
36
            formComponent = new TextArea<>("textarea", Model.of(""));
×
37
        } else {
38
            formComponent = new TextField<>("textfield", Model.of(""));
×
39
            add(new Label("textarea").setVisible(false));
×
40
        }
41
        formComponent.add(new Validator());
×
42
        add(formComponent);
×
43
        add(new Label("marker", isOptional() ? "" : "*"));
×
44
    }
×
45

46
    /**
47
     * Returns the text field for entering the parameter value.
48
     *
49
     * @return the text field component
50
     */
51
    public FormComponent<String> getFormComponent() {
52
        return formComponent;
×
53
    }
54

55
    /**
56
     * Returns the values (multi) or single value (non-multi) entered in the text field.
57
     *
58
     * @return the value of the text field
59
     */
60
    public String[] getValues() {
61
        return expandValues(formComponent.getModelObject(), paramId);
×
62
    }
63

64
    /**
65
     * Returns the parameter ID.
66
     *
67
     * @return the parameter ID
68
     */
69
    public String getParamId() {
70
        return paramId;
×
71
    }
72

73
    /**
74
     * Returns the parameter name derived from the parameter ID.
75
     *
76
     * @return the parameter name
77
     */
78
    public String getParamName() {
79
        return getParamName(paramId);
×
80
    }
81

82
    /**
83
     * Sets the value of the field (non-multi) or adds the value to the list of values (multi).
84
     *
85
     * @param value the value to be set/added
86
     */
87
    public void putValue(String value) {
88
        if (value == null) {
×
89
            return;
×
90
        }
91
        if (isMultiPlaceholder()) {
×
92
            formComponent.getModel().setObject(formComponent.getModel().getObject() + value + "\n");
×
93
        } else {
94
            formComponent.getModel().setObject(value);
×
95
        }
96
    }
×
97

98
    /**
99
     * Clears the value of the field, setting it to an empty string.
100
     */
101
    public void clearValue() {
102
        formComponent.getModel().setObject("");
×
103
    }
×
104

105
    /**
106
     * Checks if the parameter is optional (starts with "__").
107
     *
108
     * @return true if the parameter is optional, false otherwise
109
     */
110
    public boolean isOptional() {
111
        return isOptional(paramId);
×
112
    }
113

114
    /**
115
     * Checks if the parameter is an IRI parameter (ends with "_iri").
116
     *
117
     * @return true if the parameter is an IRI parameter, false otherwise
118
     */
119
    public boolean isIri() {
120
        return paramId.endsWith("_iri");
×
121
    }
122

123
    /**
124
     * Checks if the parameter has been set (non-blank value).
125
     *
126
     * @return true if the parameter has been set, false otherwise
127
     */
128
    public boolean isSet() {
129
        return isSet(formComponent.getModelObject());
×
130
    }
131

132
    /**
133
     * Checks if the parameter is a multi parameter (ends with "_multi" or "_multi_iri").
134
     *
135
     * @return true if the parameter is a multi parameter, false otherwise
136
     */
137
    public boolean isMultiPlaceholder() {
138
        return isMultiPlaceholder(paramId);
×
139
    }
140

141
    private class Validator extends InvalidityHighlighting implements INullAcceptingValidator<String> {
×
142

143
        @Override
144
        public void validate(IValidatable<String> i) {
145
            if (isOptional() && !isSet(i.getValue())) {
×
146
                // all good
147
                return;
×
148
            }
149
            if (!isSet(i.getValue())) {
×
150
                i.error(new ValidationError("Missing value for " + paramId));
×
151
                return;
×
152
            }
153
            if (isIri()) {
×
154
                for (String value : expandValues(i.getValue(), paramId)) {
×
155
                    if (!value.matches("https?://.+")) {
×
156
                        i.error(new ValidationError("Invalid IRI protocol: " + value));
×
157
                        return;
×
158
                    }
159
                    try {
160
                        ParsedIRI piri = new ParsedIRI(value);
×
161
                        if (!piri.isAbsolute()) {
×
162
                            i.error(new ValidationError("IRI not well-formed: " + value));
×
163
                        }
164
                    } catch (URISyntaxException ex) {
×
165
                        i.error(new ValidationError("IRI not well-formed: " + value));
×
166
                    }
×
167
                }
168
            }
169
        }
×
170

171
    }
172

173
    /**
174
     * Checks if a string is set (non-null and non-blank).
175
     *
176
     * @param s the string to check
177
     * @return true if the string is set, false otherwise
178
     */
179
    public static boolean isSet(String s) {
180
        return s != null && !s.isBlank();
×
181
    }
182

183
    /**
184
     * Checks if a parameter ID indicates a multi parameter (ends with "_multi" or "_multi_iri").
185
     *
186
     * @param p the parameter ID to check
187
     * @return true if the parameter ID indicates a multi parameter, false otherwise
188
     */
189
    public static boolean isMultiPlaceholder(String p) {
190
        return p.endsWith("_multi") || p.endsWith("_multi_iri");
×
191
    }
192

193
    public static boolean isOptional(String p) {
194
        return p.startsWith("__");
×
195
    }
196

197
    /**
198
     * Expands the value string into an array of values based on whether the parameter is multi or not.
199
     *
200
     * @param s       the value string
201
     * @param paramId the parameter ID
202
     * @return an array of values
203
     */
204
    public static String[] expandValues(String s, String paramId) {
205
        if (!isSet(s)) {
×
206
            return new String[]{};
×
207
        } else if (isMultiPlaceholder(paramId)) {
×
208
            return s.replaceFirst("\r?\n$", "").split("\r?\n");
×
209
        } else {
210
            return new String[]{s};
×
211
        }
212
    }
213

214
    /**
215
     * Extracts the parameter name from the placeholder ID.
216
     *
217
     * @param placeholderId the placeholder ID, which may start with underscores and end with "_iri" and/or "_multi"
218
     * @return the parameter name, stripped of leading underscores and "_iri"/"_multi" suffixes
219
     */
220
    public static String getParamName(String placeholderId) {
221
        return placeholderId.replaceFirst("^_+", "").replaceFirst("_iri$", "").replaceFirst("_multi$", "");
×
222
    }
223

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