Skip to content

Commit

Permalink
Update Freemarker version
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg authored and chenejac committed Apr 11, 2024
1 parent 71541e5 commit c6c5053
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import freemarker.template.Template;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModelException;
import freemarker.template.TemplateSequenceModel;

public abstract class Widget {

Expand Down Expand Up @@ -111,7 +112,7 @@ private String processMacroToString(Environment env, String widgetName, Macro ma
StringWriter out = new StringWriter();

try {
String templateString = macro.getChildNodes().get(0).toString();
String templateString = getTemplateString(macro);
// NB Using this method of creating a template from a string does not allow the widget template to import
// other templates (but it can include other templates). We'd need to use a StringTemplateLoader
// in the config instead. See StringTemplateLoader API doc.
Expand All @@ -128,6 +129,16 @@ private String processMacroToString(Environment env, String widgetName, Macro ma
String output = out.toString();
log.debug("Macro output: " + output);
return output;
}

private String getTemplateString(Macro macro) throws TemplateModelException {
TemplateSequenceModel childNodes = macro.getChildNodes();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < childNodes.size(); i++) {
sb.append(childNodes.get(i));
}
String template = sb.toString();
return template;
}

private String processMacroToString(Environment env, String widgetName, String macroName, Map<String, Object> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class HtmlTriplePatternFragmentWriterImpl extends TriplePatternFragmentWr
public HtmlTriplePatternFragmentWriterImpl(Map<String, String> prefixes, HashMap<String, IDataSource> datasources) throws IOException {
super(prefixes, datasources);

cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg = new Configuration(Configuration.VERSION_2_3_32);
cfg.setClassForTemplateLoading(getClass(), "/views");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void setContextPath(String path) {
public HtmlTriplePatternFragmentWriterImpl(Map<String, String> prefixes, HashMap<String, IDataSource> datasources) throws IOException {
super(prefixes, datasources);

cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg = new Configuration(Configuration.VERSION_2_3_32);
cfg.setClassForTemplateLoading(getClass(), "/tpf");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
<version>2.3.32</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand Down

0 comments on commit c6c5053

Please sign in to comment.