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

knowledgepixels / nanodash / 42215086660

06 Nov 2026 12:05PM UTC coverage: 54.828%. Remained the same
42215086660

push

github

web-flow
Merge pull request #894 from knowledgepixels/docs/fix-javadoc-warnings

docs: fix broken Javadoc link and add missing @param tags

6573 of 12818 branches covered (51.28%)

Branch coverage included in aggregate %.

11354 of 19879 relevant lines covered (57.12%)

9.47 hits per line

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

59.79
src/main/java/com/knowledgepixels/nanodash/QueryResult.java
1
package com.knowledgepixels.nanodash;
2

3
import com.knowledgepixels.nanodash.component.NanodashLink;
4
import com.knowledgepixels.nanodash.component.QueryResultComponentFactory;
5
import com.knowledgepixels.nanodash.component.menu.ViewDisplayMenu;
6
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
7
import com.knowledgepixels.nanodash.page.NanodashPage;
8
import com.knowledgepixels.nanodash.page.PublishPage;
9
import com.knowledgepixels.nanodash.page.UserPage;
10
import org.apache.wicket.Component;
11
import org.apache.wicket.markup.ComponentTag;
12
import org.apache.wicket.markup.MarkupStream;
13
import org.apache.wicket.markup.html.WebMarkupContainer;
14
import org.apache.wicket.markup.html.basic.Label;
15
import org.apache.wicket.markup.html.panel.Panel;
16
import org.apache.wicket.request.cycle.RequestCycle;
17
import org.apache.wicket.request.mapper.parameter.PageParameters;
18
import org.apache.wicket.util.string.Strings;
19
import org.nanopub.extra.services.ApiResponse;
20
import org.nanopub.extra.services.QueryRef;
21

22
import java.io.Serializable;
23
import java.util.ArrayList;
24
import java.util.List;
25
import java.util.Objects;
26
import java.util.regex.Matcher;
27
import java.util.regex.Pattern;
28

29
/**
30
 * Abstract base class for displaying query results in different formats.
31
 */
