Skip to content

Commit

Permalink
Apply mapping as first step
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOellerer committed May 12, 2022
1 parent 24b0614 commit 4a1b0f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '1.4.0-rc.2'
version = '1.4.0-rc.3'

sourceCompatibility = "17"
targetCompatibility = "17"
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/docutools/jocument/PlaceholderMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

public interface PlaceholderMapper {
Optional<String> map(String placeholder);

String tryToMap(String placeholder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public Optional<String> map(String placeholder) {
return Optional.ofNullable(placeholderMappings.get(placeholder));
}

@Override
public String tryToMap(String placeholder) {
return map(placeholder).orElse(placeholder);
}

private static void setup() {
if (pathString != null) {
var path = Path.of(pathString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private static DateTimeFormatter toDateTimeFormatter(Format format) {
@Override
protected Optional<PlaceholderData> doResolve(String placeholderName, Locale locale) {
logger.debug("Trying to resolve placeholder {}", placeholderName);
placeholderName = placeholderMapper.tryToMap(placeholderName);
boolean isCondition = placeholderName.endsWith("?");
placeholderName = isCondition ? placeholderName.substring(0, placeholderName.length() - 1) : placeholderName;
Optional<PlaceholderData> result = resolveStripped(locale, placeholderName);
Expand All @@ -175,8 +176,7 @@ protected Optional<PlaceholderData> doResolve(String placeholderName, Locale loc
}

private Optional<PlaceholderData> resolveStripped(Locale locale, String placeholder) {
return matchPattern(placeholder, locale)
.or(() -> resolveAccessor(placeholderMapper.map(placeholder).orElse(placeholder), locale));
return matchPattern(placeholder, locale).or(() -> resolveAccessor(placeholder, locale));
}

private Optional<PlaceholderData> matchPattern(String placeholderName, Locale locale) {
Expand Down

0 comments on commit 4a1b0f3

Please sign in to comment.