Search in sources :

Example 26 with TextStringBuilder

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();
}
Also used : ConfigWriter(com.djrapitops.plan.settings.config.ConfigWriter) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 27 with TextStringBuilder

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());
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 28 with TextStringBuilder

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()));
    }
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 29 with TextStringBuilder

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();
}
Also used : ExceptionWithContext(com.djrapitops.plan.exceptions.ExceptionWithContext) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 30 with TextStringBuilder

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();
}
Also used : TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Aggregations

TextStringBuilder (org.apache.commons.text.TextStringBuilder)37 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Issue (org.apache.gobblin.runtime.troubleshooter.Issue)4 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)3 Nullable (javax.annotation.Nullable)3 StringTokenizer (org.apache.commons.text.StringTokenizer)3 Test (org.junit.jupiter.api.Test)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 SecurityJpqlGenerator (com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator)2 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)2 FakeFilterSupport (com.haulmont.cuba.gui.components.filter.FakeFilterSupport)2 FilterParser (com.haulmont.cuba.gui.components.filter.FilterParser)2 FilterEditor (com.haulmont.cuba.gui.components.filter.edit.FilterEditor)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2