Search in sources :

Example 1 with TextTagValue

use of tools.utils.TagValue.TextTagValue in project AuthMeReloaded by AuthMe.

the class TagReplacer method applyReplacements.

/**
     * Replace a template with default tags and custom ones supplied by a map.
     *
     * @param template The template to process
     * @param tagValues Container with tags and their associated values
     * @return The filled template
     */
public static String applyReplacements(String template, TagValueHolder tagValues) {
    String result = template;
    for (Map.Entry<String, TagValue<?>> tagRule : tagValues.getValues().entrySet()) {
        final String name = tagRule.getKey();
        if (tagRule.getValue() instanceof TextTagValue) {
            final TextTagValue value = (TextTagValue) tagRule.getValue();
            result = replaceOptionalTag(result, name, value).replace("{" + name + "}", value.getValue());
        } else if (tagRule.getValue() instanceof NestedTagValue) {
            final NestedTagValue value = (NestedTagValue) tagRule.getValue();
            result = replaceIterateTag(replaceOptionalTag(result, name, value), name, value);
        } else {
            throw new IllegalStateException("Unknown tag value type");
        }
    }
    return applyReplacements(result);
}
Also used : TextTagValue(tools.utils.TagValue.TextTagValue) NestedTagValue(tools.utils.TagValue.NestedTagValue) NestedTagValue(tools.utils.TagValue.NestedTagValue) TextTagValue(tools.utils.TagValue.TextTagValue) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 NestedTagValue (tools.utils.TagValue.NestedTagValue)1 TextTagValue (tools.utils.TagValue.TextTagValue)1