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

knowledgepixels / nanodash / 30606286447

31 Jul 2026 05:15AM UTC coverage: 34.947% (+0.9%) from 34.084%
30606286447

push

github

web-flow
Merge pull request #579 from knowledgepixels/download-tab-doc-export

feat(download): rename Raw tab to Download and add HTML/RTF/PDF page export

2622 of 8308 branches covered (31.56%)

Branch coverage included in aggregate %.

5082 of 13737 relevant lines covered (36.99%)

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

3
import com.knowledgepixels.nanodash.page.ExplorePage;
4
import com.knowledgepixels.nanodash.page.MaintainedResourcePage;
5
import com.knowledgepixels.nanodash.page.ResourcePartPage;
6
import com.knowledgepixels.nanodash.page.SpacePage;
7
import com.knowledgepixels.nanodash.page.UserPage;
8
import org.apache.wicket.behavior.AttributeAppender;
9
import org.apache.wicket.markup.html.WebMarkupContainer;
10
import org.apache.wicket.markup.html.WebPage;
11
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
12
import org.apache.wicket.markup.html.panel.Panel;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14

15
/**
16
 * Tab strip shown at the top of a resource's page, switching between the
17
 * <b>Content</b> tab (the rendered view displays), the <b>About</b> tab (the
18
 * listing of roles/presets/view displays), the <b>Explore</b> tab (the generic
19
 * exploration panels and references), and the <b>Download</b> tab (the
20
 * downloadable document and RDF formats of the page).
21
 *
22
 * <p>All tabs are the same page, selected via the {@code tab} query parameter
23
 * ({@code content} is the default and carries no parameter). Parts
24
 * ({@code type == "part"}) have no About tab.</p>
25
 */
