1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/* $Id: CSPage.java,v 1.1 2002/09/20 23:14:10 jeske Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.String.*;
import org.clearsilver.*;
/**
* The simplest possible servlet.
*
*/
public class CSPage extends HttpServlet {
public HDF hdf;
public CS cs;
public boolean page_debug = true;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out = response.getWriter();
hdf = new HDF();
cs = new CS(hdf);
// HTTP headers
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String headerName = (String)e.nextElement();
String headerValue = request.getHeader(headerName);
hdf.setValue("HTTP." + headerName,headerValue);
}
hdf.setValue("HTTP.PATH_INFO",request.getPathInfo());
hdf.setValue("CGI.QueryString",request.getQueryString());
hdf.setValue("CGI.RequestMethod",request.getMethod());
// Querystring paramaters
e = request.getParameterNames();
while (e.hasMoreElements()) {
String paramName = (String)e.nextElement();
String paramValue = request.getParameter(paramName);
hdf.setValue("Query." + paramName,paramValue);
}
// Cookies
Cookie[] cookies = request.getCookies();
if (cookies.length > 0) {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
hdf.setValue("Cookie." + cookie.getName(),cookie.getValue());
}
}
// CGI example
// check for Actions
// then call display method
this.display();
// run required page template through CS
// cs.parseFile(a_template_file);
// Page Output
/* first do cookies
String cookieName = request.getParameter("cookiename");
String cookieValue = request.getParameter("cookievalue");
if (cookieName != null && cookieValue != null) {
Cookie cookie = new Cookie(cookieName, cookieValue);
response.addCookie(cookie);
out.println("<P>");
out.println(rb.getString("cookies.set") + "<br>");
out.print(rb.getString("cookies.name") + " " + cookieName +
"<br>");
out.print(rb.getString("cookies.value") + " " + cookieValue);
}
*/
response.setContentType("text/html");
out.print(cs.render());
// debug
if (page_debug) {
out.print("<HR><PRE>");
out.print(hdf.dump());
out.print("</PRE>");
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
doGet(request, response);
}
public void display() {
hdf.setValue("Foo.Bar","1");
cs.parseStr("Hello Clearsilver<p><TABLE BORDER=1><TR><TD>Foo.Bar</TD><TD><?cs var:Foo.Bar ?></TD></TR></TABLE>");
}
}
|