-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobals.java
More file actions
26 lines (20 loc) · 820 Bytes
/
Globals.java
File metadata and controls
26 lines (20 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.sample;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
public class Globals {
public static String htmlE(String x) {
return x.replace("&", "&").replace("<", "<")
.replaceAll("(?m)^ | $|( ) ", "$1 ").replaceAll("\n|\r\n?", "<br/>");
}
public static String attrE(String x) {
return x.replace("&", "&").replace("\"", """);
}
public static void respondPlain(HttpServletResponse resp, int statusCode, boolean json, String write) throws IOException {
resp.setStatus(statusCode);
resp.setHeader("Content-Type", json ? "application/json" : "text/plain; charset=UTF-8");
try (Writer writer = resp.getWriter()) {
writer.write(write);
}
}
}