26
public class ResourceTabs extends Panel {
27

28
    /**
29
     * Which tab is currently shown (rendered as the selected tab).
30
     */
31
    public enum Tab {CONTENT, ABOUT, EXPLORE, DOWNLOAD}
×
32

33
    /**
34
     * Maps the {@code tab} query parameter to a {@link Tab} (defaulting to
35
     * {@link Tab#CONTENT}). Used by the resource pages to pick which tab body to
36
     * render and which tab to mark active.
37
     *
38
     * @param parameters the page parameters
39
     * @return the selected tab
40
     */
41
    public static Tab activeFromParam(PageParameters parameters) {
42
        switch (parameters.get("tab").toString("content")) {
×
43
            case "about":
44
                return Tab.ABOUT;
×
45
            case "explore":
46
                return Tab.EXPLORE;
×
47
            case "download":
48
            case "raw": // legacy name of the Download tab, kept for old bookmarks
49
                return Tab.DOWNLOAD;
×
50
            default:
51
                return Tab.CONTENT;
×
52
        }
53
    }
54

55
    /**
56
     * Constructs the tab strip for a top-level resource (space, user, resource).
57
     *
58
     * @param id         the Wicket markup id
59
     * @param type       the resource kind: {@code "space"}, {@code "user"}, or {@code "resource"}
60
     * @param resourceId the resource IRI
61
     * @param active     the tab to mark as selected
62
     */
63
    public ResourceTabs(String id, String type, String resourceId, Tab active) {
64
        this(id, type, resourceId, null, active);
×
65
    }
×
66

67
    /**
68
     * Constructs the tab strip, optionally for a part (which carries a context).
69
     *
70
     * @param id         the Wicket markup id
71
     * @param type       the resource kind: {@code "space"}, {@code "user"}, {@code "resource"}, or {@code "part"}
72
     * @param resourceId the resource (or part) IRI
73
     * @param contextId  the context resource IRI (for parts), or {@code null}
74
     * @param active     the tab to mark as selected
75
     */
76
    public ResourceTabs(String id, String type, String resourceId, String contextId, Tab active) {
77
        this(id, type, resourceId, contextId, active, null);
×
78
    }
×
79

80
    /**
81
     * Constructs the tab strip, optionally pinned to a specific space ref via {@code root}.
82
     *
83
     * @param id         the Wicket markup id
84
     * @param type       the resource kind
85
     * @param resourceId the resource (or part) IRI
86
     * @param contextId  the context resource IRI (for parts), or {@code null}
87
     * @param active     the tab to mark as selected
88
     * @param root       the space ref's root nanopub to carry across tab switches, or {@code null}
89
     */
90
    public ResourceTabs(String id, String type, String resourceId, String contextId, Tab active, String root) {
91
        super(id);
×
92

93
        Class<? extends WebPage> pageClass;
94
        boolean hasAbout;
95
        switch (type) {
×
96
            case "space":
97
                pageClass = SpacePage.class;
×
98
                hasAbout = true;
×
99
                break;
×
100
            case "user":
101
                pageClass = UserPage.class;
×
102
                hasAbout = true;
×
103
                break;
×
104
            case "resource":
105
                pageClass = MaintainedResourcePage.class;
×
106
                hasAbout = true;
×
107
                break;
×
108
            case "part":
109
                pageClass = ResourcePartPage.class;
×
110
                hasAbout = true;
×
111
                break;
×
112
            default:
113
                throw new IllegalArgumentException("Unknown resource type: " + type);
×
114
        }
115

116
        add(tabLink("content-tab", pageClass, params(resourceId, contextId, null, root), active == Tab.CONTENT));
×
117
        if (hasAbout) {
×
118
            add(tabLink("about-tab", pageClass, params(resourceId, contextId, "about", root), active == Tab.ABOUT));
×
119
        } else {
120
            add(new WebMarkupContainer("about-tab").setVisible(false));
×
121
        }
122
        add(tabLink("explore-tab", pageClass, params(resourceId, contextId, "explore", root), active == Tab.EXPLORE));
×
123
        add(tabLink("download-tab", pageClass, params(resourceId, contextId, "download", root), active == Tab.DOWNLOAD));
×
124
    }
×
125

126
    /**
127
     * Constructs a two-tab strip (<b>Content</b> | <b>Explore</b>) for the
128
     * standalone {@link ExplorePage}. Unlike the resource variants this carries
129
     * the page's full parameter set (minus {@code tab}) across tab switches so
130
     * the resolved id, context and label are preserved, and it has neither an
131
     * About nor a Download tab.
132
     *
133
     * @param id         the Wicket markup id
134
     * @param baseParams the explore page's parameters to preserve across tabs
135
     * @param active     the tab to mark as selected
136
     */
137
    public ResourceTabs(String id, PageParameters baseParams, Tab active) {
138
        super(id);
×
139

140
        PageParameters contentParams = new PageParameters(baseParams);
×
141
        contentParams.remove("tab");
×
142
        PageParameters exploreParams = new PageParameters(contentParams);
×
143
        exploreParams.set("tab", "explore");
×
144

145
        add(tabLink("content-tab", ExplorePage.class, contentParams, active == Tab.CONTENT));
×
146
        add(new WebMarkupContainer("about-tab").setVisible(false));
×
147
        add(tabLink("explore-tab", ExplorePage.class, exploreParams, active == Tab.EXPLORE));
×
148
        add(new WebMarkupContainer("download-tab").setVisible(false));
×
149
    }
×
150

151
    /**
152
     * The gray-italic title suffix shown after the resource name on non-content
153
     * tabs (e.g. " – About"); empty for the content tab.
154
     *
155
     * @param tab the active tab
156
     * @return the suffix string (possibly empty)
157
     */
158
    public static String titleSuffix(Tab tab) {
159
        switch (tab) {
×
160
            case ABOUT:
161
                return " – About";
×
162
            case EXPLORE:
163
                return " – Explore";
×
164
            case DOWNLOAD:
165
                return " – Download";
×
166
            default:
167
                return "";
×
168
        }
169
    }
170

171
    private PageParameters params(String resourceId, String contextId, String tab, String root) {
172
        PageParameters p = new PageParameters().set("id", resourceId);
×
173
        if (contextId != null) p.set("context", contextId);
×
174
        if (tab != null) p.set("tab", tab);
×
175
        if (root != null) p.set("root", root);
×
176
        return p;
×
177
    }
178

179
    private BookmarkablePageLink<Void> tabLink(String id, Class<? extends WebPage> pageClass, PageParameters params, boolean selected) {
180
        BookmarkablePageLink<Void> link = new BookmarkablePageLink<>(id, pageClass, params);
×
181
        if (selected) {
×
182
            link.add(new AttributeAppender("class", " selected"));
×
183
        }
184
        return link;
×
185
    }
186

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