mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
[Debt] Removed Theme replaceColors method.
All static methods removed now from Theme. Delegated Theme and Locale html modifications to Response#send method. Affected issues: none
This commit is contained in:
parent
35be0a2afb
commit
54e3528a59
|
@ -6,7 +6,6 @@ package com.djrapitops.plan.system.settings.theme;
|
|||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
|
@ -35,13 +34,6 @@ public class Theme implements SubSystem {
|
|||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Theme getInstance() {
|
||||
Theme themeSystem = ConfigSystem.getInstance().getThemeSystem();
|
||||
Verify.nullCheck(themeSystem, () -> new IllegalStateException("Theme System has not been initialized."));
|
||||
return themeSystem;
|
||||
}
|
||||
|
||||
public String getValue(ThemeVal variable) {
|
||||
try {
|
||||
return getThemeValue(variable);
|
||||
|
@ -50,11 +42,6 @@ public class Theme implements SubSystem {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String replaceColors(String resourceString) {
|
||||
return getInstance().replaceThemeColors(resourceString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
try {
|
||||
|
@ -112,7 +99,7 @@ public class Theme implements SubSystem {
|
|||
replaced = replaced.replace(defaultValue, value);
|
||||
}
|
||||
}
|
||||
return replaced;
|
||||
return replaced.replace("${defaultTheme}", getValue(ThemeVal.THEME_DEFAULT));
|
||||
}
|
||||
|
||||
private String getThemeValue(ThemeVal color) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.djrapitops.plan.system.database.databases.Database;
|
|||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.auth.Authentication;
|
||||
import com.djrapitops.plan.system.webserver.auth.BasicAuthentication;
|
||||
import com.djrapitops.plan.system.webserver.response.PromptAuthorizationResponse;
|
||||
|
@ -36,6 +37,7 @@ public class RequestHandler implements HttpHandler {
|
|||
|
||||
private final Locale locale;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final Database database;
|
||||
private final ResponseHandler responseHandler;
|
||||
private final Timings timings;
|
||||
|
@ -46,6 +48,7 @@ public class RequestHandler implements HttpHandler {
|
|||
RequestHandler(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
Database database,
|
||||
ResponseHandler responseHandler,
|
||||
Timings timings,
|
||||
|
@ -54,6 +57,7 @@ public class RequestHandler implements HttpHandler {
|
|||
) {
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.database = database;
|
||||
this.responseHandler = responseHandler;
|
||||
this.timings = timings;
|
||||
|
@ -81,7 +85,7 @@ public class RequestHandler implements HttpHandler {
|
|||
}
|
||||
|
||||
response.setResponseHeaders(responseHeaders);
|
||||
response.send(exchange, locale);
|
||||
response.send(exchange, locale, theme);
|
||||
} catch (Exception e) {
|
||||
if (inDevMode) {
|
||||
logger.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:");
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package com.djrapitops.plan.system.webserver.response;
|
||||
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class CSSResponse extends FileResponse {
|
||||
|
||||
public CSSResponse(String fileName, Theme theme) {
|
||||
public CSSResponse(String fileName) {
|
||||
super(format(fileName));
|
||||
super.setType(ResponseType.CSS);
|
||||
setContent(theme.replaceThemeColors(getContent()));
|
||||
setContent(getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,13 @@
|
|||
package com.djrapitops.plan.system.webserver.response;
|
||||
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public class JavaScriptResponse extends FileResponse {
|
||||
|
||||
private final Locale locale;
|
||||
|
||||
JavaScriptResponse(String fileName, Locale locale, Theme theme) {
|
||||
JavaScriptResponse(String fileName) {
|
||||
super(format(fileName));
|
||||
this.locale = locale;
|
||||
|
||||
super.setType(ResponseType.JAVASCRIPT);
|
||||
Map<String, String> replace = new HashMap<>();
|
||||
replace.put("defaultTheme", theme.getValue(ThemeVal.THEME_DEFAULT));
|
||||
setContent(StringSubstitutor.replace(theme.replaceThemeColors(getContent()), replace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent() {
|
||||
return locale.replaceMatchingLanguage(super.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.djrapitops.plan.system.webserver.response;
|
||||
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -17,8 +18,8 @@ public class RedirectResponse extends Response {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void send(HttpExchange exchange, Locale locale) throws IOException {
|
||||
public void send(HttpExchange exchange, Locale locale, Theme theme) throws IOException {
|
||||
responseHeaders.set("Location", getContent());
|
||||
super.send(exchange, locale);
|
||||
super.send(exchange, locale, theme);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.djrapitops.plan.system.webserver.response;
|
||||
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.sun.net.httpserver.Headers;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
|
@ -83,12 +84,16 @@ public abstract class Response {
|
|||
this.responseHeaders = responseHeaders;
|
||||
}
|
||||
|
||||
public void send(HttpExchange exchange, Locale locale) throws IOException {
|
||||
public void send(HttpExchange exchange, Locale locale, Theme theme) throws IOException {
|
||||
responseHeaders.set("Content-Type", type);
|
||||
responseHeaders.set("Content-Encoding", "gzip");
|
||||
exchange.sendResponseHeaders(getCode(), 0);
|
||||
|
||||
String sentContent = getContent();
|
||||
if (!(this instanceof JavaScriptResponse)) {
|
||||
sentContent = locale.replaceMatchingLanguage(sentContent);
|
||||
}
|
||||
sentContent = theme.replaceThemeColors(sentContent);
|
||||
|
||||
try (GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(sentContent.getBytes(StandardCharsets.UTF_8))) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.api.exceptions.ParseException;
|
|||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
||||
|
@ -25,19 +24,16 @@ public class ResponseFactory {
|
|||
|
||||
private final PageFactory pageFactory;
|
||||
private final Locale locale;
|
||||
private final Theme theme;
|
||||
private final Database database;
|
||||
|
||||
@Inject
|
||||
public ResponseFactory(
|
||||
PageFactory pageFactory,
|
||||
Locale locale,
|
||||
Theme theme,
|
||||
Database database
|
||||
) {
|
||||
this.pageFactory = pageFactory;
|
||||
this.locale = locale;
|
||||
this.theme = theme;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
|
@ -70,11 +66,11 @@ public class ResponseFactory {
|
|||
}
|
||||
|
||||
public Response javaScriptResponse(String fileName) {
|
||||
return new JavaScriptResponse(fileName, locale, theme);
|
||||
return new JavaScriptResponse(fileName);
|
||||
}
|
||||
|
||||
public Response cssResponse(String fileName) {
|
||||
return new CSSResponse(fileName, theme);
|
||||
return new CSSResponse(fileName);
|
||||
}
|
||||
|
||||
public Response redirectResponse(String location) {
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
*/
|
||||
package com.djrapitops.plan.system.webserver.response.errors;
|
||||
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -25,11 +25,14 @@ public class ErrorResponse extends Response {
|
|||
private String title;
|
||||
private String paragraph;
|
||||
|
||||
// TODO
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
public ErrorResponse() {
|
||||
try {
|
||||
setContent(Theme.replaceColors(FileUtil.getStringFromResource("web/error.html")));
|
||||
setContent(FileUtil.getStringFromResource("web/error.html"));
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.WARN, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.djrapitops.plan.system.webserver.response.pages;
|
||||
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
|
@ -22,7 +21,7 @@ public class InspectPageResponse extends Response {
|
|||
|
||||
public InspectPageResponse(UUID uuid, String html) {
|
||||
super.setHeader("HTTP/1.1 200 OK");
|
||||
super.setContent(Theme.replaceColors(html));
|
||||
super.setContent(html);
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public class MiscUtils {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getPlanVersion() {
|
||||
return PlanPlugin.getInstance().getVersion();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.djrapitops.plan.system.database.databases.Database;
|
|||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
|
@ -31,6 +32,7 @@ public class PageFactory {
|
|||
|
||||
private final String version;
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final Lazy<Theme> theme;
|
||||
private final Lazy<Database> database;
|
||||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final Lazy<ConnectionSystem> connectionSystem;
|
||||
|
@ -45,6 +47,7 @@ public class PageFactory {
|
|||
public PageFactory(
|
||||
@Named("currentVersion") String version,
|
||||
Lazy<PlanConfig> config,
|
||||
Lazy<Theme> theme,
|
||||
Lazy<Database> database,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
Lazy<ConnectionSystem> connectionSystem,
|
||||
|
@ -57,6 +60,7 @@ public class PageFactory {
|
|||
) {
|
||||
this.version = version;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
this.connectionSystem = connectionSystem;
|
||||
|
@ -90,7 +94,7 @@ public class PageFactory {
|
|||
Map<UUID, String> serverNames = database.get().fetch().getServerNames();
|
||||
return new InspectPage(
|
||||
player, serverNames,
|
||||
config.get(), theme, graphs.get(), tables.get(), formatters.get(), serverInfo.get(), timings.get()
|
||||
config.get(), theme.get(), graphs.get(), tables.get(), formatters.get(), serverInfo.get(), timings.get()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user