|
@@ -1,36 +1,36 @@
|
1
|
|
-package kr.co.swh.lecture.opensource.sparkjava;
|
2
|
|
-
|
3
|
|
-import static spark.Spark.*;
|
4
|
|
-
|
5
|
|
-import spark.TemplateEngine;
|
6
|
|
-
|
7
|
|
-public class FreeMarkerTemplateEngine extends TemplateEngine {
|
8
|
|
-
|
9
|
|
- private Configuration configuration;
|
10
|
|
-
|
11
|
|
- protected FreeMarkerTemplateEngine() {
|
12
|
|
- this.configuration = createFreemarkerConfiguration();
|
13
|
|
- }
|
14
|
|
-
|
15
|
|
- @Override
|
16
|
|
- public String render(ModelAndView modelAndView) {
|
17
|
|
- try {
|
18
|
|
- StringWriter stringWriter = new StringWriter();
|
19
|
|
-
|
20
|
|
- Template template = configuration.getTemplate(modelAndView.getViewName());
|
21
|
|
- template.process(modelAndView.getModel(), stringWriter);
|
22
|
|
-
|
23
|
|
- return stringWriter.toString();
|
24
|
|
- } catch (IOException e) {
|
25
|
|
- throw new IllegalArgumentException(e);
|
26
|
|
- } catch (TemplateException e) {
|
27
|
|
- throw new IllegalArgumentException(e);
|
28
|
|
- }
|
29
|
|
- }
|
30
|
|
-
|
31
|
|
- private Configuration createFreemarkerConfiguration() {
|
32
|
|
- Configuration retVal = new Configuration();
|
33
|
|
- retVal.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, "freemarker");
|
34
|
|
- return retVal;
|
35
|
|
- }
|
36
|
|
-}
|
|
1
|
+//package kr.co.swh.lecture.opensource.sparkjava;
|
|
2
|
+//
|
|
3
|
+//import static spark.Spark.*;
|
|
4
|
+//
|
|
5
|
+//import spark.TemplateEngine;
|
|
6
|
+//
|
|
7
|
+//public class FreeMarkerTemplateEngine extends TemplateEngine {
|
|
8
|
+//
|
|
9
|
+// private Configuration configuration;
|
|
10
|
+//
|
|
11
|
+// protected FreeMarkerTemplateEngine() {
|
|
12
|
+// this.configuration = createFreemarkerConfiguration();
|
|
13
|
+// }
|
|
14
|
+//
|
|
15
|
+// @Override
|
|
16
|
+// public String render(ModelAndView modelAndView) {
|
|
17
|
+// try {
|
|
18
|
+// StringWriter stringWriter = new StringWriter();
|
|
19
|
+//
|
|
20
|
+// Template template = configuration.getTemplate(modelAndView.getViewName());
|
|
21
|
+// template.process(modelAndView.getModel(), stringWriter);
|
|
22
|
+//
|
|
23
|
+// return stringWriter.toString();
|
|
24
|
+// } catch (IOException e) {
|
|
25
|
+// throw new IllegalArgumentException(e);
|
|
26
|
+// } catch (TemplateException e) {
|
|
27
|
+// throw new IllegalArgumentException(e);
|
|
28
|
+// }
|
|
29
|
+// }
|
|
30
|
+//
|
|
31
|
+// private Configuration createFreemarkerConfiguration() {
|
|
32
|
+// Configuration retVal = new Configuration();
|
|
33
|
+// retVal.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, "freemarker");
|
|
34
|
+// return retVal;
|
|
35
|
+// }
|
|
36
|
+//}
|