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

knowledgepixels / nanopub-registry / 21069544356

16 Jan 2026 02:16PM UTC coverage: 14.268% (+2.3%) from 11.926%
21069544356

push

github

ashleycaselli
docs(Page): add missing Javadoc annotations

70 of 588 branches covered (11.9%)

Branch coverage included in aggregate %.

269 of 1788 relevant lines covered (15.04%)

2.53 hits per line

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

74.67
src/main/java/com/knowledgepixels/registry/Page.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import io.vertx.core.http.HttpMethod;
5
import io.vertx.ext.web.RoutingContext;
6
import org.apache.commons.lang.StringEscapeUtils;
7

8
import java.io.IOException;
9
import java.text.DecimalFormat;
10

11
import static com.knowledgepixels.registry.RegistryDB.*;
12

13
public abstract class Page {
14

15
    protected static final DecimalFormat df8 = new DecimalFormat("0.00000000");
15✔
16
    protected static final DecimalFormat df1 = new DecimalFormat("0.0");
18✔
17

18
    private RoutingContext context;
19
    protected ClientSession mongoSession;
20

21
    private String presentationFormat;
22
    private String extension;
23
    private String requestString;
24

25
    /**
26
     * Constructor for the Page class.
27
     *
28
     * @param mongoSession The MongoDB client session.
29
     * @param context      The routing context.
30
     */
31
    public Page(ClientSession mongoSession, RoutingContext context) {
6✔
32
        this.mongoSession = mongoSession;
9✔
33
        this.context = context;
9✔
34
        context.response().setChunked(true);
15✔
35

36
        // TODO See whether we can cache these better on our side. Not sure how efficient the MongoDB caching is for these
37
        //      kinds of DB queries...
38
        context.response().putHeader("Nanopub-Registry-Status", (String) getValue(mongoSession, Collection.SERVER_INFO.toString(), "status"));
33✔
39
        context.response().putHeader("Nanopub-Registry-Setup-Id", (String) getValue(mongoSession, Collection.SERVER_INFO.toString(), "setupId"));
33✔
40
        context.response().putHeader("Nanopub-Registry-Trust-State-Counter", (String) getValue(mongoSession, Collection.SERVER_INFO.toString(), "trustStateCounter"));
33✔
41
        context.response().putHeader("Nanopub-Registry-Last-Trust-State-Update", (String) getValue(mongoSession, Collection.SERVER_INFO.toString(), "lastTrustStateUpdate"));
33✔
42
        context.response().putHeader("Nanopub-Registry-Trust-State-Hash", (String) getValue(mongoSession, Collection.SERVER_INFO.toString(), "trustStateHash"));
33✔
43
        context.response().putHeader("Nanopub-Registry-Load-Counter", (String) getMaxValue(mongoSession, Collection.NANOPUBS.toString(), "counter"));
33✔
44
        context.response().putHeader("Nanopub-Registry-Test-Instance", String.valueOf(isSet(mongoSession, Collection.SERVER_INFO.toString(), "testInstance")));
33✔
45

46
        String r = context.request().path().substring(1);
18✔
47
        if (r.endsWith(".txt")) {
12✔
48
            presentationFormat = "text/plain";
9✔
49
            r = r.replaceFirst("\\.txt$", "");
18✔
50
        } else if (r.endsWith(".html")) {
12✔
51
            presentationFormat = "text/html";
9✔
52
            r = r.replaceFirst("\\.html$", "");
15✔
53
//                } else if (r.endsWith(".gz")) {
54
//                        presentationFormat = "application/x-gzip";
55
//                        r = r.replaceFirst("\\.gz$", "");
56
        }
57
        if (r.matches(".*\\.[a-z]{1,10}")) {
12✔
58
            extension = r.replaceFirst("^.*\\.([a-z]{1,10})$", "$1");
18✔
59
            requestString = r.replaceFirst("^(.*)\\.[a-z]{1,10}$", "$1");
21✔
60
        } else {
61
            requestString = r;
9✔
62
        }
63
    }
3✔
64

65
    /**
66
     * Get the routing context.
67
     *
68
     * @return The routing context.
69
     */
70
    public RoutingContext getContext() {
71
        return context;
9✔
72
    }
73

74
    /**
75
     * Print a line to the response.
76
     *
77
     * @param s The string to print.
78
     */
79
    public void println(String s) {
80
        print(s + "\n");
×
81
    }
×
82

83
    /**
84
     * Print a string to the response.
85
     *
86
     * @param s The string to print.
87
     */
88
    public void print(String s) {
89
        if (context.request().method() == HttpMethod.HEAD) {
×
90
            return;
×
91
        }
92
        context.response().write(s);
×
93
    }
×
94

95
    /**
96
     * Set the response content type.
97
     *
98
     * @param contentType The content type.
99
     */
100
    public void setRespContentType(String contentType) {
101
        if (context.request().method() == HttpMethod.HEAD) {
18✔
102
            return;
3✔
103
        }
104
        context.response().putHeader("Content-Type", contentType);
21✔
105
    }
3✔
106

107
    /**
108
     * Show the page.
109
     *
110
     * @throws IOException
111
     */
112
    protected abstract void show() throws IOException;
113

114
    /**
115
     * Print the HTML header.
116
     *
117
     * @param title The title of the page.
118
     */
119
    public void printHtmlHeader(String title) {
120
        println("<!DOCTYPE HTML>");
×
121
        println("<html><head>");
×
122
        println("<title>" + title + "</title>");
×
123
        println("<meta charset=\"utf-8\"/>");
×
124
        println("<script type=\"text/javascript\" src=\"/scripts/nanopub.js\"></script>");
×
125
        println("<link rel=\"stylesheet\" href=\"/style.css\" type=\"text/css\" media=\"screen\" title=\"Stylesheet\" />");
×
126
        println("</head><body>");
×
127
    }
×
128

129
    /**
130
     * Print the HTML footer.
131
     */
132
    public void printHtmlFooter() {
133
        println("</body></html>");
×
134
    }
×
135

136
    /**
137
     * Escape HTML special characters in a string.
138
     *
139
     * @param text The text to escape.
140
     * @return The escaped text.
141
     */
142
    public String escapeHtml(String text) {
143
        return StringEscapeUtils.escapeHtml(text);
×
144
    }
145

146
    /**
147
     * Set the canonical link for this page.
148
     *
149
     * @param url The canonical URL.
150
     */
151
    public void setCanonicalLink(String url) {
152
        context.response().putHeader("Link", "<" + url + ">; rel=\"canonical\"");
24✔
153
    }
3✔
154

155
    /**
156
     * Get the presentation format requested, if any.
157
     *
158
     * @return The presentation format.
159
     */
160
    public String getPresentationFormat() {
161
        return presentationFormat;
9✔
162
    }
163

164
    /**
165
     * Get the extension requested, if any.
166
     *
167
     * @return The extension.
168
     */
169
    public String getExtension() {
170
        return extension;
9✔
171
    }
172

173
    /**
174
     * Get the request string with the leading slash and without extension.
175
     *
176
     * @return The request string.
177
     */
178
    public String getRequestString() {
179
        return "/" + requestString;
12✔
180
    }
181

182
    /**
183
     * Get the full request path.
184
     *
185
     * @return The full request path.
186
     */
187
    public String getFullRequest() {
188
        return context.request().path();
15✔
189
    }
190

191
    /**
192
     * Get a parameter from the request.
193
     *
194
     * @param name         The name of the parameter.
195
     * @param defaultValue The default value of the parameter.
196
     * @return The value of the parameter.
197
     */
198
    public String getParam(String name, String defaultValue) {
199
        String value = context.request().getParam(name);
18✔
200
        if (value == null) value = defaultValue;
12✔
201
        return value;
6✔
202
    }
203

204
    /**
205
     * Check whether the request is empty.
206
     *
207
     * @return True if the request is empty, false otherwise.
208
     */
209
    public boolean isEmpty() {
210
        return requestString.isEmpty();
12✔
211
    }
212

213
    /**
214
     * Check whether the request contains an artifact code.
215
     *
216
     * @return True if the request contains an artifact code, false otherwise.
217
     */
218
    public boolean hasArtifactCode() {
219
        return requestString.matches("RA[A-Za-z0-9\\-_]{43}");
15✔
220
    }
221

222
    /**
223
     * Get the artifact code from the request, if present.
224
     *
225
     * @return The artifact code, or null if not present.
226
     */
227
    public String getArtifactCode() {
228
        if (hasArtifactCode()) {
9✔
229
            return requestString;
9✔
230
        }
231
        return null;
6✔
232
    }
233

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