private void renderNotificationContent(NotificationDispatcher dispatcher,
      AlertNotification notification, AlertHistoryEntity history, AlertTargetEntity target)
      throws IOException {
    String targetType = target.getNotificationType();

    // build the velocity objects for template rendering
    AmbariInfo ambari = new AmbariInfo(m_metaInfo.get(), m_configuration);
    AlertInfo alert = new AlertInfo(history);
    DispatchInfo dispatch = new DispatchInfo(target);

    // set the alert info on the notification subclass so that dispatchers
    // can use it directly
    notification.setAlertInfo(alert);

    // get the template for this target type
    final Writer subjectWriter = new StringWriter();
    final Writer bodyWriter = new StringWriter();
    final AlertTemplate template = m_alertTemplates.getTemplate(targetType);

    if (dispatcher.isNotificationContentGenerationRequired()) {
      if (null != template) {
        // create the velocity context for template rendering
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put(VELOCITY_AMBARI_KEY, ambari);
        velocityContext.put(VELOCITY_ALERT_KEY, alert);
        velocityContext.put(VELOCITY_DISPATCH_KEY, dispatch);

        // render the template and assign the content to the notification
        String subjectTemplate = template.getSubject();
        String bodyTemplate = template.getBody();

        // render the subject
        Velocity.evaluate(velocityContext, subjectWriter, VELOCITY_LOG_TAG, subjectTemplate);

        // render the body
        Velocity.evaluate(velocityContext, bodyWriter, VELOCITY_LOG_TAG, bodyTemplate);
      } else {
        // a null template is possible from parsing incorrectly or not
        // having the correct type defined for the target
        subjectWriter.write(alert.getAlertState().name());
        subjectWriter.write(" ");
        subjectWriter.write(alert.getAlertName());

        bodyWriter.write(alert.getAlertState().name());
        bodyWriter.write(" ");
        bodyWriter.write(alert.getAlertName());
        bodyWriter.write(" ");
        bodyWriter.write(alert.getAlertText());
        if (alert.hasHostName()) {
          bodyWriter.write(" ");
          bodyWriter.append(alert.getHostName());
        }
        bodyWriter.write("\n");
      }
    }

    notification.Subject = subjectWriter.toString();
    notification.Body = bodyWriter.toString();
  }
Generates the content for the {@link Notification} using the
{@link #m_alertTemplates} and the single alert passed in. If there is a
problem with the templates, this will fallback to non-formatted content.

@param dispatcher
         the dispatcher for this notification type (not {@code null}).
@param notification
         the notification (not {@code null}).
@param history
         the alert to generate the content from (not {@code null}.
@param target
         the target of the {@link Notification}.
ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java