public class TableFilter extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { // Get all headers set by the PRevious servlet and echo them java.util.Enumeration e = req.getHeaderNames(); while (e.hasMoreElements()) { String header = (String)e.nextElement(); String value = req.getHeader(header); resp.setHeader(header, value); } // Get the input and output streams ServletInputStream in = req.getInputStream(); ServletOutputStream out = resp.getOutputStream(); // Only process if this is a recognized MIME type String type = req.getContentType(); if (type.equals("text/html") type.equals("text/table") type.equals("application/x-www-form-urlencoded")) { resp.setContentType("text/html"); // Create a buffered reader that we can use to read // a single line at a time BufferedReader br = new BufferedReader(new InputStreamReader(in));
// If we are in the middle of a table command, process // the line
if (inTable) {
// Search for the end of the table if (s.startsWith("<!--end table")) { out.println("</table></center>"); inTable = false; } else { // We've got a row of a table - format it s = formatRow(s, tableCols, headerRow); headerRow = false; } } else {
// Search for the start of a table if (s.startsWith("<!--table")) { int pos = s.indexOf("columns="); tableCols = 0; if (pos >= 0) {