public static Map<String,Object> prepareNotification(DispatchContext ctx,Map<String,? extends Object> context){
  Delegator delegator=ctx.getDelegator();
  String templateName=(String)context.get("templateName");
  Map<String,Object> templateData=UtilGenerics.checkMap(context.get("templateData"));
  String webSiteId=(String)context.get("webSiteId");
  Locale locale=(Locale)context.get("locale");
  Map<String,Object> result=null;
  if (templateData == null) {
    templateData=new LinkedHashMap<String,Object>();
  }
  try {
    setBaseUrl(delegator,webSiteId,templateData);
    URL templateUrl=FlexibleLocation.resolveLocation(templateName);
    if (templateUrl == null) {
      Debug.logError("Problem getting the template URL: " + templateName + " not found",module);
      return ServiceUtil.returnError(UtilProperties.getMessage(resource,"CommonNotifyEmailProblemFindingTemplate",locale));
    }
    Writer writer=new StringWriter();
    FreeMarkerWorker.renderTemplate(templateUrl.toExternalForm(),templateData,writer);
    String notificationBody=writer.toString();
    result=ServiceUtil.returnSuccess(UtilProperties.getMessage(resource,"CommonNotifyEmailMessageBodyGeneratedSuccessfully",locale));
    result.put("body",notificationBody);
  }
 catch (  IOException ie) {
    Debug.logError(ie,"Problems reading template",module);
    result=ServiceUtil.returnError(UtilProperties.getMessage(resource,"CommonNotifyEmailProblemReadingTemplate",locale));
  }
catch (  TemplateException te) {
    Debug.logError(te,"Problems processing template",module);
    result=ServiceUtil.returnError(UtilProperties.getMessage(resource,"CommonNotifyEmailProblemProcessingTemplate",locale));
  }
  return result;
}

public static Map < String , Object > prepareNotification ( DispatchContext ctx , Map < String , ? extends Object > context ) { Delegator delegator = ctx . getDelegator ( ) ; String templateName = ( String ) context . get ( "templateName" ) ; Map < String , Object > templateData = UtilGenerics . checkMap ( context . get ( "templateData" ) ) ; String webSiteId = ( String ) context . get ( "webSiteId" ) ; Locale locale = ( Locale ) context . get ( "locale" ) ; Map < String , Object > result = null ; if ( templateData == null ) { templateData = new LinkedHashMap < String , Object > ( ) ; } try { setBaseUrl ( delegator , webSiteId , templateData ) ; URL templateUrl = FlexibleLocation . resolveLocation ( templateName ) ; if ( templateUrl == null ) { Debug . logError ( "Problem getting the template URL: " + templateName + " not found" , module ) ; return ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "CommonNotifyEmailProblemFindingTemplate" , locale ) ) ; } Writer writer = new StringWriter ( ) ; FreeMarkerWorker . renderTemplate ( templateUrl . toExternalForm ( ) , templateData , writer ) ; String notificationBody = writer . toString ( ) ; result = ServiceUtil . returnSuccess ( UtilProperties . getMessage ( resource , "CommonNotifyEmailMessageBodyGeneratedSuccessfully" , locale ) ) ; result . put ( "body" , notificationBody ) ; } catch ( IOException ie ) { Debug . logError ( ie , "Problems reading template" , module ) ; result = ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "CommonNotifyEmailProblemReadingTemplate" , locale ) ) ; } catch ( TemplateException te ) { Debug . logError ( te , "Problems processing template" , module ) ; result = ServiceUtil . returnError ( UtilProperties . getMessage ( resource , "CommonNotifyEmailProblemProcessingTemplate" , locale ) ) ; } return result ; }
this will process the associated notification template definition with all the fields contained in the given context and generate the message body of the notification . < p > the result returned will contain the appropriate response messages indicating success or failure and the out parameter , " body " containing the generated message .
