001 /***************************************************************************** 002 * MODULE DESCRIPTION 003 ****************************************************************************** 004 * 005 * NAME: HtmlBean.java 006 * LANGUAGE: Java 2 007 * DATE: 11.02.2002 008 * AUTHOR: Miika Nurminen, University of Jyväskylä (JYU) 009 * PURPOSE: Abstraction of HTML table + related routines 010 * 011 ****************************************************************************** 012 * COPYRIGHT (C) Kiuru group 013 * Limited rights granted. Please refer to license 014 *****************************************************************************/ 015 016 /***************************************************************************** 017 * UPDATES 018 ****************************************************************************** 019 * 020 * 11.2.2003 / mn 021 * - Initial version 022 * 023 ******************************************************************************/ 024 package kiurubeans; 025 import kotkabeans.RS2; 026 import kotkabeans.Log; 027 import java.util.*; 028 029 /** 030 * Abstraction of HTML table 031 * 032 * @author Miika Nurminen 033 */ 034 public class HtmlTable { 035 /** If true links for ordering table are appended to table headers */ 036 private boolean orderLinks = true; 037 038 /** RS2 where data is retrieved */ 039 private RS2 rs; 040 /** 041 * Used with order links 042 */ 043 private String baseDocument; 044 045 /** Column data */ 046 private ArrayList columnList = new ArrayList(); 047 048 /** Creates a new instance of HtmlTable - dummy empty constructor */ 049 public HtmlTable() { 050 } 051 052 /** Creates a new instance of HtmlTable 053 * @param rs RS2 to be iterated in table 054 * @param baseDoc base address for ordering 055 */ 056 public HtmlTable(RS2 rs, String baseDoc) { 057 setRs(rs); 058 setBaseDocument(baseDoc); 059 } 060 061 /** Creates a new instance of HtmlTable 062 * @param c columns to be added 063 * @param rs RS2 to be iterated in table 064 * @param baseDoc base address for ordering 065 */ 066 public HtmlTable(RS2 rs, String baseDoc, HtmlColumn[] c) { 067 setRs(rs); 068 setBaseDocument(baseDoc); 069 addColumn(c); 070 } 071 072 /** Getter for property orderLinks. 073 * @return Value of property orderLinks. 074 */ 075 public boolean getOrderLinks() { 076 return orderLinks; 077 } 078 079 /** Setter for property orderLinks. 080 * @param o new value for orderLinks 081 */ 082 public void setOrderLinks(boolean o) { 083 orderLinks=o; 084 } 085 086 /** Getter for property rs. 087 * @return Value of property rs. 088 */ 089 public RS2 getRs() { 090 return this.rs; 091 } 092 093 /** Setter for property rs. 094 * @param rs New value of property rs. 095 */ 096 public void setRs(RS2 rs) { 097 this.rs = rs; 098 } 099 100 101 /** Getter for property baseDocument. 102 * @return Value of property baseDocument. 103 */ 104 public String getBaseDocument() { 105 return this.baseDocument; 106 } 107 108 /** Setter for property baseDocument. 109 * @param baseDocument New value of property baseDocument. 110 */ 111 public void setBaseDocument(String baseDocument) { 112 this.baseDocument = baseDocument; 113 } 114 115 116 /** 117 * Clears column data for current table 118 */ 119 public void clear() { 120 columnList.clear(); 121 } 122 123 /** 124 * Adds new column to list 125 * @param c column to be added 126 */ 127 public void addColumn(HtmlColumn c) { 128 columnList.add(c); 129 } 130 131 /** 132 * Adds an array of columns to list 133 * @param c columns to be added 134 */ 135 public void addColumn(HtmlColumn[] c) { 136 if ((c==null) || (c.length==0)) return; 137 for (int i=0; i<c.length; i++) 138 addColumn(c[i]); 139 } 140 141 /** 142 * Generates HTML table 143 * @return table & content in HTML format 144 */ 145 public String generateTable() { 146 if (columnList.size()==0) return ""; 147 if (SimpleDb.isEmpty(getRs())) return ""; 148 149 StringBuffer result = new StringBuffer(100); 150 151 result.append(HtmlBean.begin_table()); 152 153 result.append("<tr>"); 154 Iterator i = columnList.iterator(); 155 while (i.hasNext()) { 156 HtmlColumn h = (HtmlColumn)(i.next()); 157 result.append("<th>"); 158 result.append(h.getHeader(getBaseDocument(),getOrderLinks())); 159 result.append("</th>\n"); 160 } 161 result.append("</tr>"); 162 163 while (getRs().next()) { 164 result.append("<tr>"); 165 i = columnList.iterator(); 166 while (i.hasNext()) { 167 HtmlColumn h = (HtmlColumn)(i.next()); 168 result.append("<td>"); 169 result.append(h.getCellData(getRs())); 170 result.append("</td>"); 171 } 172 result.append("</tr>"); 173 } 174 175 result.append("</table>"); 176 177 return result.toString(); 178 } 179 180 } 181 /*************************************************************************************************** 182 * COPYRIGHT (C) KIURU -PROJECT GROUP 183 * Limited rights granted. Please refer to license. 184 **************************************************************************************************/