Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f55cdf8

Browse files
committedNov 7, 2024·
Start adding files such as the fonts to the server as local files
1 parent 461db91 commit f55cdf8

9 files changed

+3175
-2
lines changed
 

‎src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java

+34
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,35 @@ public void handle(HttpExchange httpExchange) throws IOException {
852852
}
853853
} // end static class FileHandler
854854

855+
/**
856+
* Serve a content file (image, font, etc) from the filesystem or classpath
857+
*/
858+
public static class BytesFileHandler implements HttpHandler {
859+
private final byte[] content;
860+
private final String contentType;
861+
public BytesFileHandler(String fileOrClasspath, String contentType) throws IOException {
862+
try (InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(fileOrClasspath)) {
863+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
864+
int available = is.available();
865+
while (available > 0) {
866+
byte next[] = new byte[available];
867+
is.read(next);
868+
bos.write(next);
869+
available = is.available();
870+
}
871+
this.content = bos.toByteArray();
872+
}
873+
this.contentType = contentType + "; charset=utf-8"; // always encode in utf-8
874+
}
875+
@Override
876+
public void handle(HttpExchange httpExchange) throws IOException {
877+
httpExchange.getResponseHeaders().set("Content-type", this.contentType);
878+
httpExchange.sendResponseHeaders(HTTP_OK, content.length);
879+
httpExchange.getResponseBody().write(content);
880+
httpExchange.close();
881+
}
882+
} // end static class FileHandler
883+
855884
private int maybeAlterStanfordTimeout(HttpExchange httpExchange, int timeoutMilliseconds) {
856885
if ( ! stanford) {
857886
return timeoutMilliseconds;
@@ -1759,6 +1788,11 @@ public void run(Optional<Pair<String,String>> basicAuth,
17591788
withAuth(server.createContext(uriContext+"/corenlp-brat.js", new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-brat.js", "application/javascript")), basicAuth);
17601789
withAuth(server.createContext(uriContext+"/corenlp-brat.cs", new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-brat.css", "text/css")), basicAuth);
17611790
withAuth(server.createContext(uriContext+"/corenlp-parseviewer.js", new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-parseviewer.js", "application/javascript")), basicAuth);
1791+
withAuth(server.createContext(uriContext+"/static/fonts/Astloch-Bold.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/Astloch-Bold.ttf", "font/ttfx")), basicAuth);
1792+
withAuth(server.createContext(uriContext+"/static/fonts/Liberation_Sans-Regular.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/LiberationSans-Regular.ttf", "font/ttf")), basicAuth);
1793+
withAuth(server.createContext(uriContext+"/static/fonts/PT_Sans-Caption-Web-Regular.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/PTSansCaption-Regular.ttf", "font/ttf")), basicAuth);
1794+
withAuth(server.createContext(uriContext+"/visualizer.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/visualizer.js", "application/javascript")), basicAuth);
1795+
withAuth(server.createContext(uriContext+"/img/corenlp-title.png", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/corenlp-title.png", "image/png")), basicAuth);
17621796
withAuth(server.createContext(uriContext+"/ping", new PingHandler()), Optional.empty());
17631797
withAuth(server.createContext(uriContext+"/shutdown", new ShutdownHandler()), basicAuth);
17641798
if (this.serverPort == this.statusPort) {
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎src/edu/stanford/nlp/pipeline/demo/corenlp-brat.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div class="container">
3030
<div id="logo">
3131
<a href="https://stanfordnlp.github.io/CoreNLP/">
32-
<img id="logo-image" src="https://nlp.stanford.edu/img/corenlp-title.png">
32+
<img id="logo-image" src="img/corenlp-title.png">
3333
</a>
3434
</div>
3535
<div id="version-num">version 4.5.8<br><br><br></div>

‎src/edu/stanford/nlp/pipeline/demo/corenlp-brat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ head.js(
2020
// brat modules
2121
bratLocation + '/client/src/dispatcher.js',
2222
bratLocation + '/client/src/url_monitor.js',
23-
bratLocation + '/client/src/visualizer.js',
23+
'./visualizer.js',
2424

2525
// parse viewer
2626
'./corenlp-parseviewer.js'
Loading
39.2 KB
Loading

‎src/edu/stanford/nlp/pipeline/demo/visualizer.js

+3,139
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.