32
public abstract class QueryResult extends Panel {
33

34
    /**
35
     * Leaves the description out, for a view rendered without its title row: the paragraph
36
     * explains a titled view, and on its own above bare results it reads as content.
37
     */
38
    protected void hideDescription() {
39
        descriptionLabel.setVisible(false);
×
40
    }
×
41

42
    /**
43
     * A view-level action, shown as a top entry of the view's dropdown menu.
44
     *
45
     * @param label     the menu entry's text
46
     * @param pageClass the page the entry links to
47
     * @param params    the parameters passed to that page
48
     */
49
    public record MenuAction(String label, Class<? extends NanodashPage> pageClass, PageParameters params) implements Serializable {
36 ✔
50
    }
51

52
    /**
53
     * The note shown where a view has no results to show.
54
     */
55
    protected static final String NOTHING_FOUND_NOTE = "(nothing found)";
56

57
    protected final List<MenuAction> menuActions = new ArrayList<>();
15 ✔
58
    protected String contextId;
59
    protected String partId;
60
    protected String postPublishTab;
61
    // The ref (root definition) this view is pinned to (?root=), used to scope per-entry
62
    // action visibility to the claimant being viewed. Null = the resource's representative
63
    // ref. See docs/space-ref-identity.md.
64
    protected String refRoot;
65
    protected boolean finalized = false;
9 ✔
66
    protected final QueryRef queryRef;
67
    protected final ViewDisplay viewDisplay;
68
    protected final ApiResponse response;
69
    protected AbstractResourceWithProfile resourceWithProfile;
70
    protected AbstractResourceWithProfile pageResource;
71
    protected boolean showViewDisplayMenu = true;
9 ✔
72
    protected final GrlcQuery grlcQuery;
73

74
    /**
75
     * The view's description, shown below its title. See {@link #hideDescription()}.
76
     */
77
    private final Label descriptionLabel;
78

79
    /**
80
     * Constructor for QueryResult.
81
     *
82
     * @param markupId    the markup ID
83
     * @param queryRef    the query reference
84
     * @param response    the API response
85
     * @param viewDisplay the view display
86
     */
87
    public QueryResult(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
88
        super(markupId);
9 ✔
89
        this.queryRef = queryRef;
9 ✔
90
        this.viewDisplay = viewDisplay;
9 ✔
91
        this.response = response;
9 ✔
92
        this.grlcQuery = GrlcQuery.get(queryRef);
12 ✔
93

94
        // Every view carries an id in the rendered page, so that it can be replaced on its
95
        // own over Ajax — which is how "refresh now" updates one view without re-rendering
96
        // the page. Without it the replacement would be written under an id the browser has
97
        // never seen, leaving the old markup (and its now-removed links) in place.
98
        setOutputMarkupId(true);
12 ✔
99

100
        // The spinner shown beside the title while this view's results are being brought up
101
        // to date; hidden until someone turns it on (see RefreshingResultPanel). It lives in
102
        // the title row, right after the title, where the row's own layout keeps it clear of
103
        // everything — see the .refresh-spinner rules in style.css.
104
        //
105
        // When the results are older than a refresh that failed, the same spot holds a short
106
        // note saying so instead (issue #889). Results from the cache look current otherwise,
107
        // and the query may keep failing for a while.
108
        refreshFailed = response != null && ApiCache.lastAttemptFailed(queryRef);
30 !
109
        refreshIndicator = new WebMarkupContainer("refresh-indicator") {
42 ✔
110

111
            @Override
112
            protected void onConfigure() {
113
                super.onConfigure();
6 ✔
114
                setVisible(refreshing || refreshFailed);
42 ✔
115
            }
3 ✔
116

117
            @Override
118
            protected void onComponentTag(ComponentTag tag) {
119
                super.onComponentTag(tag);
9 ✔
120
                if (!refreshing) {
12 ✔
121
                    tag.put("class", "refresh-failed");
12 ✔
122
                    tag.put("title", "The query failed when it was last run. These results are from an earlier run.");
12 ✔
123
                }
124
            }
3 ✔
125

126
            @Override
127
            public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
128
                if (refreshing) {
12 ✔
129
                    super.onComponentTagBody(markupStream, openTag);
15 ✔
130
                } else {
131
                    replaceComponentTagBody(markupStream, openTag, REFRESH_FAILED_NOTE);
15 ✔
132
                }
133
            }
3 ✔
134

135
        };
136
        refreshIndicator.setOutputMarkupPlaceholderTag(true);
15 ✔
137
        add(refreshIndicator);
30 ✔
138

139
        // The view's explaining paragraph, below its title (issue #735). Every view kind
140
        // shows it the same way, so it is added here rather than in each of them; a view
141
        // that declares none, and one rendered without its title row, show nothing (see
142
        // hideDescription).
143
        String description = viewDisplay == null ? null : viewDisplay.getDescription();
15 !
144
        // Markup is allowed and was sanitized when the view was read, as elsewhere.
145
        descriptionLabel = new Label("description", description);
21 ✔
146
        descriptionLabel.setEscapeModelStrings(false);
15 ✔
147
        descriptionLabel.setVisible(description != null && !description.isBlank());
21 !
148
        add(descriptionLabel);
30 ✔
149
    }
3 ✔
150

151
    private final WebMarkupContainer refreshIndicator;
152
    private boolean refreshing = false;
9 ✔
153
    private boolean refreshFailed;
154

155
    /**
156
     * The note shown beside the title of a view whose results are older than a refresh that
157
     * failed.
158
     */
159
    public static final String REFRESH_FAILED_NOTE = "Couldn't refresh, showing older results";
160

161
    /**
162
     * The query reference this view's results come from.
163
     *
164
     * @return the query reference
165
     */
166
    public QueryRef getQueryRef() {
167
        return queryRef;
×
168
    }
169

170
    /**
171
     * The results this view is showing. Available to the action-link builder, which runs
172
     * after the response has arrived, so a view-level action can take a value from the rows
173
     * (see {@link com.knowledgepixels.nanodash.component.ViewActionMappings}).
174
     *
175
     * @return the API response
176
     */
177
    public ApiResponse getApiResponse() {
178
        return response;
9 ✔
179
    }
180

