public static String makeMultilineDisplayable(String text) {
    String result = text;

    if (!Utility.isNullOrEmpty(text)) {
      result = result.replaceAll("\n", "<br/>");
    }

    return result;
  }
  private static void addWhereClause(StringBuffer buffer, String columnName, String[] values) {
    if ((buffer != null)
        && !Utility.isNullOrEmpty(columnName)
        && (values != null)
        && (values.length > 0)) {
      boolean nonBlankFound = false;

      for (String value : values) {
        if ("ALL".equalsIgnoreCase(value)) {
          return;
        }

        if (!isNullOrEmpty(value)) {
          nonBlankFound = true;
        }
      }

      if (!nonBlankFound) {
        return;
      }

      if (buffer.length() > 0) {
        buffer.append(" and ");
      }
      if (values.length > 1) {
        buffer.append('(');
      }

      for (int x = 0; x < values.length; x++) {
        if (x != 0) {
          buffer.append(" or ");
        }
        buffer.append(columnName);
        buffer.append("='");
        buffer.append(values[x]);
        buffer.append("'");
      }

      if (values.length > 1) {
        buffer.append(')');
      }
    }
  }
  public static void sendNotification(
      String toUsername, String toEmailAddress, String subjectText, String messageText) {
    if (!Utility.isNullOrEmpty(toUsername)
        && !Utility.isNullOrEmpty(subjectText)
        && !Utility.isNullOrEmpty(messageText)
        && !Utility.isNullOrEmpty(toEmailAddress)) {
      Properties properties = new Properties();

      properties.put("mail.smtp.host", UtilityResource.getSmtpHost());
      properties.put("mail.smtp.port", UtilityResource.getSmtpPort());

      Session session = Session.getInstance(properties);

      if (session == null) {
        UtilityFaces.addError("Unable to notify user. Failed to retrieve mail session");
      } else {
        try {
          Message message = new MimeMessage(session);
          InternetAddress fromAddress =
              new InternetAddress(UtilityResource.getNotificationFromAddress());

          InternetAddress toAddress = new InternetAddress(toEmailAddress);

          message.setFrom(fromAddress);
          message.addRecipient(Message.RecipientType.TO, toAddress);
          message.setSubject(subjectText);
          message.setContent(messageText, "text/plain");
          Transport.send(message);

          UtilityFaces.addInfo(
              "User \"" + toUsername + "\" notified at \"" + toEmailAddress + "\"");
        } catch (Exception e) {
          UtilityFaces.addError("Failed to notify user on " + toEmailAddress, e);
        }
      }
    } else {
      UtilityLog.logWarning(
          Utility.class,
          "Unable to notify. Username="******", Email Address="
              + toEmailAddress
              + ", Subject="
              + subjectText
              + ", Message="
              + messageText,
          null);

      StringBuffer msg = new StringBuffer();

      if (!isNullOrEmpty(toUsername)) {
        msg.append("Unable to notify user \"");
        msg.append(toUsername);
        msg.append("\".");

        if (isNullOrEmpty(toEmailAddress)) {
          if (msg.length() > 0) {
            msg.append(" ");
          }

          msg.append("No email address is available.");
        } else {
          msg.append(" At email address \"");
          msg.append(toEmailAddress);
          msg.append("\"");
        }
      }

      if (msg.length() > 0) {
        UtilityFaces.addError(msg.toString());
      }
    }
  }