MCSM: перенос компонентов в отдельный файл
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user