package com.ngMAT.appl.bbs.etc.customtags; import java.io.IOException; import java.text.SimpleDateFormat; import com.ngMAT.HTML.Anchor; 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; import com.ngMAT.appl.genericservlet.GenericServletConfig; /** * * 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() { } /* (non-Javadoc) * @see com.ngMAT.HTML.EZSCustomTag#loaded(EZServletContext) */ public void loaded (EZServletContext context) { // init---- try { template = HTMLTemplate.createHTMLTemplateFromString (context, 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); } // init---- } /* (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); String email = d.contributer_email; if (email != null && email.length() > 0) { Anchor a = new Anchor ("mailto:" + d.contributer_email, d.contributer_name); template.setTagValue ("contributer_name", a); } else template.setTagValue ("contributer_name", d.contributer_name); if (d.contributer_url != null) { GenericServletConfig config = (GenericServletConfig)context.getConfig(); HTMLTemplate hplink = context.getTemplate (config.getProperty ("bbs.HpLink.Template")); hplink.setTagValue ("contributer_url", d.contributer_url); template.setTagValue ("hplink", hplink); } 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()); } }