Skip to content

Commit

Permalink
LPS-137504 Preprocess HTML to remove freemarker variables
Browse files Browse the repository at this point in the history
As long as the resulting HTML is valid, the replacement we use doesn't
really matter. Using a valid HTML identifier to avoid issues.
  • Loading branch information
adolfopa committed Aug 17, 2021
1 parent 5f33f07 commit f6b79c6
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -30,6 +30,8 @@

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author Adolfo Pérez
Expand All @@ -54,7 +56,7 @@ public static <E extends Throwable> void forEachInfoField(
for (FragmentEntryLink fragmentEntryLink : fragmentEntryLinks) {
Map<String, String> editableTypes =
EditableFragmentEntryProcessorUtil.getEditableTypes(
fragmentEntryLink.getHtml());
_getHtml(fragmentEntryLink));

for (Map.Entry<String, String> entry : editableTypes.entrySet()) {
String type = entry.getValue();
Expand All @@ -74,6 +76,12 @@ public static <E extends Throwable> void forEachInfoField(
}
}

private static String _getHtml(FragmentEntryLink fragmentEntryLink) {
Matcher matcher = _pattern.matcher(fragmentEntryLink.getHtml());

return matcher.replaceAll("element");
}

private static InfoField<TextInfoFieldType> _getInfoField(
long fragmentEntryLinkId, String name, String type) {

Expand Down Expand Up @@ -107,4 +115,6 @@ private static boolean _isTextFieldType(String type) {
return false;
}

private static final Pattern _pattern = Pattern.compile("\\$\\{[^}]*\\}");

}

0 comments on commit f6b79c6

Please sign in to comment.