19 package org.turro.marker;
21 import freemarker.template.Configuration;
22 import freemarker.template.DefaultObjectWrapperBuilder;
23 import freemarker.template.Template;
24 import freemarker.template.TemplateException;
25 import freemarker.template.TemplateExceptionHandler;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.StringWriter;
30 import java.io.Writer;
31 import java.util.HashMap;
33 import java.util.logging.Level;
34 import java.util.logging.Logger;
35 import org.turro.string.Strings;
36 import org.turro.action.EntityInfoContent;
37 import org.turro.action.EntityInfoType;
38 import org.turro.action.LinkType;
39 import org.turro.elephant.context.ElephantContext;
40 import org.turro.elephant.context.History;
41 import org.turro.elephant.context.IConstructor;
42 import org.turro.elephant.direct.DirectContents;
43 import org.turro.i18n.I_;
51 private static final String TEMPLATE_DIR =
"/WEB-INF/elephant/";
54 private final Map root =
new HashMap();
61 this(constructor,
false);
65 this.constructor = constructor;
67 setDirectoryForTemplateLoading(
new File(
templateRoot(constructor, mail)));
68 DefaultObjectWrapperBuilder dowb =
new DefaultObjectWrapperBuilder(VERSION_2_3_30);
69 dowb.setForceLegacyNonListCollections(
false);
70 setObjectWrapper(dowb.build());
71 setLocale(
I_.
api().used());
74 setDateFormat(
"short");
75 setDateTimeFormat(
"short_short");
77 setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
78 setURLEscapingCharset(
"UTF-8");
79 setAPIBuiltinEnabled(
true);
80 root.put(
"constructor", constructor);
88 root.put(
"i_",
I_.
api());
89 root.put(
"i",
I_.
map());
95 root.put(
"identity", identity);
98 if(getLocale() !=
null) {
99 root.put(
"lang", getLocale().getLanguage());
102 }
catch (IOException ex) {
115 public String
parse(String rootTmpl, String tmpl) {
116 StringWriter sw =
new StringWriter();
118 return sw.toString();
121 public void process(String rootTmpl, String tmpl) {
124 }
catch (IOException ex) {
129 public void process(String rootTmpl, String tmpl, Writer out) {
131 Template
template =
null;
134 }
catch(FileNotFoundException ex) {
137 template.process(root, out);
138 }
catch (IOException | TemplateException ex) {
145 public Object
get(Object key) {
146 return root.get(key);
149 public Object
put(Object key, Object value) {
150 return root.put(key, value);
153 public Object
remove(Object key) {
154 return root.remove(key);
158 return root.containsKey(key);
166 if(!Strings.isBlank(
template)) {
168 template =
"/" + root +
"/" +
template +
"Template.html";
175 if(!Strings.isBlank(
template)) {
177 template =
"/" + root +
"/site/" +
template +
"Template.html";
188 return fileTemplate(constructor, mail, root, name, overriden).exists();
192 return fileTemplate(constructor, mail, root, name,
false);
196 StringBuilder sb =
new StringBuilder(
templateRoot(constructor, mail));
197 sb.append(
"/").append(root).append(
"/");
198 if(overriden) sb.append(
"site").append(
"/");
199 sb.append(name).append(
"Template.html");
200 return new File(sb.toString());
206 }
else if(constructor !=
null) {
static String createURL(EntityInfoType type, LinkType link)
static String getRealPath(String path)
static String getSiteName()
static String getServerUrl(String scheme)
static String getRootWebPath()
static String logMsg(String msg)
static String getEncoding()
static String getTemplatesRoot()
static IConstructor createConstructor()
static History getInstance(IConstructor constructor)
static String createRelativeURL(String id)
static I18nByKey byKeyMap()
static I18nApiWrapper api()
static I18nMapWrapper map()
static I18nCompatibilityMap compatibilityMap()
static void addToMap(Map map)
static String templateRoot(IConstructor constructor, boolean mail)
static File fileTemplate(IConstructor constructor, boolean mail, String root, String name)
ElephantMarker(IConstructor constructor)
void process(String rootTmpl, String tmpl)
static boolean existsTemplate(IConstructor constructor, boolean mail, String root, String name, boolean overriden)
IConstructor getConstructor()
static boolean existsTemplate(IConstructor constructor, boolean mail, String root, String name)
boolean contains(Object key)
String parse(String rootTmpl, String tmpl)
void process(String rootTmpl, String tmpl, Writer out)
Object put(Object key, Object value)
String getSiteTemplateString(String root, String template)
String getTemplateString(String root, String template)
static File fileTemplate(IConstructor constructor, boolean mail, String root, String name, boolean overriden)
ElephantMarker(IConstructor constructor, boolean mail)
HttpServletResponse getResponse()
HttpServletRequest getRequest()
static String globalRepository()
static String currentRepository(IConstructor constructor)