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

knowledgepixels / nanodash / 17833286003

18 Sep 2025 03:15PM UTC coverage: 13.949% (-0.03%) from 13.974%
17833286003

push

github

tkuhn
feat: Show multi-placeholders as text areas in QueryPage

Still more work needed to fully support multi-placeholders.

444 of 4022 branches covered (11.04%)

Branch coverage included in aggregate %.

1141 of 7341 relevant lines covered (15.54%)

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 java.net.URISyntaxException;
4

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

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

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

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

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

56
    /**
57
     * Returns the value entered in the text field.
58
     *
59
     * @return the value of the text field
60
     */
61
    public String getValue() {
62
        return formComponent.getModelObject();
×
63
    }
64

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

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

83
    /**
84
     * Returns the model of the text field.
85
     *
86
     * @return the model of the text field
87
     */
88
    public IModel<String> getModel() {
89
        return formComponent.getModel();
×
90
    }
91

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

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

110
    /**
111
     * Checks if the parameter is a multi parameter (ends with "_multi" or "_multi_iri").
112
     *
113
     * @return true if the parameter is a multi parameter, false otherwise
114
     */
115
    public boolean isMultiPlaceholder() {
116
        return paramId.endsWith("_multi") || paramId.endsWith("_multi_iri");
×
117
    }
118

119
    private class Validator extends InvalidityHighlighting implements INullAcceptingValidator<String> {
×
120

121
        @Override
122
        public void validate(IValidatable<String> s) {
123
            String value = s.getValue();
×
124
            if (isOptional() && !isSet(value)) {
×
125
                // all good
126
                return;
×
127
            }
128
            if (!isSet(value)) {
×
129
                s.error(new ValidationError("Missing value for " + paramId));
×
130
                return;
×
131
            }
132
            if (isIri()) {
×
133
                if (!value.matches("https?://.+")) {
×
134
                    s.error(new ValidationError("Invalid IRI protocol: " + value));
×
135
                    return;
×
136
                }
137
                try {
138
                    ParsedIRI piri = new ParsedIRI(value);
×
139
                    if (!piri.isAbsolute()) {
×
140
                        s.error(new ValidationError("IRI not well-formed: " + value));
×
141
                    }
142
                } catch (URISyntaxException ex) {
×
143
                    s.error(new ValidationError("IRI not well-formed: " + value));
×
144
                }
×
145
            }
146
        }
×
147

148
        private static boolean isSet(String s) {
149
            return s != null && !s.isBlank();
×
150
        }
151

152
    }
153

154
    /**
155
     * Extracts the parameter name from the placeholder ID.
156
     *
157
     * @param placeholderId the placeholder ID, which may start with underscores and end with "_iri" and/or "_multi"
158
     * @return the parameter name, stripped of leading underscores and "_iri"/"_multi" suffixes
159
     */
160
    public static String getParamName(String placeholderId) {
161
        return placeholderId.replaceFirst("^_+", "").replaceFirst("_iri$", "").replaceFirst("_multi$", "");
×
162
    }
163

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