Class NotificationRenderer

java.lang.Object
com.easydesk.notification.util.NotificationRenderer

@Component public class NotificationRenderer extends Object
Notification(Email) 의 제목/본문 템플릿 renderer 이다.

예전: Avalon 객체 풀링(InitableRecyclable) + Turbine Template Service (TurbineTemplate.handleRequest) + Velocity(.vm) + 패키지를 거슬러 올라가며 Default.vm 을 찾는 Turbine Resolver.

이후: Spring bean(singleton) + standalone Thymeleaf(SpringTemplateEngine). web(MVC) 과 무관하게 동작하며, 의도적으로 SpringTemplateEngine 을 Spring bean 으로 노출하지 않고 이 클래스 안에서만 만든다 - 그렇지 않으면 easydesk-spring-web-demo 처럼 Spring Boot 가 이미 자동설정한 화면용 SpringTemplateEngine 과 타입이 겹쳐 주입이 모호해지거나 Boot 의 자동설정이 물러난다.

템플릿 위치 (classpath)

  • 제목 : notifications/subject/<name>.txt (Thymeleaf TEXT mode, 예: [[#{...}]])
  • 본문 : notifications/layouts/<name>.html (Thymeleaf HTML mode, 예: th:text)
  • 다국어 : easydesk-localization 의 EasyDeskBundle 등 (템플릿에서 #{key})

NotificationType.getTemplate() 값(예: "ItemAdded.vm", "note/Foo.vm1")에서 확장자를 떼고 위 위치에서 찾는다. 해당 템플릿이 없으면 예전 Resolver 와 같이 상위 폴더의 Default 로 거슬러 올라간다 (note/Foo -> note/Default -> Default).

Author:
Youncho Cho
  • Field Details

    • SUBJECT

      public static final String SUBJECT
      제목 template 종류 (폴더 이름)
      See Also:
    • LAYOUTS

      public static final String LAYOUTS
      본문 template 종류 (폴더 이름)
      See Also:
    • HTML

      public static final String HTML
      layout 안에 들어가는 본문 내용 template 폴더 (예전 html/*.vm)
      See Also:
    • FRAGMENTS

      public static final String FRAGMENTS
      공통 fragment (header/footer 등) template 폴더 (예전 macros/GlobalMacros.vm 의 #macro 대체)
      See Also:
    • DEFAULT_TEMPLATE

      public static final String DEFAULT_TEMPLATE
      못 찾으면 상위 폴더에서 찾는 template 이름
      See Also:
  • Constructor Details

    • NotificationRenderer

      public NotificationRenderer()
      Creates a new NotificationRenderer.
  • Method Details

    • renderSubject

      public String renderSubject(NotificationContext context, String template, Locale locale)
      제목을 render 한다. 제목은 한 줄이어야 하므로 줄바꿈/연속 공백은 공백 하나로 합치고 trim 한다.
      Parameters:
      context - template 변수
      template - NotificationType 의 template 이름 (확장자는 무시된다)
      locale - 수신자 locale
      Returns:
      제목
    • renderBody

      public String renderBody(NotificationContext context, String template, Locale locale)
      본문(html)을 render 한다.
      Parameters:
      context - template 변수
      template - NotificationType 의 template 이름 (확장자는 무시된다)
      locale - 수신자 locale
      Returns:
      html 본문
    • templateExists

      public boolean templateExists(String kind, String template)
      template 이 실제로 존재하는지 (Default 로의 fallback 포함하여) 확인한다.
      Parameters:
      kind - SUBJECT 또는 LAYOUTS
      template - NotificationType 의 template 이름
      Returns:
      사용할 template 이 하나라도 있으면 true