<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Yes, it was left intentionally unsealed to allow for other implementations. I may be odd-thinking, but my thought was that other languages or DSLs might want their template objects to interact with Java template processors. That is, assuming that 3rd party
template processors will become ubiquitous.
<div><br>
</div>
<div>An implementation might implement a parser that would parse a file and result in a specialized StringTemplate, maybe parsing on the fly so the whole file doesn’t need to be read in. Note the parser could also use any style embedded expression it wanted.</div>
<div><br>
Ex:<br>
<br>
<div><font face="Consolas">Department of Agriculture</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">«DATE»</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">«FIRSTNAME» «INITIAL». «SURNAME»</font></div>
<div><font face="Consolas">«ADDRESS»</font></div>
<div><font face="Consolas">«CITY», «STATE», «COUNTRY»</font></div>
<div><font face="Consolas">«POSTAL»</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">Dear «FIRSTNAME»,</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">I wish to inform you that your application for</font></div>
<div><font face="Consolas">a sunflower seed permit has been approved. You</font></div>
<div><font face="Consolas">should receive said permit within three weeks.</font></div>
<div><font face="Consolas">Do not hesitate to enquire on any issue.</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">Sincerely,</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">Joan Smith</font></div>
<div><font face="Consolas">Director</font></div>
<div><br>
</div>
<div>The embedded expressions here might be the names of fields in a DB and the target processor retrieves the actual value based on the embedded expression. Loosely something like:</div>
<div> </div>
<div>
<div><font face="Consolas">while (resultSet.hasNext()) {</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">...</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas"> StringTemplate.Processor<String, RuntimeException> dbFill = st -> {</font></div>
<div><font face="Consolas"> List<String> fragments = st.fragments()</font></div>
<div><font face="Consolas"> List<Object> values = st.values().stream()</font></div>
<div><font face="Consolas"> .map(Object::toString)</font></div>
<div><font face="Consolas"> .map(v -> resultSet.getString(v))</font></div>
<div><font face="Consolas"> .toList();</font></div>
<div><font face="Consolas"> return StringTemplate.interpolate(fragments, values);</font></div>
<div><font face="Consolas"> };</font></div>
<div><font face="Consolas"> </font></div>
<div><font face="Consolas"> </font></div>
<div><font face="Consolas"> String result = dbFill.process(temple);</font></div>
<div><font face="Consolas">...</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">}</font></div>
</div>
<div><br>
</div>
<div>Since the processing here is somewhat generic, someone else could apply the same processor using templates generated by Kotlin.</div>
<div><br>
</div>
<div>Bottom line is to create an ecosystem that has a lot of template processors with the potential for a variety of template sources.</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>— Jim</div>
<div><br>
</div>
<br>
<br id="lineBreakAtBeginningOfMessage">
<br>
<blockquote type="cite">On Oct 20, 2023, at 9:09 AM, Patrik Duditš <pato@dudits.net> wrote:<br>
<br class="Apple-interchange-newline">
Hello,<br>
<br>
I've been experimenting with StringTemplates recently for a few weeks. One thing that appeared odd to me is that StringTemplate is defined as an unsealed interface, as if it would make sense for users of the API to create their own implementations of it.<br>
<br>
I would like to ask whether that is an omission, or there is some other underlying reason for that.<br>
<br>
<br>
Patrik Duditš<br>
</blockquote>
<br>
</div>
</body>
</html>