001package bradleyross.library.helpers; 002import java.sql.ResultSet; 003import java.sql.SQLException; 004import java.sql.ResultSetMetaData; 005public abstract class WebTable implements TableInterface 006{ 007 protected GenericPrinter output = null; 008 protected int debugLevel = 0; 009 protected int columnCount = 0; 010 protected int rowCount = 0; 011 public void finishRow() 012 { 013 output.println("</tr>"); 014 } 015 public void finishTable() 016 { 017 output.println("</table>"); 018 019 } 020 public void formatCell(Object value) 021 { 022 formatCell(value, NORMAL); 023 } 024 public void formatCell(Object value, int format) 025 { 026 output.println("<td>" + value.toString() + "</td>"); 027 028 } 029 030 public void formatDataRow(Object...values) 031 { 032 startRow(); 033 for (int i = 0; i < values.length; i++) 034 { 035 formatCell(values[i]); 036 } 037 finishRow(); 038 } 039 public void formatDataRow(ResultSet rs) throws SQLException 040 { 041 startRow(); 042 for (int i = 1; i <= getColumnCount(); i++) 043 { 044 formatCell(rs.getString(i)); 045 } 046 finishRow(); 047 } 048 049 public void formatHeaderRow(Object... values) 050 { 051 startRow(); 052 for (int i = 0; i < values.length; i++) 053 { 054 formatCell(values[i]); 055 } 056 finishRow(); 057 } 058 public void formatHeaderRow(ResultSet rs) throws SQLException 059 { 060 ResultSetMetaData meta = rs.getMetaData(); 061 startRow(); 062 for (int i = 0; i <= getColumnCount(); i++) 063 { 064 formatCell(meta.getColumnName(i)); 065 } 066 finishRow(); 067 } 068 public int getColumnCount() 069 { 070 return columnCount; 071 } 072 073 public int getDebugLevel() 074 { 075 return debugLevel; 076 } 077 078 public void setColumnCount(int value) 079 { 080 columnCount = value; 081 082 } 083 public void setDebugLevel(int value) 084 { 085 debugLevel = value; 086 087 } 088 public void startRow() 089 { 090 rowCount++; 091 output.println("<tr>"); 092 } 093 public void startTable() 094 { 095 output.println("<table border=\"1\">"); 096 097 } 098 public void setOutput(GenericPrinter value) 099 { 100 output = value; 101 102 } 103 104}