public Map < String , String > processTemplate ( ActionMessage msg ) throws Exception { Map < String , String > emailProcessed = new HashMap <> ( ) ; PluginMessageDescription pmDesc = new PluginMessageDescription ( msg ) ; // Prepare emailSubject directly from PluginMessageDescription class emailProcessed . put ( "emailSubject" , pmDesc . getEmailSubject ( ) ) ; // Check if templates are defined in properties String plain ; String html ; String templateLocale = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_LOCALE ) : null ; if ( templateLocale != null ) { plain = pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_PLAIN + "." + templateLocale ) ; html = pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_HTML + "." + templateLocale ) ; } else { plain = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_PLAIN ) : null ; html = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_HTML ) : null ; } /* Invoke freemarker template with PluginMessageDescription as root object for dynamic data. PluginMessageDescription fields are accessible within .ftl templates. */ StringWriter writerPlain = new StringWriter ( ) ; StringWriter writerHtml = new StringWriter ( ) ; if ( ! isEmpty ( plain ) ) { StringReader plainReader = new StringReader ( plain ) ; ftlTemplate = new Template ( "plainTemplate" , plainReader , ftlCfg ) ; ftlTemplate . process ( pmDesc , writerPlain ) ; } else { ftlTemplatePlain . process ( pmDesc , writerPlain ) ; } if ( ! isEmpty ( html ) ) { StringReader htmlReader = new StringReader ( html ) ; ftlTemplate = new Template ( "htmlTemplate" , htmlReader , ftlCfg ) ; ftlTemplate . process ( pmDesc , writerHtml ) ; } else { ftlTemplateHtml . process ( pmDesc , writerHtml ) ; } writerPlain . flush ( ) ; writerPlain . close ( ) ; emailProcessed . put ( "emailBodyPlain" , writerPlain . toString ( ) ) ; writerHtml . flush ( ) ; writerHtml . close ( ) ; emailProcessed . put ( "emailBodyHtml" , writerHtml . toString ( ) ) ; return emailProcessed ; }
Process a PluginMessage and creates email content based on templates .