package com.ngMAT.appl.etc.customtags; import java.text.SimpleDateFormat; import com.ngMAT.HTML.EZSCustomTag; import com.ngMAT.servlet.EZServletContext; import com.ngMAT.appl.GenericRuntimeException; import com.ngMAT.appl.genericservlet.GenericServletContext; /** * @author tsuhtan * * 現在時刻を表示するカスタムタグ。 */ public class Now extends EZSCustomTag { private final static String default_timestamp_format_string = "yyyy/MM/dd HH:mm:ss"; private SimpleDateFormat timestamp_format = null; private String result = null; /* テンプレートがロードされた時点での初期化。書式の指定をゲットしておく。 * @see com.ngMAT.HTML.CustomTag#init() */ public void init() { String s = super.getAttribute ("timestamp_format"); timestamp_format = new SimpleDateFormat (s != null ? s : default_timestamp_format_string); } /* このカスタムタグオブジェクトを使用するテンプレートがロードされた時に * 呼ばれる。このタイミングで文字列を用意しちゃう。 * @see com.ngMAT.HTML.EZSCustomTag#loaded(EZServletContext) */ public void loaded (EZServletContext _context) { result = timestamp_format.format (new java.util.Date()); } /* フラッシュされる前に呼ばれる。このクラスでは何もしない。 * @see com.ngMAT.HTML.EZSCustomTag#fix(EZServletContext) */ public void fix (EZServletContext arg0) { } /* このオブジェクトを文字列表現に変換する。 * @see com.ngMAT.HTML.HTMLComponent#toHTML() */ public String toHTML() { return result; } }