package com.ngMAT.appl.bbs.servlets; import com.ngMAT.HTML.Anchor; import com.ngMAT.HTML.HTMLTemplate; import com.ngMAT.appl.genericservlet.GenericServletContext; import com.ngMAT.appl.genericservlet.PartitionedListServlet; import com.ngMAT.appl.genericservlet.PartitionedListServletConfig; import com.ngMAT.appl.bbs.data.table.TBbsMessage; public class MessageListServlet extends PartitionedListServlet { public boolean isReadyToGo(GenericServletContext context) { return true; } public void processRowFilling(GenericServletContext context, PartitionedData data, int index, HTMLTemplate row) { // This method is derived from class com.ngMAT.appl.genericservlet.PartitionedListServlet // to do: code goes here MessageListServletConfig config = (MessageListServletConfig)context.getConfig(); TBbsMessage d = (TBbsMessage)data.data.elementAt (index); row.setTagValue ("bbs_message_id", d.bbs_message_id); row.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); row.setTagValue ("contributer_name", a); } else row.setTagValue ("contributer_name", d.contributer_name); if (d.contributer_url != null && d.contributer_url.trim().length() > 0) { HTMLTemplate hplink = context.getTemplate (config.hplink_template_name); hplink.setTagValue ("contributer_url", d.contributer_url); row.setTagValue ("hplink", hplink); } row.setTagValue ("reg_timestamp", config.df.format (d.reg_timestamp)); row.setTagValue ("description", d.description); } public void processSurrounding(GenericServletContext context, PartitionedData data, HTMLTemplate template) { String keyword = (String)data.optional_data.get ("keyword"); if (keyword != null) template.setTagValue ("message", "キーワード:" + keyword); } public void refreshData(GenericServletContext context, PartitionedData data) { // This method is derived from class com.ngMAT.appl.genericservlet.PartitionedListServlet // to do: code goes here MessageListServletConfig config = (MessageListServletConfig)context.getConfig(); String command = context.getParameter ("command"); if (command != null) { if (command.equalsIgnoreCase ("change_order")) processChangeOrder (context, data); else if (command.equalsIgnoreCase ("query")) processSearchKey (context, data); } long bbs_id = context.getLongParameter ("bbs_id", 0); if (bbs_id == 0) context.forward (config.getProperty ("bbs.Url.forward.BbsList")); String order_by = (String)data.optional_data.get ("order_by"); if (order_by == null) order_by = config.DEFAULT_ORDER_BY; String condition = (String)data.optional_data.get ("condition"); if (condition == null) condition = ""; data.data = TBbsMessage.selectAny (context, "where bbs_id = " + bbs_id + condition + " and deleted_on is null " + order_by); } private void processChangeOrder (GenericServletContext context, PartitionedData data) { MessageListServletConfig config = (MessageListServletConfig)context.getConfig(); String order_by = config.DEFAULT_ORDER_BY; String s = context.getParameter ("order"); if (s != null) { if (s.equalsIgnoreCase ("+")) order_by = "order by bbs_message_id asc"; } data.optional_data.put ("order_by", order_by); } private void processSearchKey (GenericServletContext context, PartitionedData data) { String condition = ""; String keyword = context.getParameter ("keyword"); if (keyword != null) { keyword = keyword.trim(); if (keyword.length()> 0) condition = " and description like '%" + escapeSearchKey (context, keyword) + "%'"; else keyword = null; } data.optional_data.put ("condition", condition); if (keyword != null) data.optional_data.put ("keyword", keyword); else data.optional_data.remove ("keyword"); } private String escapeSearchKey (GenericServletContext context, String s) { PartitionedListServletConfig config = (PartitionedListServletConfig)context.getConfig(); if (s.length() > config.search_key_max_length) s = s.substring (0, config.search_key_max_length); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt (i); if (c == '\'') buffer.append ("''"); else buffer.append (c); } return new String (buffer); } /** * PartitionedListServlet#processCommand(...)をオーバライド。 */ public void processCommand (GenericServletContext context, HTMLTemplate template, PartitionedData sd) { String command = context.getParameter ("command"); if (command != null) { if (command.equalsIgnoreCase ("change_order")) sd.refresh_required = true; else if (command.equalsIgnoreCase ("query")) sd.refresh_required = true; } } }