Archived
0

MCSM: перенос компонентов в отдельный файл

This commit is contained in:
2017-03-25 03:49:56 +03:00
parent d9d5f5cb02
commit a57d41f5b4
3 changed files with 66 additions and 58 deletions

View File

@@ -11,9 +11,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MCSM_WebModule extends WebModule {
private final String MODULE_NAME = "mcsmanager";
private final Pattern URL_PATTERN_JS = Pattern.compile("/"+MODULE_NAME+"/(\\w+)\\.js");
@Override
public String getName() {
@@ -35,8 +38,13 @@ public class MCSM_WebModule extends WebModule {
@Override
public boolean handle(HttpExchange httpExchange) throws IOException {
String urlPath = httpExchange.getRequestURI().getPath();
if (urlPath.equals("/"+MODULE_NAME+"/module.js")) {
InputStream stream = getClass().getResourceAsStream("/module.js");
Matcher matcher = URL_PATTERN_JS.matcher(urlPath);
if (matcher.find()) {
InputStream stream = getClass().getResourceAsStream("/"+matcher.group(1)+".js");
if (stream == null) {
this.sendHttpCode(httpExchange, 404, "not found");
return true;
}
httpExchange.getResponseHeaders().add("Content-Type", "text/javascript;charset=utf-8");
this.sendContent(httpExchange, 0, stream);
return true;