Vanilla Development Maling List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS update: web/servlets
Date: Monday March 8, 1999 @ 19:34
Author: tanner
Update of /home/netrek/cvsroot/web/servlets
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv7638
Modified Files:
HttpFormException.java MailingList.java MailingListNode.java
MailingListProperties.java MailingListServlet.java Makefile
MonthToNumber.java
Added Files:
announcements.txt copyright.txt
Removed Files:
MailingListHTML.java
Log Message:
Made everything Java1.1 compliant.
Lots of documentation. Still got lots to go.
Servlet is actually functional. Give it a try :-)
Added copyright.txt, this is what I use for the "banner" of each .java
file. Is this what we want in each file?
Added announcements.txt as a template for a future project. :-)
Remove MailingListHTML, servlet does these functions itself.
When we get our new Linux web server this servlet will go into
production.
****************************************
Index: web/servlets/HttpFormException.java
diff -u web/servlets/HttpFormException.java:1.1 web/servlets/HttpFormException.java:1.2
--- web/servlets/HttpFormException.java:1.1 Sat Feb 27 22:03:16 1999
+++ web/servlets/HttpFormException.java Mon Mar 8 19:34:57 1999
@@ -2,8 +2,7 @@
* Wrapper class around HTTP Status codes and JDK Exceptions.
*
* @author Bob Tanner
- * @version $Revision: 1.1 $ $Date: 1999/02/28 04:03:16 $
- * @since InstantSend1.0
+ * @version $Revision: 1.2 $ $Date: 1999/03/09 01:34:57 $
*/
public class HttpFormException extends Exception {
@@ -15,7 +14,6 @@
* @param sc the status code.
* @param message the Exception message.
* @see Exception
- * @since InstantSend1.0
*/
public HttpFormException(int sc, String message) {
this.sc = sc;
@@ -27,7 +25,6 @@
* Returns the message of the Exception.
*
* @return the exception message
- * @since InstantSend1.0
*/
public String getMessage() {
return message;
@@ -38,7 +35,6 @@
* Returns the status code of the Exception.
*
* @return the http status code
- * @since InstantSend1.0
*/
public int getSC() {
return sc;
Index: web/servlets/MailingList.java
diff -u web/servlets/MailingList.java:1.2 web/servlets/MailingList.java:1.3
--- web/servlets/MailingList.java:1.2 Sat Feb 27 23:41:32 1999
+++ web/servlets/MailingList.java Mon Mar 8 19:34:57 1999
@@ -1,6 +1,36 @@
+/*
+ * Copyright (c) 1999 Real Time Enterprises, Inc. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY REAL TIME ENTERPRISES, INC. "AS IS" AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REAL TIME ENTERPRISES INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
import java.io.*;
import java.util.Vector;
+/*
+ *
+ * @author Bob Tanner
+ * @version $Revision: 1.3 $ $Date: 1999/03/09 01:34:57 $
+ * @since MailingList1.0
+ */
+
public class MailingList {
public static void main(String[] argv) {
@@ -10,14 +40,14 @@
for (int j = 0; j < archive.size(); j++) {
MailingListNode node = (MailingListNode)archive.elementAt(j);
- System.out.println(node.getYear());
+ System.err.println(node.getYear());
String[] months = node.getMonths();
for (int i = 0; i < MailingListNode.MAX_MONTH; i++) {
if (months[i] != null) {
- System.out.println(months[i]);
+ System.err.println(months[i]);
}
}
- System.out.println();
+ System.err.println();
}
}
@@ -38,8 +68,18 @@
for (int year = 0; year < years.length; year++) {
MailingListNode node = new MailingListNode();
- System.out.println(years.length+" Years "+years[year].getName());
node.setYear(years[year].getName());
+
+ // This is a hack so I could incorporate the old archives before the
+ // YYYY/mmm directory structure was implemented. Put all your old archive
+ // files into Attic/All and this should work.
+
+ if (years[year].getName().equalsIgnoreCase("attic") == true) {
+ node.setMonth(0, "All");
+ list.insertElementAt(node, year);
+ break;
+ }
+
String[] months = years[year].list();
sorted_months = sortMonths(months);
for (int month = 0; month < MailingListNode.MAX_MONTH; month++) {
@@ -53,33 +93,76 @@
}
}
- /* This has a 10 year limitation! Hopefully Java2 will be ported to Linux by
- then */
+ /**
+ * Similates the Java2 API <a href="http://java.sun.com/products/jdk/1.2/docs/api/java/io/File.html#listFiles()>listFiles()</a>. <p>
+ * Returns an array of abstract pathnames denoting the files in the directory
+ * denoted by this abstract pathname.
+ * If this abstract pathname does not denote a directory, then this method returns
+ * null. Otherwise an array of File objects is returned, one for each file or
+ * directory in the directory. Pathnames denoting the directory itself and the
+ * directory's parent directory are not included in the result. Each resulting
+ * abstract pathname is constructed from this abstract pathname using the
+ * File(File, String) constructor. <p>
+ * Therefore if this pathname is absolute then each resulting pathname is
+ * absolute; if this pathname is relative then each resulting pathname will be
+ * relative to the same directory. <p>
+ * There is no guarantee that the name strings in the resulting array will
+ * appear in any specific order; they are not, in particular, guaranteed to
+ * appear in alphabetical order.<p>
+ * This has a 10 year limitation (limited by hardcoded array size)! Hopefully
+ * Java2 will be ported to Linux in the next 10 years.
+ *
+ * @param Pathname to the directory to look in
+ * @return An array of abstract pathnames denoting the files and
+ * directories in the directory denoted by this abstract pathname. The array
+ * will be empty if the directory is empty. Returns null if this abstract
+ * pathname does not denote a directory, or if an I/O error occurs.
+ */
public File[] listFiles(String pathname) {
- System.out.println("Pathname "+pathname);
+ // System.out.println("listFiles Pathname "+pathname);
File parent = new File(pathname);
- File[] temp_months = new File[10];
+
+ // If the parent is not a directory return null
+ if (!parent.isDirectory()) {
+ return null;
+ }
+
+ // Hardcoded(!) limitation
+ File[] temp_years = new File[10];
+
+ // Get all the files listed in the parent directory
String[] all_files = parent.list();
int temp_count = 0;
-
- for (int i = 0; i < all_files.length; i++) {
+
+ // Walk through the listing of all the files picking out only the
+ // directories and saving them in another array
+ for (int i = 0; i < all_files.length; i++) {
File test = new File(getParent()+"/"+all_files[i]);
if (test.isDirectory() == true) {
- System.out.println("directory "+getParent()+"/"+all_files[i]);
- temp_months[i] = new File(getParent()+"/"+all_files[i]);
+ temp_years[i] = new File(getParent()+"/"+all_files[i]);
temp_count++;
}
}
- File[] months = new File[temp_count];
+ // For each directory found, create a File object and save that for return
+ // to the caller.
+ File[] years = new File[temp_count];
for (int i = 0; i < temp_count; i++) {
- months[i] = temp_months[i];
+ years[i] = temp_years[i];
}
- return months;
+ return years;
}
-
+
+ /**
+ * Sorts the months numerically from Jan (first month) to Dec (twelfth month).
+ *
+ * @param months array of strings representing the months using the mmm format
+ * @return an array of strings representing months sorted numerically
+ */
public String[] sortMonths(String[] months) {
String[] sorted_months = new String[MailingListNode.MAX_MONTH];
+
+ // Use colaterally crossed arrays to do the sorting
for (int i = 0; i < months.length; i++) {
sorted_months[numbers.convertIntValue(months[i])-1] = months[i];
@@ -87,13 +170,23 @@
return sorted_months;
}
+ /**
+ * Sets the pathname to the parent directory of the mailing list.
+ *
+ * @param pathname the pathname of the parent directory
+ */
public void setParent(String pathname) {
parent = pathname;
}
+ /**
+ * Returns the pathname to the parent directory of the mailing list files.
+ *
+ * @return the pathname to the parent directory
+ */
public String getParent()
{
- return parent;
+ return parent;
}
private String parent;
Index: web/servlets/MailingListNode.java
diff -u web/servlets/MailingListNode.java:1.1 web/servlets/MailingListNode.java:1.2
--- web/servlets/MailingListNode.java:1.1 Sat Feb 27 22:03:16 1999
+++ web/servlets/MailingListNode.java Mon Mar 8 19:34:57 1999
@@ -1,40 +1,99 @@
+/*
+ * Copyright (c) 1999 Real Time Enterprises, Inc. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY REAL TIME ENTERPRISES, INC. "AS IS" AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REAL TIME ENTERPRISES INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/**
+ *
+ * @author Bob Tanner
+ * @version $Revision: 1.2 $ $Date: 1999/03/09 01:34:57 $
+ */
+
public class MailingListNode {
+ /**
+ * Number of months in a year.
+ */
public static final int MAX_MONTH = 12;
+ /**
+ * Construct a MailListNode.
+ */
public MailingListNode() {
months = new String[MAX_MONTH];
}
+ /**
+ *
+ * @param value the year as an String
+ */
public void setYear(String value) {
- setYear(new Integer(value));
+ year = value;
}
+ /**
+ *
+ * @param value the year as an Integer
+ */
public void setYear(Integer value) {
- year = value;
+ setYear(value.toString());
}
- public void setYear(int value) {
- setYear(new Integer(value));
- }
-
+ /**
+ *
+ * @param index the month as a number
+ * @param value the months as a String
+ */
public void setMonth(int index, String value) {
// Check range.
months[index] = value;
}
- public Integer getYear() {
+ /**
+ *
+ * @return the year as a String
+ */
+ public String getYear() {
return year;
}
+ /**
+ *
+ * @param index the month as a number
+ * @return the month as a String
+ */
public String getMonth(int index) {
+ // Check bounds
return months[index];
}
+ /**
+ *
+ * @return an array of months as Strings, collaterally cross referenced
+ */
public String[] getMonths() {
return months;
}
- private Integer year;
+ private String year;
private String[] months;
}
Index: web/servlets/MailingListProperties.java
diff -u web/servlets/MailingListProperties.java:1.1 web/servlets/MailingListProperties.java:1.2
--- web/servlets/MailingListProperties.java:1.1 Sat Feb 27 22:03:16 1999
+++ web/servlets/MailingListProperties.java Mon Mar 8 19:34:58 1999
@@ -1,13 +1,36 @@
+/*
+ * Copyright (c) 1999 Real Time Enterprises, Inc. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY REAL TIME ENTERPRISES, INC. "AS IS" AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REAL TIME ENTERPRISES INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
import java.io.*;
import java.util.Properties;
/**
- * MailingListProperties provides and interface for default
- * attributes that reside in a FileInputStream (flat file).
+ * MailingListProperties provides and interface for default attributes that
+ * reside in a FileInputStream (flat file). I took this from another
+ * project. Lots of clean up here. But it works for now.
*
* @author Bob Tanner
- * @version $Revision: 1.1 $ $Date: 1999/02/28 04:03:16 $
- * @since MailingList1.0
+ * @version $Revision: 1.2 $ $Date: 1999/03/09 01:34:58 $
*/
public class MailingListProperties extends Properties{
@@ -23,7 +46,6 @@
* @see Properties
* @see FileNotFoundException
* @see IOException
- * @since MailingList1.0
*/
public MailingListProperties(String filename) throws
@@ -49,7 +71,6 @@
* Returns the full pathname to the default propertoies file
*
* @return the full pathname to the default properties file
- * @since MailingList1.0
*/
public String getDefPath() {
return defPath;
@@ -59,7 +80,6 @@
* Sets the full pathname to the default properties file
*
* @param value the full pathname to the default properties file
- * @since MailingList1.0
*/
public void setDefPath(String value) {
defPath = value;
Index: web/servlets/MailingListServlet.java
diff -u web/servlets/MailingListServlet.java:1.2 web/servlets/MailingListServlet.java:1.3
--- web/servlets/MailingListServlet.java:1.2 Sat Feb 27 23:41:32 1999
+++ web/servlets/MailingListServlet.java Mon Mar 8 19:34:58 1999
@@ -1,6 +1,26 @@
/*
- */
-
+ * Copyright (c) 1999 Real Time Enterprises, Inc. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY REAL TIME ENTERPRISES, INC. "AS IS" AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REAL TIME ENTERPRISES INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
import java.io.*;
import java.util.Vector;
import java.util.PropertyResourceBundle;
@@ -8,54 +28,74 @@
import javax.servlet.*;
/**
- * MailingListSevlet can be used to send a restricted set of files to a
- * restricted hostname or IP address using a secure protocol
- * <a href="http://www.ssh.fi/sshprotocols2/index.html">(ssh)</a>.
- * By default MailingListServlet only sends files that have changed AND only
- * the changed parts of those files. After a successful run of
- * MailingList the destination directory will be an exact match of
- * the source directory. <p>
- *
- * <b>WARNING!</b> If you delete files in the source directory
- * MailingList will delete those same files in the destination
- * directory. <p>
- *
- * MailingList works on all files, including binary files. <p>
- *
- * It can be run via a web interface
- * <a href="http://java.sun.com/products/servlet/index.html">(servlet)</a>,
- * on a command line or automatically via cron. <p>
+ * MailingListSevlet will dynamically generate html for display on the
+ * web for directories that follow the YYYY/mmm format. Perfect for
+ * displaying archived mail messages from your favorite mailing
+ * list.<p>
+ *
+ * The directory structure <b>MUST</b> follow the YYYY/mmm format or these
+ * servlet will throw an exception. <p>
*
+ * Parent directory is /usr/local/tmp/vanilla. A long listing of
+ * /usr/local/tmp/vanilla looks like this:
+ *
+ * <pre>
+ * drwxr-xr-x 14 tanner users 512 Mar 3 18:01 1999/
+ * drwxr-xr-x 10 tanner users 512 Mar 3 18:01 2000/
+ * drwxr-xr-x 4 tanner users 512 Mar 3 18:01 2001/
+ * drwxr-xr-x 2 tanner users 512 Mar 3 18:01 Attic/
+ * </pre>
+ *
+ * Drilling down into the 1999 directory a long listing looks like
+ * this:
+ *
+ * <pre>
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Apr/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Aug/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Dec/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:58 Feb/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:58 Jan/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Jul/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Jun/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:58 Mar/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 May/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Nov/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Oct/
+ * drwxr-xr-x 2 tanner users 512 Feb 23 18:59 Sep/
+ * </pre>
+ *
* @author Bob Tanner
- * @version $Revision: 1.2 $ $Date: 1999/02/28 05:41:32 $
- * @since MailingList1.0
+ * @version $Revision: 1.3 $ $Date: 1999/03/09 01:34:58 $
*/
public class MailingListServlet extends HttpServlet {
+ /**
+ * The location of the properties file. Should probably make a
+ * seperate class for this stuff.
+ */
public static final String PROPERTIES = "/usr/local/tmp/web/servlets/MailingList.properties";
+
+ /**
+ * The location of the resource bundle file. Should probably make a
+ * seperate class for this stuff.
+ */
public static final String RESOURCES = "/usr/local/tmp/web/servlets/MailingListBundle.properties";
/**
* Reads 2 properties files, 1 for operation parameter defaults and
- * the other for i18n messages.
- * This will allow you to change the operation parameter properties
- * file and not have to re-compile to change the behavior of
- * MailingListServlet.<p>
+ * the other for i18n messages. This will allow you to change the operation
+ * parameter properties file and not have to re-compile to change the
+ * behavior of MailingListServlet.<p>
*
* We also read in the i18n and l10n ResourceBundles. Not because
* this application is International, but so we can change the
- * displayed status messages without having to
- * have 2 different applications.<p>
+ * displayed status messages without having to recompile.<p>
*
- * <b>WARNING!</b> InstandSend the command-line application shares the
- * operation parameter defaults and the ResourceBundle property file
- * with this application. Changes to the properties file will effect
- * BOTH programs.
*
* @param config Servlet configuration
*
- * @throws ServletException if the servlet cannot be
+ * @exception ServletException if the servlet cannot be
* initialized cannot handle the expection with
* anything more specific
* @see SevletException
@@ -66,6 +106,11 @@
super.init(config);
try {
+ sm = new MailingListSecurityManager();
+ System.setSecurityManager(sm);
+ /*
+ I have this shutoff for debugging
+
defProp = new MailingListProperties(PROPERTIES);
FileInputStream stream = new FileInputStream(RESOURCES);
defMsg = new PropertyResourceBundle(stream);
@@ -74,6 +119,9 @@
throw new ServletException("File Not Found: "+e.getMessage());
} catch (IOException e) {
throw new ServletException(e.getMessage());
+ */
+ } catch (SecurityException e) {
+ System.err.println("SecurityManager already set");
}
}
@@ -82,14 +130,14 @@
* around the <code>doPost()</code> method.
*
* @param req HttpServletRequest that encapsulates the request to the
- * servlet.
+ * servlet.
* @param res HttpServletResponse that encapsulates the response from
- * the servlet.
+ * the servlet.
* @exception ServletException if the request could not be handled
* @exception IOException if detected when handling the request
* @see ServletException
* @see IOException
- * @since MailingList1.0
+ * @since MailingList1.0
*/
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
@@ -97,21 +145,20 @@
}
/**
- * Process the HTTP POST request.
- * Get the POST request parameters user and password. Verifies they
- * are actually in the request and have assigned values. If all
- * criteria are met, start the mirroring process and update the user
- * as the files are successfully mirrored.
+ * Process the HTTP POST request. Get the POST request parameters, verify
+ * they are actually in the request and have assigned values. If all criteria
+ * are met, read the parent directory for YYYY/mmm directory pairs and
+ * display them.
*
* @param req HttpServletRequest that encapsulates the request to the
- * servlet.
+ * servlet.
* @param res HttpServletResponse that encapsulates the response from
- * the servlet.
+ * the servlet.
* @exception IOException if detected when handling the request
* @exception ServletException if the request could not be handled
- * @see ServletException
- * @see IOException
- * @since MailingList1.0
+ * @see ServletException
+ * @see IOException
+ * @since MailingList1.0
*/
public void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException {
@@ -119,26 +166,52 @@
String[] pathname;
String[] baseurl;
String[] listname;
-
+ String doc_root = req.getRealPath("/");
+
+ sm.setDocRoot(doc_root);
+ // System.err.println("Root "+sm.getDocRoot());
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/html");
try {
+ // Required parameters. Should generalize this, so we can do optional and
+ // well as required parameters.
+
pathname = getParameter(req, "pathname");
+ sm.setPathname(pathname[0]);
+ // System.err.println("Servlet setPathname");
+
baseurl = getParameter(req, "baseurl");
listname = getParameter(req, "listname");
-
+
+ // Java2 has a linked-list, but had to go with a Vector for Java1
+ // compatibilty.
+
Vector archive = new Vector();
MailingList list = new MailingList(archive);
+
+ // Walk the directory hierarchy of pathname, looking for YYYY/mmm
+ // directory pairs and save them in a link-list (Vector for Java1
+ // compatibility).
+
list.DirectoryToLinkedList(pathname[0]);
+
out.println("<html><head><title>Testing</title><body>");
for (int j = 0; j < archive.size(); j++) {
+
+ // For each node in the list, get the year and display it in bold on a
+ // line by itself.
+
MailingListNode node = (MailingListNode)archive.elementAt(j);
out.println("<b>"+node.getYear()+"</b><br>");
String[] months = node.getMonths();
+ // For each year there is 12 months. Walk the month array display each
+ // month found in the YYYY/mmm directory pairs. If a month element is
+ // NULL then there is no directory for that YYYY/mmm pair.
+
for (int i = 0; i < MailingListNode.MAX_MONTH; i++) {
if (months[i] != null) {
out.print("<a href=\""+baseurl[0]+"/"+listname[0]+"/"+node.getYear()+"/"+months[i]+"\">"+months[i]+"</a>\n");
@@ -147,17 +220,28 @@
out.println("<p>");
}
out.println("</body></html>");
- out.println("getPathinfo "+req.getPathInfo()+"<p>");
- out.println("getPathTranslated "+req.getPathTranslated()+"<p>");
- out.println("getServletPath "+req.getServletPath()+"<p>");
- out.println("getRealPath "+req.getRealPath("/")+"<p>");
-
} catch (HttpFormException e) {
res.sendError(e.getSC(), e.getMessage());
out.flush();
}
}
+ /**
+ * Returns the value of a required parameter from the httpd request.
+ * This method should be named something like getRequiredParameter()
+ * because if the request value is not found in the httpd request it
+ * will throw a HttpFormException, which is not what should happen
+ * if the parameter is optional.
+ *
+ * @param req HttpServletRequest that encapsulates the request to the
+ * servlet.
+ * @param value String of the parameter we are looking for inside
+ * the request
+ * @exception HttpFormException if a parameters is not found in the
+ * request or the parameter is blank/null
+ * @return the value of the parameters found in the request
+ * @since MailingList1.0
+ */
public String[] getParameter(HttpServletRequest req, String value) throws HttpFormException {
String[] parameters;
@@ -184,6 +268,7 @@
return "MailListServlet";
}
+ private MailingListSecurityManager sm;
private MailingListProperties defProp;
private PropertyResourceBundle defMsg;
}
Index: web/servlets/Makefile
diff -u web/servlets/Makefile:1.2 web/servlets/Makefile:1.3
--- web/servlets/Makefile:1.2 Sat Feb 27 23:41:32 1999
+++ web/servlets/Makefile Mon Mar 8 19:34:58 1999
@@ -5,24 +5,31 @@
JAVACFLAGS=-g -deprecation -d .
JAVACOMPILE=CLASSPATH=${CLASSPATH}:. $(JAVAC) $(JAVACFLAGS)
-JAVA_SOURCES=MonthToNumber.java MailingListProperties.java HttpFormException.java \
- MailingListNode.java \
+JAVA_SOURCES=MonthToNumber.java MailingListProperties.java \
+ HttpFormException.java MailingListNode.java \
+ MailingListSecurityManager.java \
-CLASSFILES=*.class
+CLASSFILES=MonthToNumber.class MailingListProperties.class \
+ HttpFormException.class MailingListNode.class \
+ MailingListSecurityManager.class \
-all:: MailingList.class MailingListServlet.class
+%.class: %.java
+ CLASSPATH=${CLASSPATH}:. $(JAVAC) $(JAVACFLAGS) $<
-MailingList.class: MailingList.java $(JAVA_SOURCES)
- $(JAVACOMPILE) $(JAVA_SOURCES)
+all:: MailingList MailingListServlet
-MailingListServlet.class: MailingListServlet.java $(JAVA_SOURCES)
- $(JAVACOMPILE) MailingListServlet.java
+MailingList: MailingList.class $(CLASSFILES)
+ CLASSPATH=${CLASSPATH}:. $(JAVAC) $(JAVACFLAGS) MailingList.java
+MailingListServlet: MailingListServlet.class $(CLASSFILES)
+ CLASSPATH=${CLASSPATH}:. $(JAVAC) $(JAVACFLAGS) MailingListServlet.java
+
install:
install
docs::
- javadoc -version -author -d docs $(JAVA_SOURCES)
+ javadoc -version -author -d docs $(JAVA_SOURCES) MailingListServlet.java \
+ MailingList.java
jar::
$(JAR) $(JARFLAGS) MailingList.jar $(CLASSFILES)
Index: web/servlets/MonthToNumber.java
diff -u web/servlets/MonthToNumber.java:1.1 web/servlets/MonthToNumber.java:1.2
--- web/servlets/MonthToNumber.java:1.1 Sat Feb 27 22:03:17 1999
+++ web/servlets/MonthToNumber.java Mon Mar 8 19:34:58 1999
@@ -1,7 +1,48 @@
+/*
+ * Copyright (c) 1999 Real Time Enterprises, Inc. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY REAL TIME ENTERPRISES, INC. "AS IS" AND
+ * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL REAL TIME ENTERPRISES INC.
+ * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
import java.util.Hashtable;
+/**
+ * MonthToNumber provides a simple way of converting a month as a
+ * string in mmm format to the corresponding month as a number. <p>
+ *
+ * Code is quick hack. I think there should be a way to do this with
+ * the Calendar class, but I did not investigate it all that much.<p>
+ *
+ * Should add code to range check the numbers.
+ *
+ * @author Bob Tanner
+ * @version $Revision: 1.2 $ $Date: 1999/03/09 01:34:58 $
+ */
+
public class MonthToNumber {
+ /**
+ * Contructs MonthToNumber object. Might think about making this a
+ * static object.
+ */
+
public MonthToNumber() {
numbers = new Hashtable();
numbers.put("Jan", new Integer(1));
@@ -18,12 +59,27 @@
numbers.put("Dec", new Integer(12));
}
- public int convertIntValue(String name) {
- return convertIntegerValue(name).intValue();
+ /**
+ * Converts a month name in mmm format to the corresponding month
+ * number (Jan = 1, Dec = 12) as an integer.
+ *
+ * @param month the month name as a string
+ * @return the month as a primitive type int
+ */
+ public int convertIntValue(String month) {
+ return convertIntegerValue(month).intValue();
}
- public Integer convertIntegerValue(String name) {
- return (Integer)numbers.get(name);
+ /**
+ * Converts a month name in mmm format to the corresponding month
+ * number (Jan = 1, Dec = 12) as an Integer class.
+ *
+ * @param month the month as a string
+ * @return the month as an Integer class
+ */
+ public Integer convertIntegerValue(String month) {
+ return (Integer)numbers.get(month);
}
+
private Hashtable numbers;
}