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