Skip to content

Commit a351533

Browse files
committed
- call Freemarker/Velocity templates directly for importing in other templates
1 parent 69f3d58 commit a351533

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

clownfish/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.clownfish</groupId>
55
<artifactId>clownfish</artifactId>
6-
<version>0.3.0-SNAPSHOT</version>
6+
<version>0.4.1-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<scm>
99
<connection>scm:git:https://github.com/rawdog71/Clownfish</connection>

clownfish/src/main/java/io/clownfish/clownfish/Clownfish.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,42 @@ public void universalGetTemplate(@PathVariable("name") String name, @Context Htt
660660
}
661661
}
662662

663+
@GetMapping(path = "/{name}.ftl")
664+
public void universalGetFreemarkerTemplate(@PathVariable("name") String name, @Context HttpServletRequest request, @Context HttpServletResponse response) {
665+
CfTemplate cftemplate = null;
666+
try {
667+
cftemplate = cftemplateService.findByName(name);
668+
if (0 == cftemplate.getScriptlanguage()) {
669+
response.setContentType("text/html");
670+
response.setCharacterEncoding("UTF-8");
671+
PrintWriter outwriter = response.getWriter();
672+
outwriter.println(cftemplate.getContent());
673+
} else {
674+
LOGGER.warn("ONLY Freemarker Templates");
675+
}
676+
} catch (Exception ex) {
677+
LOGGER.warn("Template NOT FOUND");
678+
}
679+
}
680+
681+
@GetMapping(path = "/{name}.vm")
682+
public void universalGetVelocityTemplate(@PathVariable("name") String name, @Context HttpServletRequest request, @Context HttpServletResponse response) {
683+
CfTemplate cftemplate = null;
684+
try {
685+
cftemplate = cftemplateService.findByName(name);
686+
if (1 == cftemplate.getScriptlanguage()) {
687+
response.setContentType("text/html");
688+
response.setCharacterEncoding("UTF-8");
689+
PrintWriter outwriter = response.getWriter();
690+
outwriter.println(cftemplate.getContent());
691+
} else {
692+
LOGGER.warn("ONLY Velocity Templates");
693+
}
694+
} catch (Exception ex) {
695+
LOGGER.warn("Template NOT FOUND");
696+
}
697+
}
698+
663699
@GetMapping(path = "/{name}.js")
664700
public void universalGetJS(@PathVariable("name") String name, @Context HttpServletRequest request, @Context HttpServletResponse response) {
665701
CfJavascript cfjavascript = null;

clownfish/src/main/java/io/clownfish/clownfish/serviceimpl/CfTemplateLoaderImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public CfTemplateLoaderImpl() {
3333
@Override
3434
public Object findTemplateSource(String name) throws IOException {
3535
try {
36+
if ((name.endsWith(".ftl")) || (name.endsWith(".vm"))) {
37+
name = name.substring(0, name.lastIndexOf("."));
38+
}
3639
CfTemplate cftemplate = cftemplateService.findByName(name);
3740
return cftemplate;
3841
} catch (Exception ex) {

0 commit comments

Comments
 (0)