Yet another implementation of remote publishing. This is a Java servlets based implementation of news forum or blog. Forum is a collection of messages. Each message has got short announce (subject) and body. News servlet supports WAP/WML also. So you may use this servlet in your portal for example as a common source of news information for desktop and mobile clients.
NewsServlet supports file based persistence - your data will be saved in the flat file (files) or database based persistence. See below how to define this option.
How to use it:
a) copy newsPackage.jar into your WEB-INF/lib directory.
b) define NewsServlet in your web.xml file:
c) define a mapping:
For each your forum you must provide a configuration file describes how to save messages as well as various interface settings. You can use NewsServlet in two forms.
1) pass configuration file as a parameter. E.g.:
2) define your configuration file as an initial parameter for servlet
(parameter name is config):
and use servlet in this form: http://your_host/servlet/NewsServlet
Configuration file is a text file, each line describes one parameter in the form of
parameter=value
Empty lines and any line starts with # or // are ignored.
Current version supports the following list of parameters:
# data persistence
#
# base directory, this parameter must be set in case of
# file based persistence. Points to any existing directory
# on your server.
dir=your_directory
#
# JDBC settings. You must set this in case db-based persistence
# Options are: (JDBC driver, database URL) pair or JNDI datasource
# JDBC driver
driver=your_jdbc_driver
# database URL
url=your_db_url
# JNDI name (instead of the above mentioned pair)
jndiname=your_data_source
# Optional parameter: user name for JDBC connection.
user=db_user
# Optional parameter: password for JDBC connection.
password=db_user's_password
# name of the table
table=your_db_table
# See below DDL description for this table
# how to show full message: call server or use client side functionality
# possible values are server (default value) or client
runat=server
# Interface
# forum title (default value is Coldjava's news)
title=My news
# background (default value is #FFFFFF)
bgcolor=your_color
# foreground color (default value is #000000)
fgcolor=#000000
# foreground color for subjects (default value is #008000)
fgcolor1=#008000
# foreground color for messages (default value is #000000)
fgcolor2=#000000
#font size (by default is current browser's font)
size=your_size
#font face (by default is current browser's font)
face=your_font_face
# sort data: 0 - first to last, 1 - last to first (default
value is 1)
sort=1
# refresh time in seconds (default value is 600)
refresh=your_time
# enable/disable post messages. By default this parameter is empty
# and posting is enabled for everyone.
# You can provide here a commas separated list of roles for users allowed
# to post data
post=list_of_roles
# page size in messages (default value is 10)
page=8
# enable/disable html codes in messages. 1- enable, 0 - disable. (default
value is 0)
html=0
# header. You can set here some file contains any html-code. This code
will be
# outputted at the beginning of the each page. So you can set for example
some banners or CSS styles.
# By default this value is empty
header=path_to_your_file
# footer. You can set here some file contains any html-code. This code
will be
# outputted at the bottom of the each page. So you can set for example
some banners.
# By default this value is empty
footer=path_to_your_file
# admin password. Default value is welcome
admin=your_word
# localization support. You can set character encoding for input parameters
# here. Default value is ISO-8859-1
encoding=Cp1251
More about database persistence
All data will be saved in the one table. Name of this table is included
in your configuration file (table=your_table). So if you support several
stores each of them has got own table (probably in the same database).
Table must be created before the first use of servlet with the appropriate
configuration file. Use your database admin tools for doing this. Here
is a DDL statement for this table:
CREATE TABLE your_table_name (
Id CHAR(30) PRIMARY KEY,
Moment CHAR(14),
Subject LONG VARCHAR,
Msg LONG VARCHAR);
You must use the same names for columns but depends on your database you can change types for columns (Msg and Subject). These columns (domains) will keep text data for individual messages. You may decide to use TEXT for example. Check out your DB manual for supported SQL data types.
Domain Moment will keep time stamp for messages (in milliseconds). We used type CHAR just for compatibility with JDBC-ODBC bridges (where the usage of any another type is one big bug). You may also change types from CHAR to VARCHAR.
You can manage by your message store running the same servlet in the
so called Administrative mode. Here you can for example delete your messages.
Appropriate command is:
http://your_host/servlet/NewsServlet?config=your_config_file&admin=yes
or for example for historical data (one day ago):
http://your_host/servlet/NewsServlet?config=your_config_file&date=1&admin=yes
See above for admin settings in the configuration file.
Notes:
1. You can save configuration file in the any place on your server.
Just use the proper path for setting servlet's parameter. Short path (just
name of the file) means that your configuration file is saved under servletrunner's
root directory. But you can always use some like this:
http://your_host/servlet/NewsServlet?c:\myfiles\config.txt
2. Also the base directory for messages store can be created at the any place of your server (just check access rights).
3. You can use the same servlet for access to the history data. For
example one day ago data:
http://your_host/servlet/NewsServlet?config=your_config&date=1
two days ago:
http://your_host/servlet/NewsServlet?config=your_config&date=2
etc. Or you can set the date directly (date format is yyyymmdd.
E.g. June 05 2000 is 20000605):
http://your_host/servlet/NewsServlet?config=your_config&date=20000605
4. For database persistence make sure you add your JDBC driver to CLASSPATH.
5. Evaluation version lets you see the first two pages only.
For downloading: newsPackage.jar
Sample of config file: newsconf
See also JSOS - the largest collection of servlets and filters.