package com.ngMAT.appl.bbs.etc.customtags; import java.io.IOException; import java.text.SimpleDateFormat; import com.ngMAT.HTML.EZSCustomTag; import com.ngMAT.HTML.HTMLTemplate; import com.ngMAT.servlet.EZServletContext; import com.ngMAT.appl.GenericRuntimeException; import com.ngMAT.appl.genericservlet.GenericServletContext; import com.ngMAT.appl.bbs.data.table.TBbsMessage; /** * * Bbs message box custom tag. */ public class BbsMessageBox extends EZSCustomTag { private final static String default_timestamp_format_string = "yyyy/MM/dd HH:mm:ss"; private SimpleDateFormat timestamp_format = null; private HTMLTemplate template = null; private boolean is_empty = true; /* (non-Javadoc) * @see com.ngMAT.HTML.CustomTag#init() */ public void init() { try { template = HTMLTemplate.createHTMLTemplateFromString (super.getContent()); String s = super.getAttribute ("timestamp_format"); timestamp_format = new SimpleDateFormat (s != null ? s : default_timestamp_format_string); } catch (IOException e) { throw new GenericRuntimeException (e); } } /* (non-Javadoc) * @see com.ngMAT.HTML.EZSCustomTag#loaded(EZServletContext) */ public void loaded (EZServletContext context) { } /* (non-Javadoc) * @see com.ngMAT.HTML.EZSCustomTag#fix(EZServletContext) */ public void fix (EZServletContext _context) { GenericServletContext context = (GenericServletContext)_context; long bbs_message_id = context.getLongParameter ("bbs_message_id", 0); if (bbs_message_id > 0) { context.assignConnection(); TBbsMessage d = TBbsMessage.select (context, bbs_message_id); context.releaseConnection(); if (d != null) { template.setTagValue ("bbs_message_id", d.bbs_message_id); template.setTagValue ("subject", d.subject); template.setTagValue ("contributer_name", d.contributer_name); template.setTagValue ("contributer_email", d.contributer_email); template.setTagValue ("reg_timestamp", timestamp_format.format (d.reg_timestamp)); template.setTagValue ("description", d.description); is_empty = false; } } } /* (non-Javadoc) * @see com.ngMAT.HTML.HTMLComponent#toHTML() */ public String toHTML() { return (is_empty ? "" : template.toHTML()); } }