181
    /**
182
     * The version of the view definition this view display is showing, as the id to hand to
183
     * {@link View#refreshLatestVersion(String)} when checking for a newer one.
184
     *
185
     * @return the shown view's id, or null if this result has no view behind it
186
     */
187
    public String getShownViewId() {
188
        View view = (viewDisplay == null ? null : viewDisplay.getView());
×
189
        return view == null ? null : view.getId();
×
190
    }
191

192
    /**
193
     * Shows or hides the spinner beside this view's title.
194
     *
195
     * @param refreshing true while the view's results are being brought up to date
196
     */
197
    public void setRefreshing(boolean refreshing) {
198
        this.refreshing = refreshing;
9 ✔
199
    }
3 ✔
200

201
    /**
202
     * Sets whether this view's results are older than a refresh that failed, which puts a
203
     * short note beside the title while no spinner is showing there.
204
     *
205
     * @param refreshFailed true if the latest refresh of these results failed or timed out
206
     */
207
    public void setRefreshFailed(boolean refreshFailed) {
208
        this.refreshFailed = refreshFailed;
9 ✔
209
    }
3 ✔
210

211
    /**
212
     * The spinner component itself (or the note in its place), so a caller that changes it
213
     * over Ajax can repaint just that instead of the whole view.
214
     *
215
     * @return the refresh indicator
216
     */
217
    public Component getRefreshIndicator() {
218
        return refreshIndicator;
9 ✔
219
    }
220

221
    /**
222
     * Builds this view again from the current state of the cache, as a component that can
223
     * take this one's place. Used to refresh a single view where it stands (see the "refresh
224
     * now" entry of its menu) instead of re-rendering the page around it.
225
     * <p>
226
     * With the view's results just marked as outdated, the rebuild comes back as the results
227
     * that are on screen now plus a spinner, which swaps in the new ones by itself once the
228
     * query has run.
229
     *
230
     * @param markupId the id the replacement must take, i.e. that of the component it replaces
231
     * @return the replacement component
232
     */
233
    public Component rebuild(String markupId) {
234
        // The part id is only set when it differs from the context; otherwise the view is
235
        // shown for the context resource itself.
236
        String id = partId != null ? partId : contextId;
×
237
        Component rebuilt = QueryResultComponentFactory.build(markupId, queryRef, viewDisplay,
×
238
                resourceWithProfile, id, contextId, refRoot);
239
        if (rebuilt != null) rebuilt.setOutputMarkupId(true);
×
240
        return rebuilt;
×
241
    }
242

243
    @Override
244
    protected void onBeforeRender() {
245
        if (!finalized) {
9 !
246
            // View-level actions used to render as a button strip in the header here;
247
            // they now live as the top entries of the view's dropdown menu instead.
248
            add(new Label("buttons").setVisible(false));
42 ✔
249
            if (showViewDisplayMenu) {
9 !
250
                if (viewDisplay.getNanopubId() != null || !menuActions.isEmpty()) {
24 !
251
                    add(new ViewDisplayMenu("np", viewDisplay, queryRef, pageResource, menuActions));
×
252
                } else {
253
                    add(new Label("np").setVisible(false));
42 ✔
254
                }
255
            }
256
            finalized = true;
9 ✔
257
        }
258
        super.onBeforeRender();
6 ✔
259
    }
3 ✔
260

261
    /**
262
     * The view-level actions to render as top entries of the view's dropdown menu.
263
     *
264
     * @return the collected view-level menu actions
265
     */
266
    public List<MenuAction> getMenuActions() {
267
        return menuActions;
9 ✔
268
    }
269

270
    /**
271
     * Set the resource with profile for this component.
272
     *
273
     * @param resourceWithProfile The resource with profile to set.
274
     */
275
    public void setResourceWithProfile(AbstractResourceWithProfile resourceWithProfile) {
276
        this.resourceWithProfile = resourceWithProfile;
×
277
    }
×
278

279
    public void setPageResource(AbstractResourceWithProfile pageResource) {
280
        this.pageResource = pageResource;
9 ✔
281
    }
3 ✔
282

283
    /**
284
     * Set the context ID for this component.
285
     *
286
     * @param contextId The context ID to set.
287
     */
