package jp.co.y_net.amm.common;

import java.util.Date;

import jp.co.y_net.amm.dao.Inf;

public class InfoRenderer {
//    public static String execute(String title, String body) {
//        return execute(title, "XXXX/XX/XX", body);
//    }
    public static String execute(Inf inf) {
        if(inf == null) {
            return "";
        }
        Date dPubdate = AppUtils.toDate(inf.getPubdate());
        String strPubdate;
        if(dPubdate != null) {
            strPubdate = Inf.DF_PUBDATE.format(dPubdate);
        } else {
            strPubdate = Inf.DF_PUBDATE.format(new Date());
        }
        
        return execute(inf.getTitle(), strPubdate, inf.getBody());
    }
    private static String execute(String title, String pubdate, String body) {
        
        body = body.replaceAll("\n", "<br />");
        
        StringBuilder sb = new StringBuilder();
        sb.append("<h2>" + title + "</h2>\n");
        sb.append(pubdate + "<br />\n");
//        sb.append("<br />\n");
        sb.append(body);
        return sb.toString();
    }



}
