use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class StoreConfigTransaction method extractConfigSettingLines.
private String extractConfigSettingLines(Config config) {
TextStringBuilder configTextBuilder = new TextStringBuilder();
List<String> lines = new ConfigWriter().createLines(config);
configTextBuilder.appendWithSeparators(lines, "\n");
return configTextBuilder.toString();
}
use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class CreateIndexTransaction method createIndex.
private void createIndex(String tableName, String indexName, String... indexedColumns) {
if (indexedColumns.length == 0) {
throw new IllegalArgumentException("Can not create index without columns");
}
boolean isMySQL = dbType == DBType.MYSQL;
if (isMySQL) {
boolean indexExists = query(MySQLSchemaQueries.doesIndexExist(indexName, tableName));
if (indexExists)
return;
}
TextStringBuilder sql = new TextStringBuilder("CREATE INDEX ");
if (!isMySQL) {
sql.append("IF NOT EXISTS ");
}
sql.append(indexName).append(" ON ").append(tableName);
sql.append(" (");
sql.appendWithSeparators(indexedColumns, ",");
sql.append(')');
execute(sql.toString());
}
use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class ResourceSvc method addScriptsToResource.
@Override
public void addScriptsToResource(String pluginName, String fileName, Position position, String... jsSources) {
checkParams(pluginName, fileName, position, jsSources);
String snippet = new TextStringBuilder("<script src=\"").appendWithSeparators(jsSources, "\"></script><script src=\"").append("\"></script>").build();
snippets.add(new Snippet(pluginName, fileName, position, snippet));
if (!"Plan".equals(pluginName)) {
logger.info(locale.getString(PluginLang.API_ADD_RESOURCE_JS, pluginName, fileName, position.cleanName()));
}
}
use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class InternalErrorPage method createContent.
private String createContent() {
TextStringBuilder paragraph = new TextStringBuilder();
paragraph.append("Please report this issue here: ");
paragraph.append(Html.LINK.create("https://github.com/plan-player-analytics/Plan/issues", "Issues"));
paragraph.append("<br><br><pre>");
paragraph.append(error).append(" | ").append(errorMsg);
if (error instanceof ExceptionWithContext) {
((ExceptionWithContext) error).getContext().ifPresent(context -> paragraph.append(context.getWhatToDo().map(whatToDo -> "<br>What to do about it: " + whatToDo).orElse("<br>Error message: " + error.getMessage())).append("<br><br>Related things:<br>").appendWithSeparators(context.toLines(), "<br>").append("<br>"));
}
for (StackTraceElement element : error.getStackTrace()) {
paragraph.append("<br>");
paragraph.append(" ").append(element);
}
if (error.getCause() != null) {
appendCause(error.getCause(), paragraph);
}
paragraph.append("</pre>");
return paragraph.toString();
}
use of org.apache.commons.text.TextStringBuilder in project Plan by plan-player-analytics.
the class RequestHandler method getAuthentication.
private Optional<Authentication> getAuthentication(Headers requestHeaders) {
if (config.isTrue(WebserverSettings.DISABLED_AUTHENTICATION)) {
return Optional.empty();
}
List<String> cookies = requestHeaders.get("Cookie");
if (cookies != null && !cookies.isEmpty()) {
for (String cookie : new TextStringBuilder().appendWithSeparators(cookies, ";").build().split(";")) {
String[] split = cookie.trim().split("=", 2);
String name = split[0];
String value = split[1];
if ("auth".equals(name)) {
return Optional.of(new CookieAuthentication(activeCookieStore, value));
}
}
}
List<String> authorization = requestHeaders.get("Authorization");
if (authorization == null || authorization.isEmpty())
return Optional.empty();
String authLine = authorization.get(0);
if (StringUtils.contains(authLine, "Basic ")) {
return Optional.of(new BasicAuthentication(StringUtils.split(authLine, ' ')[1], dbSystem.getDatabase()));
}
return Optional.empty();
}
Aggregations