288
    public void setContextId(String contextId) {
289
        this.contextId = contextId;
9 ✔
290
    }
3 ✔
291

292
    /**
293
     * Set the part ID when this view is shown on a part page (e.g. paper collection).
294
     * Used for redirect-after-publish to return to the part page.
295
     *
296
     * @param partId The part ID to set, or null when on the main context page.
297
     */
298
    public void setPartId(String partId) {
299
        this.partId = partId;
×
300
    }
×
301

302
    /**
303
     * Set the tab to return to after publishing one of this view's action
304
     * buttons (e.g. {@code "about"} so a space's About-tab views send the user
305
     * back to About instead of the default Content tab). Null leaves the
306
     * post-publish redirect on its default tab.
307
     *
308
     * @param postPublishTab the tab name, or null for the default
309
     */
310
    public void setPostPublishTab(String postPublishTab) {
311
        this.postPublishTab = postPublishTab;
×
312
    }
×
313

314
    /**
315
     * Set the ref (root definition) this view is pinned to, so per-entry action visibility
316
     * is gated against that claimant's authority rather than the resource's representative
317
     * ref. Null = representative ref. See docs/space-ref-identity.md.
318
     *
319
     * @param refRoot the ref's root nanopub, or null
320
     */
321
    public void setRefRoot(String refRoot) {
322
        this.refRoot = refRoot;
×
323
    }
×
324

325
    /**
326
     * @return the tab to return to after publishing via an action button, or null for the default
327
     */
328
    public String getPostPublishTab() {
329
        return postPublishTab;
9 ✔
330
    }
331

332
    // A view-level action button; collected here and rendered as a top entry of the
333
    // view's dropdown menu (see ViewDisplayMenu).
334
    public void addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
335
        if (parameters == null) {
6 !
336
            parameters = new PageParameters();
×
337
        }
338
        if (contextId != null) {
9 !
339
            parameters.set("context", contextId);
×
340
        }
341
        menuActions.add(new MenuAction(label, pageClass, parameters));
30 ✔
342
    }
3 ✔
343

344
    /**
345
     * The navigation context to stamp on links in result cells: this view's context
346
     * resource if bound to one, else the page's navigation context. Only usable at
347
     * render time (needs the page). Visible to the view types that build their links
348
     * as URLs rather than components (see the network view).
349
     *
350
     * @return the context id, or null if neither is set
351
     */
352
    protected String renderContextId() {
353
        if (contextId != null) return contextId;
18 ✔
354
        if (getPage() instanceof NanodashPage nanodashPage) return nanodashPage.getContextId();
18 !
355
        return null;
6 ✔
356
    }
357

358
    /**
359
     * The resource part to stamp on links in result cells, next to
360
     * {@link #renderContextId()}: the part this view is bound to, else the part the page
361
     * was reached under. A part only travels together with its own context (issue #697),
362
     * so it is dropped when the links carry a different one. Only usable at render time.
363
     *
364
     * @return the part id, or null if none applies
365
     */
366
    private String renderPartId() {
367
        if (partId != null) return partId;
9 !
368
        if (getPage() instanceof NanodashPage nanodashPage
18 !
369
                && Objects.equals(renderContextId(), nanodashPage.getIncomingContextId())) {
×
370
            return nanodashPage.getPartId();
×
371
        }
372
        return null;
6 ✔
373
    }
374

375
    /**
376
     * The label to carry along with {@link #renderPartId()}, so the target page's
377
     * back-link can name the part. Only known where the page is the part's own.
378
     *
379
     * @return the part label, or null if none is known
380
     */
381
    private String renderPartLabel() {
382
        if (getPage() instanceof NanodashPage nanodashPage
18 !
383
                && Objects.equals(renderPartId(), nanodashPage.getPartId())) {
×
384
            return nanodashPage.getPartLabel();
×
385
        }
386
        return null;
6 ✔
387
    }
388

