|
What this is
Other links
The source code
/**
* CSGuestbook.java
* Pete Willemsen
* CoolServlets.com
* February 3, 2000
* Version 1.01
*
* Any errors or feature requests can be reported on CoolServlets.com.
* We hope you enjoy this program!
*
* Copyright (C) 1999 Pete Willemsen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import javax.servlet.*;
import javax.servlet.ServletRequest;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.coolservlets.guestbook.*;
import com.coolservlets.util.*;
/**
* The main Java servlet for the CSGuestbook system.
*
* Three modes of operation: DISPLAY_MODE, RECORD_MODE, ADMIN_MODE
*
* "mode" - determines mode of operation
* VALUES: "display", "record", "admin" (default="display")
*
* MODE 1 PARAMETERS - DISPLAY_MODE - mode="display" || mode=null
*
* "key" - specifies the name of the guestbook to use
* VALUES: a string representing name of guestbook (default="default")
*
* "html" - determines whether guestbook should return full HTML, or
* just guestbook entries (I envision use of the SERVLET tag
* in the * latter case)
* VALUES: "on", "off" (default="on")
*
* "sty" - specifies the style type for printing of guestbook entries
* VALUES: "s1", "s2", "s3", "s4", "s5" (default="s1")
*
* "fltr" - specifies whether to filter words in the comment section;
* currently uses built-in list of words
* VALUES: "on", "off" (default="off")
*
* "fltrlist" - specifies a comma-delimited list of strings to use as
* the filter in the comment section. This option is
* only effective when fltr="on". The comma-delimited list
* of words overrides the built-in list of words. The
* filter currently only works well with words, so things
* like "filter this" won't work well as a filter, but
* unique separate words like "shit" will work. Future
* versions will be more robust about filtering.
* VALUES: comma-delimited list of strings to filter
*
* "cnt" - number of entries to return (returns most recent entries)
* VALUES: any positive number (default=all)
*
* "title" - specifies the title to be used on the guestbook page
* "fontFace" - sets the style of the font face for the document
* VALUES: any font face (default=normal)
* "fontSize" - sets the style for the font size for the document
* VALUES: any font size (default=normal)
* "background" - uses the file given as parameter for a background
* image. VALUES: an image file (default=none)
* "bgcolor" - specifies the background color for the guestbook page.
* VALUES: any browser specified color (default=normal)
* "text" - specifies the color for normal text
* VALUES: any browser defined color (default="#000000")
* "link" - specifies the color for links
* VALUES: any browser defined color (default="#0000ff")
* "vlink" - specifies the color for visited links
* VALUES: any browser defined color (default="#800080")
* "alink" - specifies the color for active links
* VALUES: any browser defined color (default="#ff0000")
*
* MODE 2 PARAMETERS - RECORD_MODE - mode="record"
*
* "key" - specifies the name of the guestbook to use
* "name" - form input parameter that holds their name
* "email" - form input parameter that holds their email address
* "url" - form input parameter that holds their url
* "city" - form input parameter that holds their city
* "state" - form input parameter that holds their state
* "country" - form input parameter that holds their country
* "comment" - form input parameter (textarea) that holds their comment
*
* "response" - specifies a thank you response used when an entry has
* been added to the database.
* "linkBack" - Specifies the link to use as a return link.
* VALUES: any URL such as "http://www.cnn.com" (default=none)
* "textBack" - The text that is associated with the linkBack parameter.
* VALUES: a string (default="Go Back")
*
* "title" - specifies the title to be used on the guestbook page
* "fontFace" - sets the style of the font face for the document
* VALUES: any font face (default=normal)
* "fontSize" - sets the style for the font size for the document
* VALUES: any font size (default=normal)
* "background" - uses the file given as parameter for a background
* image. VALUES: an image file (default=none)
* "bgcolor" - specifies the background color for the guestbook page.
* VALUES: any browser specified color (default=normal)
* "text" - specifies the color for normal text
* VALUES: any browser defined color (default="#000000")
* "link" - specifies the color for links
* VALUES: any browser defined color (default="#0000ff")
* "vlink" - specifies the color for visited links
* VALUES: any browser defined color (default="#800080")
* "alink" - specifies the color for active links
* VALUES: any browser defined color (default="#ff0000")
*
*
* MODE 3 PARAMETERS - ADMIN_MODE - mode="admin" - NOT IMPLEMENTED
*
* */
public class CSGuestbook extends HttpServlet implements MaintainedServlet {
/** ****************************************
* Initialize global variables
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Read the guestbook database from file.
database = readDatabaseFile();
//Startup a maintenance thread that will write the guestbook database
//to file every 10 minutes.
maintenance = new ServletMaintenance(this, 10, ServletMaintenance.MINUTES);
}
/**
* Process HTTP requests.
*/
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
// --------------------------------------------------------
// acquire basic options used in all modes
// --------------------------------------------------------
thankyou_response = request.getParameter( "response" );
if (thankyou_response == null)
thankyou_response = "Thanks for signing our guestbook!";
title = request.getParameter( "title" );
if (title == null || title.length() == 0)
title = "CSGuestbook";
fontFace = request.getParameter( "fontFace" );
fontSize = request.getParameter( "fontSize" );
linkBack = request.getParameter( "linkBack" );
textBack = request.getParameter( "textBack" );
background = request.getParameter( "background" );
bgcolor = request.getParameter( "bgcolor" );
text = request.getParameter( "text" );
link = request.getParameter( "link" );
vlink = request.getParameter( "vlink" );
alink = request.getParameter( "alink" );
// --------------------------------------------------------
// Check mode type first: DISPLAY, RECORD, ADMIN
// --------------------------------------------------------
String mode = request.getParameter("mode");
if (mode != null) {
if (mode.equals( "record" )) {
// enter RECORD_MODE and process request
enterRecordMode( request, response );
}
// else if (mode.equals( "admin" )) {
// do admin duties - not yet completed and will be release
// in next version
// }
else {
// assume DISPLAY_MODE if no "known" mode is specified
enterDisplayMode( request, response );
}
}
else {
// assume DISPLAY_MODE if no mode is specified
enterDisplayMode( request, response );
}
}
/** ****************************************
*
*/
public void doMaintenance() {
writeDatabaseFile();
}
/** ****************************************
* Called as the servlet is being destroyed. It saves the counter
* database and stops the maintenance thread.
*/
public void destroy() {
writeDatabaseFile();
maintenance.shutDown();
}
/** ****************************************
* Get Servlet information
*/
public String getServletInfo() {
return "CSGuestbook v1.0 - CoolServlets.com";
}
/** ****************************************
*
*/
private void printGuestbookHeader( PrintWriter out ) {
out.println( "<html>
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.