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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

0.68 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/ValueTextfieldItem.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.LocalUri;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.template.Template;
6
import com.knowledgepixels.nanodash.template.TemplateContext;
7
import com.knowledgepixels.nanodash.template.UnificationException;
8
import org.apache.wicket.AttributeModifier;
9
import org.apache.wicket.Component;
10
import org.apache.wicket.ajax.AjaxRequestTarget;
11
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
12
import org.apache.wicket.markup.html.form.TextField;
13
import org.apache.wicket.markup.html.panel.Panel;
14
import org.apache.wicket.model.IModel;
15
import org.apache.wicket.model.Model;
16
import org.apache.wicket.validation.IValidatable;
17
import org.apache.wicket.validation.IValidator;
18
import org.apache.wicket.validation.Validatable;
19
import org.apache.wicket.validation.ValidationError;
20
import org.eclipse.rdf4j.common.net.ParsedIRI;
21
import org.eclipse.rdf4j.model.IRI;
22
import org.eclipse.rdf4j.model.Literal;
23
import org.eclipse.rdf4j.model.Value;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
import java.net.URISyntaxException;
28

29
/**
30
 * A text field component for entering values in a template.
31
 */
32
public class ValueTextfieldItem extends Panel implements ContextComponent {
33

34
    private TemplateContext context;
35
    private TextField<String> textfield;
36
    private IRI iri;
37
    private static final Logger logger = LoggerFactory.getLogger(ValueTextfieldItem.class);
×
38

39
    /**
40
     * Constructor for creating a text field item.
41
     *
42
     * @param id       the component ID
43
     * @param parentId the parent component ID
44
     * @param iriP     the IRI associated with this text field
45
     * @param optional whether the field is optional
46
     * @param context  the template context containing models and components
47
     */
48
    public ValueTextfieldItem(String id, String parentId, final IRI iriP, boolean optional, final TemplateContext context) {
49
        super(id);
×
50
        this.context = context;
×
51
        this.iri = iriP;
×
52
        final Template template = context.getTemplate();
×
53
        IModel<String> model = context.getComponentModels().get(iri);
×
54
        if (model == null) {
×
55
            model = Model.of("");
×
56
            context.getComponentModels().put(iri, model);
×
57
        }
58
        String postfix = Utils.getUriPostfix(iri);
×
59
        if (context.hasParam(postfix)) {
×
60
            model.setObject(context.getParam(postfix));
×
61
        }
62
        textfield = new TextField<>("textfield", model);
×
63
        if (!optional) textfield.setRequired(true);
×
64
        textfield.add(new Validator(iri, template));
×
65
        context.getComponents().add(textfield);
×
66
        if (template.getLabel(iri) != null) {
×
67
            textfield.add(new AttributeModifier("placeholder", template.getLabel(iri)));
×
68
            textfield.setLabel(Model.of(template.getLabel(iri)));
×
69
        }
70
        textfield.add(new OnChangeAjaxBehavior() {
×
71

72
            @Override
73
            protected void onUpdate(AjaxRequestTarget target) {
74
                for (Component c : context.getComponents()) {
×
75
                    if (c == textfield) continue;
×
76
                    if (c.getDefaultModel() == textfield.getModel()) {
×
77
                        c.modelChanged();
×
78
                        target.add(c);
×
79
                    }
80
                }
×
81
            }
×
82

83
        });
84
        add(textfield);
×
85
    }
×
86

87
    /**
88
     * {@inheritDoc}
89
     */
90
    @Override
91
    public void removeFromContext() {
92
        context.getComponents().remove(textfield);
×
93
    }
×
94

95
    /**
96
     * {@inheritDoc}
97
     */
98
    @Override
99
    public boolean isUnifiableWith(Value v) {
100
        if (v == null) return true;
×
101
        String vs = v.stringValue();
×
102
        if (v instanceof Literal vL) vs = Utils.getSerializedLiteral(vL);
×
103
        if (Utils.isLocalURI(vs)) vs = vs.replaceFirst("^" + LocalUri.PREFIX, "");
×
104
        Validatable<String> validatable = new Validatable<>(vs);
×
105
        if (v instanceof IRI && context.getTemplate().isLocalResource(iri) && !Utils.isUriPostfix(vs)) {
×
106
            vs = Utils.getUriPostfix(vs);
×
107
        }
108
        new Validator(iri, context.getTemplate()).validate(validatable);
×
109
        if (!validatable.isValid()) {
×
110
            return false;
×
111
        }
112
        if (textfield.getModelObject().isEmpty()) {
×
113
            return true;
×
114
        }
115
        return vs.equals(textfield.getModelObject());
×
116
    }
117

118
    /**
119
     * {@inheritDoc}
120
     */
121
    @Override
122
    public void unifyWith(Value v) throws UnificationException {
123
        if (v == null) return;
×
124
        if (!isUnifiableWith(v)) throw new UnificationException(v.stringValue());
×
125
        String vs = v.stringValue();
×
126
        if (Utils.isLocalURI(vs)) {
×
127
            textfield.setModelObject(vs.replaceFirst("^" + LocalUri.PREFIX, ""));
×
128
        } else if (v instanceof Literal vL) {
×
129
            textfield.setModelObject(Utils.getSerializedLiteral(vL));
×
130
        } else {
131
            textfield.setModelObject(vs);
×
132
        }
133
    }
×
134

135

136
    /**
137
     * Validator class for validating the text field input.
138
     */
139
    protected static class Validator extends InvalidityHighlighting implements IValidator<String> {
140

141
//                private IRI iri;
142
//                private Template template;
143

144
        /**
145
         * Constructor for the validator.
146
         *
147
         * @param iri      the IRI associated with the value
148
         * @param template the template containing the context
149
         */
150
        public Validator(IRI iri, Template template) {
×
151
//                        this.iri = iri;
152
//                        this.template = template;
153
        }
×
154

155
        @Override
156
        public void validate(IValidatable<String> s) {
157
            if (s.getValue().startsWith("\"")) {
×
158
                if (!Utils.isValidLiteralSerialization(s.getValue())) {
×
159
                    s.error(new ValidationError("Invalid literal value"));
×
160
                }
161
                return;
×
162
            }
163
            String p = "";
×
164
            if (s.getValue().matches("[^:# ]+")) p = LocalUri.PREFIX;
×
165
            try {
166
                ParsedIRI piri = new ParsedIRI(p + s.getValue());
×
167
                if (!piri.isAbsolute()) {
×
168
                    s.error(new ValidationError("IRI not well-formed"));
×
169
                }
170
                if (p.isEmpty() && !Utils.isLocalURI(s.getValue()) && !(s.getValue()).matches("https?://.+")) {
×
171
                    s.error(new ValidationError("Only http(s):// IRIs are allowed here"));
×
172
                }
173
            } catch (URISyntaxException ex) {
×
174
                s.error(new ValidationError("IRI not well-formed"));
×
175
            }
×
176
        }
×
177

178
    }
179

180
    /**
181
     * {@inheritDoc}
182
     */
183
    @Override
184
    public void fillFinished() {
185
    }
×
186

187
    /**
188
     * {@inheritDoc}
189
     */
190
    @Override
191
    public void finalizeValues() {
192
        Value defaultValue = context.getTemplate().getDefault(iri);
×
193
        if (isUnifiableWith(defaultValue)) {
×
194
            try {
195
                unifyWith(defaultValue);
×
196
            } catch (UnificationException ex) {
×
197
                logger.error("Unification with default value failed: {}", ex.getMessage());
×
198
            }
×
199
        }
200
    }
×
201

202
    /**
203
     * <p>toString.</p>
204
     *
205
     * @return a {@link java.lang.String} object
206
     */
207
    public String toString() {
208
        return "[value textfield item: " + iri + "]";
×
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