389
    /**
390
     * A page reference for a result row's own resource part, reached from this view: the
391
     * part page of the given IRI under this view's navigation context, carrying the given
392
     * label as the page title where the part declares none, plus the part this page was
393
     * reached under so the target's back-link can name it (issue #697). Only usable at
394
     * render time (needs the page).
395
     *
396
     * @param partId the row's resource IRI
397
     * @param label  the label to show for it, or null to fall back to its short name
398
     * @return the page reference, or null when no navigation context is known (a part
399
     * page cannot resolve a part without its maintaining resource)
400
     */
401
    protected NanodashPageRef partPageRef(String partId, String label) {
402
        String ctx = renderContextId();
9 ✔
403
        NanodashPageRef ref = NavigationContext.getPartPageRef(partId, label, ctx);
15 ✔
404
        if (ref == null) return null;
12 ✔
405
        NavigationContext.withPart(ref.getParameters(), renderPartId(), renderPartLabel(), ctx);
27 ✔
406
        return ref;
6 ✔
407
    }
408

409
    /**
410
     * The navigation parameters to append to a hand-built app-internal link in a result
411
     * cell: the {@code &context=...} suffix, plus the resource part the page was reached
412
     * under where that applies (issue #697). Empty string when no context is set. Only
413
     * usable at render time (needs the page).
414
     *
415
     * @param url the link the parameters are appended to, or null if not known yet
416
     * @return the URL parameter suffix, possibly empty
417
     */
418
    protected String linkNavParams(String url) {
419
        // Not for a crawler: these say where the visitor came from, and adding them makes
420
        // one target page a different URL per route, which is a crawl of the cross-product
421
        // (issue #804). A link that needs its context to resolve at all -- a resource part,
422
        // which cannot be found without its maintaining resource -- is not built here but
423
        // through NavigationContext.getPartPageRef, and keeps it.
424
        if (CrawlerRequest.isCrawler()) return "";
6 !
425
        String ctx = renderContextId();
9 ✔
426
        if (ctx == null) return "";
12 !
427
        StringBuilder params = new StringBuilder("&context=").append(Utils.urlEncode(ctx));
×
428
        String part = renderPartId();
×
429
        // Not on a link to the part itself, nor on one up to the resource maintaining
430
        // it: the part is then either the destination or behind the user.
431
        if (part != null && !namesResource(url, part) && !namesResource(url, ctx)) {
×
432
            params.append("&part=").append(Utils.urlEncode(part));
×
433
            String partLabel = renderPartLabel();
×
434
            if (partLabel != null && !partLabel.isBlank()) {
×
435
                params.append("&part-label=").append(Utils.urlEncode(partLabel));
×
436
            }
437
        }
438
        return params.toString();
×
439
    }
440

441
    /**
442
     * The URL for a result row's agent cell: the person's part page under this view's
443
     * navigation context where that context shows something about people, else their own
444
     * page. Carries the name the row already resolved, so the part page is titled with it
445
     * rather than with the bare ORCID number.
446
     * <p>
447
     * A cell naming a person is built as a plain {@code href} rather than through
448
     * {@link NanodashLink}, so neither its routing nor the navigation-parameter behaviors
449
     * reach it. That is why a space's own listings -- its organizers, its programme
450
     * committee -- led to the general profile while the same person clicked in an ordinary
451
     * IRI cell led to their page in that space (issue #822).
452
     *
453
     * @param agentIri the person's IRI
454
     * @param label    the name shown for them, or null if none was resolved
455
     * @return the cell link's URL, navigation parameters included
456
     */
457
    protected String agentCellUrl(String agentIri, String label) {
458
        if (NanodashLink.leadsToAgentPartPage(agentIri, renderContextId())) {
×
459
            NanodashPageRef partRef = partPageRef(agentIri, label);
×
460
            if (partRef != null) {
×
461
                return RequestCycle.get().urlFor(partRef.getPageClass(), partRef.getParameters()).toString();
×
462
            }
463
        }
464
        String url = UserPage.MOUNT_PATH + "?id=" + Utils.urlEncode(agentIri);
×
465
        return url + linkNavParams(url);
×
466
    }
467

468
    /**
469
     * Whether the given app-internal link points at the given resource, i.e. carries it
470
     * as its {@code id}. The sanitizer writes "=" as "&#61;", so both spellings count.
471
     *
472
     * @param url        the link to check, or null
473
     * @param resourceId the resource id to look for
474
     * @return true if the link's id is that resource
475
     */
