FreeMarker template in a separated file

This commit is contained in:
Pedro Beschorner Marin 2016-01-27 14:27:06 +00:00 committed by Felipe Cecagno
parent 497930b06d
commit 00d378831e
2 changed files with 41 additions and 32 deletions

View File

@ -47,8 +47,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList;
import java.text.DateFormat;
import freemarker.template.Template;
import freemarker.template.Configuration;
import freemarker.cache.WebappTemplateLoader;
class ApiController {
private static final Integer SESSION_TIMEOUT = 14400 // 4 hours
@ -1440,37 +1440,12 @@ class ApiController {
return;
}
def cfg = new Configuration()
// Still missing this inside mkp.yield(item.getExtensions()) playbacks. Not a clue why we do this
def ftl = new Template("getRecordings", new StringReader('''<response>
<returncode>${code}</returncode>
<recordings>
<#list recs as r>
<recording>
<recordID>${r.getId()}</recordID>
<meetingID>${r.getMeetingID()?html}</meetingID>
<name>${r.getName()?html}</name>
<published>${r.isPublished()?string}</published>
<startTime>${r.getStartTime()}</startTime>
<endTime>${r.getEndTime()}</endTime>
<#assign m = r.getMetadata()>
<metadata>
<#list m?keys as prop>
<${prop}>${m[prop]?html}</${prop}>
</#list>
</metadata>
<playback>
<#list r.getPlaybacks() as p>
<format>
<type>${p.getFormat()}</type>
<url>${p.getUrl()}</url>
<length>${p.getLength()}</length>
</format>
</#list>
</playback>
</recording>
</#list>
</recordings>
</response>'''), cfg)
// Load the XML template
// TODO: Maybe there is a better way to define the templates path
def wtl = new WebappTemplateLoader(getServletContext(), "/WEB-INF/freemarker")
cfg.setTemplateLoader(wtl)
def ftl = cfg.getTemplate("get-recordings.ftl")
def xmlText = new StringWriter()
ftl.process([code:RESP_CODE_SUCCESS, recs:recs.values()], xmlText)
withFormat {

View File

@ -0,0 +1,34 @@
<#-- GET_RECORDINGS FreeMarker XML template -->
<response>
<#-- Where code is a 'SUCCESS' or 'FAILED' String -->
<returncode>${code}</returncode>
<recordings>
<#-- Where recs is a String -> Recording HashMap -->
<#list recs as r>
<recording>
<recordID>${r.getId()}</recordID>
<meetingID>${r.getMeetingID()?html}</meetingID>
<name>${r.getName()?html}</name>
<published>${r.isPublished()?string}</published>
<startTime>${r.getStartTime()}</startTime>
<endTime>${r.getEndTime()}</endTime>
<#assign m = r.getMetadata()>
<metadata>
<#list m?keys as prop>
<${prop}>${m[prop]?html}</${prop}>
</#list>
</metadata>
<playback>
<#list r.getPlaybacks() as p>
<format>
<type>${p.getFormat()}</type>
<url>${p.getUrl()}</url>
<length>${p.getLength()}</length>
<#-- Missing p.getExtensions() -->
</format>
</#list>
</playback>
</recording>
</#list>
</recordings>
</response>