Skip to content

Commit 7c1b163

Browse files
authored
Merge pull request #684 from internetarchive/ato/autocomplete
Config editor: implement autocompletion
2 parents ab41c7a + c0e5018 commit 7c1b163

File tree

5 files changed

+346
-16
lines changed

5 files changed

+346
-16
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ updates:
1515
- dependency-name: "org.eclipse.jetty:jetty-bom"
1616
versions: "[12.1,)"
1717
- dependency-name: "org.eclipse.jetty.ee10:jetty-ee10-bom"
18-
versions: "[12.1,)"
19-
- dependency-name: "org.webjars.npm:codemirror"
18+
versions: "[12.1,)"

engine/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@
101101
<artifactId>webjars-locator-lite</artifactId>
102102
<version>1.1.2</version>
103103
</dependency>
104-
<dependency>
105-
<groupId>org.webjars.npm</groupId>
106-
<artifactId>codemirror</artifactId>
107-
<version>6.0.1</version>
108-
</dependency>
109104
<dependency>
110105
<groupId>org.webjars.npm</groupId>
111106
<artifactId>codemirror__autocomplete</artifactId>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of the Heritrix web crawler (crawler.archive.org).
3+
*
4+
* Licensed to the Internet Archive (IA) by one or more individual
5+
* contributors.
6+
*
7+
* The IA licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.archive.crawler.restlet;
20+
21+
import org.apache.commons.codec.digest.DigestUtils;
22+
import org.restlet.data.MediaType;
23+
import org.restlet.data.Status;
24+
import org.restlet.data.Tag;
25+
import org.restlet.representation.Representation;
26+
import org.restlet.representation.StringRepresentation;
27+
import org.restlet.resource.Get;
28+
import org.restlet.resource.ServerResource;
29+
30+
import java.io.IOException;
31+
import java.net.URL;
32+
import java.nio.charset.StandardCharsets;
33+
import java.util.Collections;
34+
import java.util.Enumeration;
35+
36+
public class BeanDocResource extends ServerResource {
37+
private static Tag etag = null;
38+
39+
@Get("json")
40+
public Representation getBeans() throws IOException {
41+
if (etag != null && getRequest().getConditions().getNoneMatch().contains(etag)) {
42+
getResponse().setStatus(Status.REDIRECTION_NOT_MODIFIED);
43+
return null;
44+
}
45+
var resources = getClass().getClassLoader().getResources("META-INF/heritrix-beans.json");
46+
var json = concatenateJsonObjects(resources);
47+
var representation = new StringRepresentation(json, MediaType.APPLICATION_JSON);
48+
if (etag == null) etag = new Tag(DigestUtils.md5Hex(json));
49+
representation.setTag(etag);
50+
return representation;
51+
}
52+
53+
private static String concatenateJsonObjects(Enumeration<URL> resources) throws IOException {
54+
var builder = new StringBuilder("{");
55+
for (var url : Collections.list(resources)) {
56+
try (var stream = url.openStream()) {
57+
var json = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
58+
if (json.isEmpty()) continue;
59+
if (builder.length() > 1) builder.append(",");
60+
61+
// strip leading '{' and trailing '}' (we just assume no whitespace)
62+
builder.append(json, 1, json.length() - 1);
63+
}
64+
}
65+
builder.append("}");
66+
return builder.toString();
67+
}
68+
}

engine/src/main/java/org/archive/crawler/restlet/EngineApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public Restlet createInboundRoot() {
7474
.setMatchingMode(Template.MODE_EQUALS);
7575
router.attach("/engine/",EngineResource.class)
7676
.setMatchingMode(Template.MODE_EQUALS);
77+
router.attach("/engine/beandoc", BeanDocResource.class);
7778

7879
Directory alljobsdir = new Directory(
7980
getContext(),

0 commit comments

Comments
 (0)