476
    static boolean namesResource(String url, String resourceId) {
477
        if (url == null) return false;
12 ✔
478
        String encoded = Utils.urlEncode(resourceId);
9 ✔
479
        return url.contains("id=" + encoded) || url.contains("id&#61;" + encoded);
42 ✔
480
    }
481

482
    private static final Pattern INTERNAL_HREF_PATTERN = Pattern.compile("href=\"(/[^\"]*)\"");
9 ✔
483

484
    /**
485
     * Appends the navigation context, and the resource part where one applies, to
486
     * app-internal links ({@code href="/..."}) inside sanitized result-cell HTML, so
487
     * ready-made links coming from the query data itself (e.g. template or query links
488
     * emitted by the SPARQL) also lead back to where the user came from. Links already
489
     * carrying a context are left alone.
490
     *
491
     * @param sanitizedHtml the sanitized cell HTML, or null
492
     * @return the HTML with context-enriched internal links
493
     */
494
    protected String withNavParamsInHtmlLinks(String sanitizedHtml) {
495
        if (renderContextId() == null || sanitizedHtml == null) return sanitizedHtml;
21 !
496
        Matcher m = INTERNAL_HREF_PATTERN.matcher(sanitizedHtml);
12 ✔
497
        StringBuilder sb = new StringBuilder();
12 ✔
498
        while (m.find()) {
9 !
499
            String url = m.group(1);
×
500
            String replacement = m.group();
×
501
            // The sanitizer escapes "=" as "&#61;", so check both spellings.
502
            if (!url.contains("context=") && !url.contains("context&#61;")) {
×
503
                String separator = url.contains("?") ? "&amp;" : "?";
×
504
                // The suffix starts with "&", which the separator replaces.
505
                replacement = "href=\"" + url + separator + linkNavParams(url).substring(1).replace("&", "&amp;") + "\"";
×
506
            }
507
            m.appendReplacement(sb, Matcher.quoteReplacement(replacement));
×
508
        }
×
509
        m.appendTail(sb);
12 ✔
510
        return sb.toString();
9 ✔
511
    }
512

513
    // An "<a ...>" start tag in sanitized cell HTML, with its attribute part.
514
    private static final Pattern ANCHOR_TAG_PATTERN = Pattern.compile("<a\\b([^>]*)>", Pattern.CASE_INSENSITIVE);
12 ✔
515
    private static final Pattern HREF_ATTRIBUTE_PATTERN = Pattern.compile("href=\"([^\"]*)\"");
12 ✔
516

517
    // The look given to publish links in result content: the small transparent button
518
    // used for secondary actions elsewhere in the app.
519
    private static final String PUBLISH_BUTTON_CLASSES = "smallbutton button light";
520

521
    /**
522
     * Prepares raw HTML coming from query data for display in result content: it is
523
     * sanitized, its app-internal links get the navigation context, and its links to
524
     * the publish form are turned into buttons.
525
     *
526
     * @param rawHtml the raw HTML from the query data, or null
527
     * @return the sanitized and enriched HTML
528
     */
529
    protected String cellHtml(String rawHtml) {
530
        return withPublishLinksAsButtons(withNavParamsInHtmlLinks(Utils.sanitizeHtml(rawHtml)));
18 ✔
531
    }
532

533
    /**
534
     * Shows links to the publish form as buttons, so that the actions a view offers
535
     * stand out from the links to content. Only links that don't bring their own class
536
     * are styled.
537
     *
538
     * @param sanitizedHtml the sanitized cell HTML, or null
539
     * @return the HTML with publish links marked as buttons
540
     */
