keycloak-service
クラス | 公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.keycloak.theme.FreeMarkerUtil クラス
org.keycloak.theme.FreeMarkerUtil 連携図
Collaboration graph

クラス

class  ThemeTemplateLoader
 

公開メンバ関数

 FreeMarkerUtil ()
 
String processTemplate (Object data, String templateName, Theme theme) throws FreeMarkerException
 

非公開メンバ関数

Template getTemplate (String templateName, Theme theme) throws IOException
 

非公開変数類

ConcurrentHashMap< String, Template > cache
 
final KeycloakSanitizerMethod kcSanitizeMethod = new KeycloakSanitizerMethod()
 

詳解

著者
Stian Thorgersen

構築子と解体子

◆ FreeMarkerUtil()

org.keycloak.theme.FreeMarkerUtil.FreeMarkerUtil ( )
inline
41  {
42  if (Config.scope("theme").getBoolean("cacheTemplates", true)) {
43  cache = new ConcurrentHashMap<>();
44  }
45  }
ConcurrentHashMap< String, Template > cache
Definition: FreeMarkerUtil.java:38

関数詳解

◆ getTemplate()

Template org.keycloak.theme.FreeMarkerUtil.getTemplate ( String  templateName,
Theme  theme 
) throws IOException
inlineprivate
76  {
77  Configuration cfg = new Configuration();
78 
79  // Assume *.ftl files are html. This lets freemarker know how to
80  // sanitize and prevent XSS attacks.
81  if (templateName.toLowerCase().endsWith(".ftl")) {
82  cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
83  }
84 
85  cfg.setTemplateLoader(new ThemeTemplateLoader(theme));
86  return cfg.getTemplate(templateName, "UTF-8");
87  }

◆ processTemplate()

String org.keycloak.theme.FreeMarkerUtil.processTemplate ( Object  data,
String  templateName,
Theme  theme 
) throws FreeMarkerException
inline
47  {
48  if (data instanceof Map) {
49  ((Map)data).put("kcSanitize", kcSanitizeMethod);
50  }
51 
52  try {
53  Template template;
54  cache = null;
55  if (cache != null) {
56  String key = theme.getName() + "/" + templateName;
57  template = cache.get(key);
58  if (template == null) {
59  template = getTemplate(templateName, theme);
60  if (cache.putIfAbsent(key, template) != null) {
61  template = cache.get(key);
62  }
63  }
64  } else {
65  template = getTemplate(templateName, theme);
66  }
67 
68  Writer out = new StringWriter();
69  template.process(data, out);
70  return out.toString();
71  } catch (Exception e) {
72  throw new FreeMarkerException("Failed to process template " + templateName, e);
73  }
74  }
Template getTemplate(String templateName, Theme theme)
Definition: FreeMarkerUtil.java:76
ConcurrentHashMap< String, Template > cache
Definition: FreeMarkerUtil.java:38
final KeycloakSanitizerMethod kcSanitizeMethod
Definition: FreeMarkerUtil.java:39

メンバ詳解

◆ cache

ConcurrentHashMap<String, Template> org.keycloak.theme.FreeMarkerUtil.cache
private

◆ kcSanitizeMethod

final KeycloakSanitizerMethod org.keycloak.theme.FreeMarkerUtil.kcSanitizeMethod = new KeycloakSanitizerMethod()
private

このクラス詳解は次のファイルから抽出されました: