Package com.ourlinc.activity

Source Code of com.ourlinc.activity.EmailTemplates

package com.ourlinc.activity;

import java.io.FileInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Date;

/**
* 使用邮件模版生成邮件内容
*
* @author lipeiying
*
*/
public class EmailTemplates {
  // 模版为html文件,使用gbk编码,放在项目根目录下的templates目录中
  private EmailTemplates() {
  }

  /**
   * 创建发布活动邮件通知的内容
   *
   * @param date
   *            活动举行日期
   * @param name
   *            活动名称
   * @param id
   *            活动id
   * @return
   * @throws IOException
   */
  public static String buildAddContent(Date date, String name, int id)
      throws IOException {
    return MessageFormat.format(read("templates/add.html"), date, name, id);
  }

  /**
   * 创建取消活动邮件通知内容
   *
   * @param date
   *            活动举行日期
   * @param name
   *            活动名称
   * @return
   * @throws IOException
   */
  public static String buildCancelContent(Date date, String name)
      throws IOException {
    return MessageFormat.format(read("templates/cancel.html"), date, name);
  }

  /**
   * 创建修改活动邮件通知内容
   *
   * @param date
   *            活动举行日期
   * @param name
   *            活动名称
   * @param different
   *            修改了的内容
   * @param id
   *            活动id
   * @return
   * @throws IOException
   */
  public static String buildEditContent(Date date, String name,
      String different, int id) throws IOException {
    return MessageFormat.format(read("templates/edit.html"), date, name,
        different, id);
  }

  /**
   * 涉及并发读取同一个文件
   *
   * @param filePath
   * @return
   * @throws IOException
   */
  private static String read(String filePath) throws IOException {
    FileInputStream in = new FileInputStream(filePath);
    byte[] buf = new byte[in.available()];
    try {
      in.read(buf);
    } finally {
      in.close();
    }
    return new String(buf, "GBK");
  }

  public static void main(String[] args) throws IOException {
    System.out.println(read("templates/cancel.html"));
  }
}
TOP

Related Classes of com.ourlinc.activity.EmailTemplates

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.