541
    protected static String withPublishLinksAsButtons(String sanitizedHtml) {
542
        if (sanitizedHtml == null) return null;
12 ✔
543
        Matcher m = ANCHOR_TAG_PATTERN.matcher(sanitizedHtml);
12 ✔
544
        StringBuilder sb = new StringBuilder();
12 ✔
545
        while (m.find()) {
9 ✔
546
            String attributes = m.group(1);
12 ✔
547
            String replacement = m.group();
9 ✔
548
            Matcher hrefMatcher = HREF_ATTRIBUTE_PATTERN.matcher(attributes);
12 ✔
549
            if (hrefMatcher.find() && isPublishLink(hrefMatcher.group(1)) && !attributes.contains("class=")) {
36 !
550
                replacement = "<a class=\"" + PUBLISH_BUTTON_CLASSES + "\"" + attributes + ">";
9 ✔
551
            }
552
            m.appendReplacement(sb, Matcher.quoteReplacement(replacement));
18 ✔
553
        }
3 ✔
554
        m.appendTail(sb);
12 ✔
555
        return sb.toString();
9 ✔
556
    }
557

558
    /**
559
     * Whether the given value is a link to the publish form, i.e. the app-internal
560
     * {@code /publish} path, with or without query parameters. Only the path is
561
     * checked, so the sanitizer's escaping inside the parameters (it writes "=" as
562
     * "&#61;") makes no difference.
563
     *
564
     * @param value the value to check, or null
565
     * @return true if the value is a publish link
566
     */
567
    public static boolean isPublishLink(String value) {
568
        if (value == null) return false;
12 ✔
569
        return value.split("[?#]", 2)[0].equals(PublishPage.MOUNT_PATH);
27 ✔
570
    }
571

572
    /**
573
     * The content for a publish link that comes as a plain cell value: a button
574
     * carrying the label from the sibling label column where there is one, and a
575
     * generic label otherwise.
576
     *
577
     * @param url   the publish link
578
     * @param label the label from the sibling label column, or null
579
     * @return the HTML for the button
580
     */
581
    protected String publishButtonHtml(String url, String label) {
582
        String text = (label == null || label.isBlank() || label.equals(url)) ? "publish…" : label;
×
583
        String inner = Utils.looksLikeHtml(text) ? text : Strings.escapeMarkup(text).toString();
×
584
        return cellHtml("<a href=\"" + Strings.escapeMarkup(url) + "\">" + inner + "</a>");
×
585
    }
586

587
    /**
588
     * Whether all result rows fit on the first page, so no pagination is needed
589
     * and the filter textfield can be hidden. Also true when the page size is
590
     * unlimited ({@code < 1}).
591
     *
592
     * @return true if all entries fit on the first page
593
     */
594
    protected boolean fitsOnFirstPage() {
595
        int pageSize = viewDisplay.getPageSize();
15 ✔
596
        return pageSize < 1 || response.getData().size() <= pageSize;
36 !
597
    }
598

599
    /**
600
     * Whether the empty state should point the viewer to the view-level actions:
601
     * the underlying response (not just a filtered view of it) has no rows, and
602
     * there is at least one action the viewer is entitled to.
603
     *
604
     * @return true if the empty-state call-to-action buttons should show
605
     */
606
    protected boolean hasEmptyStateActions() {
607
        return response.getData().isEmpty() && !menuActions.isEmpty();
33 !
608
    }
609

610
    /**
611
     * Whether this view has nothing at all to put on the page: no rows, and no action to
612
     * offer in their place. A view display marked {@link ViewDisplay#hiddenWhenEmpty()}
613
     * leaves the page in that case instead of printing the empty note.
614
     *
615
     * @return true if there is neither a row nor an action to show
616
     */
617
    public boolean hasNothingToShow() {
618
        return response != null && response.getData().isEmpty() && !hasEmptyStateActions();
45 !
619
    }
620

621
    /**
622
     * The note to print in place of the results. A view display may override it (see
623
     * {@link ViewDisplay#withEmptyMessage(String)}), but only for a genuinely empty
624
     * result: the same note also covers "the filter matched no row", where a message
625
     * written to speak for the whole page would be a lie.
626
     *
627
     * @return the note to show instead of results
628
     */
629
    protected String emptyNote() {
630
        String message = viewDisplay.getEmptyMessage();
12 ✔
631
        if (message != null && response != null && response.getData().isEmpty()) return message;
36 !
632
        return NOTHING_FOUND_NOTE;
6 ✔
633
    }
634

635
    /**
636
     * Populate the component with the query results.
637
     */
638
    protected abstract void populateComponent();
639

640
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc