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

knowledgepixels / nanodash / 18155160356

01 Oct 2025 07:42AM UTC coverage: 13.788% (-0.03%) from 13.817%
18155160356

push

github

ashleycaselli
docs: add missing or update Javadoc annotations

445 of 4084 branches covered (10.9%)

Branch coverage included in aggregate %.

1155 of 7520 relevant lines covered (15.36%)

0.69 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) return;
×
89
        if (isMultiPlaceholder()) {
×
90
            formComponent.getModel().setObject(formComponent.getModel().getObject() + value + "\n");
×
91
        } else {
92
            formComponent.getModel().setObject(value);
×
93
        }
94
    }
×
95

96
    /**
97
     * Checks if the parameter is optional (starts with "__").
98
     *
99
     * @return true if the parameter is optional, false otherwise
100
     */
101
    public boolean isOptional() {
102
        return paramId.startsWith("__");
×
103
    }
104

105
    /**
106
     * Checks if the parameter is an IRI parameter (ends with "_iri").
107
     *
108
     * @return true if the parameter is an IRI parameter, false otherwise
109
     */
110
    public boolean isIri() {
111
        return paramId.endsWith("_iri");
×
112
    }
113

114
    /**
115
     * Checks if the parameter has been set (non-blank value).
116
     *
117
     * @return true if the parameter has been set, false otherwise
118
     */
119
    public boolean isSet() {
120
        return isSet(formComponent.getModelObject());
×
121
    }
122

123
    /**
124
     * Checks if the parameter is a multi parameter (ends with "_multi" or "_multi_iri").
125
     *
126
     * @return true if the parameter is a multi parameter, false otherwise
127
     */
128
    public boolean isMultiPlaceholder() {
129
        return isMultiPlaceholder(paramId);
×
130
    }
131

132
    private class Validator extends InvalidityHighlighting implements INullAcceptingValidator<String> {
×
133

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

162
    }
163

164
    /**
165
     * Checks if a string is set (non-null and non-blank).
166
     *
167
     * @param s the string to check
168
     * @return true if the string is set, false otherwise
169
     */
170
    public static boolean isSet(String s) {
171
        return s != null && !s.isBlank();
×
172
    }
173

174
    /**
175
     * Checks if a parameter ID indicates a multi parameter (ends with "_multi" or "_multi_iri").
176
     *
177
     * @param p the parameter ID to check
178
     * @return true if the parameter ID indicates a multi parameter, false otherwise
179
     */
180
    public static boolean isMultiPlaceholder(String p) {
181
        return p.endsWith("_multi") || p.endsWith("_multi_iri");
×
182
    }
183

184
    /**
185
     * Expands the value string into an array of values based on whether the parameter is multi or not.
186
     *
187
     * @param s       the value string
188
     * @param paramId the parameter ID
189
     * @return an array of values
190
     */
191
    public static String[] expandValues(String s, String paramId) {
192
        if (!isSet(s)) {
×
193
            return new String[]{};
×
194
        } else if (isMultiPlaceholder(paramId)) {
×
195
            return s.replaceFirst("\r?\n$", "").split("\r?\n");
×
196
        } else {
197
            return new String[]{s};
×
198
        }
199
    }
200

201
    /**
202
     * Extracts the parameter name from the placeholder ID.
203
     *
204
     * @param placeholderId the placeholder ID, which may start with underscores and end with "_iri" and/or "_multi"
205
     * @return the parameter name, stripped of leading underscores and "_iri"/"_multi" suffixes
206
     */
207
    public static String getParamName(String placeholderId) {
208
        return placeholderId.replaceFirst("^_+", "").replaceFirst("_iri$", "").replaceFirst("_multi$", "");
×
209
    }
210

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