");
if (url.length() != 0)
out.println("<tr>");
if (comments.length() != 0)
out.println("<tr>");
out.println("</table>");
out.println("<hr NOSHADE width=65%>");
out.println("<!-- End Entry Section: STYLE4 -->");
}
else if ( s.type == GuestbookStyle.STYLE_5 ) {
out.println("<!-- Begin Entry Section: STYLE5 -->");
out.print("<b>");
if (name.length() != 0)
out.print(name + " - ");
out.print(simple_date.format( _timestamp ));
if (email.length() != 0)
out.print(" - " + uriEmail());
out.println("</b>
");
if (url.length() != 0)
out.println("<b>url: " + uriUrl() + "
");
if (comments.length() != 0) {
out.println("<b>comment:");
out.println("<ul>" + f.filterBadwords( comments ) + "");
}
out.println("<hr NOSHADE width=65%>");
out.println("<!-- End Entry Section: STYLE5 -->");
}
else if ( s.type == GuestbookStyle.FULL ) {
out.println("<!-- Begin Entry Section: FULL-->");
out.println("<b>Time of submission: " + simple_date.format( _timestamp ) + "
");
out.println("<b>Name:" + name + "
");
out.println("<b>EMail:" + uriEmail() + "
");
out.println("<b>URL:" + uriUrl() + "
");
out.println("<b>City:" + city + "
");
out.println("<b>State:" + state + "
");
out.println("<b>Country:" + country + "
");
out.println("<b>Comment
");
out.println("<ul>" + f.filterBadwords( comments ) + "");
out.println("<!-- End Entry Section: STYLE5 -->");
}
else {
out.println("<!-- Begin Entry Section: Default(STYLE1) -->");
out.println("<B>" + simple_date.format( _timestamp ) + "
");
out.print(name);
if (email.length() != 0)
out.print(" <" + uriEmail() + ">");
if (name.length() != 0 || email.length() != 0)
out.println("<BR>");
out.println("<BR>");
out.println("<I>" + f.filterBadwords( comments ) + "");
out.println("<HR>");
out.println("<!-- End Entry Section: Default(STYLE1) -->");
}
}
public String name;
public String email;
public String url;
public String city;
public String state;
public String country;
public String comments;
// time stamp to record the exact time this entry was created
private Date _timestamp;
}
|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
/**
* GuestbookEntry.java
* Pete Willemsen
* CoolServlets.com
* February 3, 2000
* Version 1.0.3
*
* Any errors or feature requests can be reported on CoolServlets.com.
* We hope you enjoy this program!
*
* Copyright (C) 2000 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
*/
package com.coolservlets.guestbook;
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
/**
* GuestbookEntry class
*
*/
public class GuestbookEntry implements Serializable {
public GuestbookEntry() {
_timestamp = new Date();
}
public Date timestamp() {
return _timestamp;
}
private String uriEmail() {
if (email.length() == 0)
return "";
else
return "<a href=\"mailto:" + email + "\">" + email + "";
}
private String uriUrl() {
if (url.length() == 0)
return "";
else
return "<a href=\"" + url + "\">" + url + "";
}
public void print( PrintWriter out, GuestbookStyle s, GuestbookFilter f ) {
SimpleDateFormat simple_date = new SimpleDateFormat();
simple_date.applyPattern("MMMM d, yyyy");
if ( s.type == GuestbookStyle.STYLE_1 ) {
out.println("<!-- Begin Entry Section: STYLE1 -->");
out.println("<B>" + simple_date.format( _timestamp ) + " ");
out.print(name);
if (email.length() != 0)
out.print(" <" + uriEmail() + ">");
if (name.length() != 0 || email.length() != 0)
out.println("<BR>");
out.println("<BR>");
out.println( f.filterBadwords( comments ) );
out.println("<HR>");
out.println("<!-- End Entry Section: STYLE1 -->");
}
else if ( s.type == GuestbookStyle.STYLE_2 ) {
out.println("<!-- Begin Entry Section: STYLE2 -->");
out.println("<B>" + simple_date.format( _timestamp ) + " ");
out.print(name);
if (city.length() != 0)
out.print(", " + city);
if (state.length() != 0)
out.print(", " + state);
if (country.length() != 0)
out.print(", " + country);
if (name.length() != 0 ||
city.length() != 0 ||
state.length() != 0 ||
country.length() != 0)
out.println("<BR>");
out.println("<BR>");
out.println( f.filterBadwords( comments ) );
out.println("<HR>");
out.println("<!-- End Entry Section: STYLE2 -->");
}
else if ( s.type == GuestbookStyle.STYLE_3 ) {
out.println("<!-- Begin Entry Section: STYLE3 -->");
out.println("<B>" + simple_date.format( _timestamp ) + " ");
out.print(name);
if (email.length() != 0)
out.print(" <" + uriEmail() + ">");
if (name.length() != 0 || email.length() != 0)
out.println("<BR>");
out.print( uriUrl() );
if (url.length() != 0)
out.println("<BR>");
out.println("<BR>");
out.println( f.filterBadwords( comments ) );
out.println("<HR>");
out.println("<!-- End Entry Section: STYLE3 -->");
}
else if ( s.type == GuestbookStyle.STYLE_4 ) {
out.println("<!-- Begin Entry Section: STYLE4 -->");
out.println("<table border=0>");
out.print("<tr> | ");
if (name.length() != 0)
out.print("Name:</td> | " + name);
else
out.print("Name:</td> | ");
if (email.length() != 0)
out.print(" <" + uriEmail() + ">");
out.println("</td> |
URL: | " + uriUrl() + " |
Comment: | " + f.filterBadwords( comments ) + " |