package org.gjt.bugrat.servlet;
import java.io.*;
import java.util.*;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.MessagingException;
import org.gjt.bugrat.db.*;
import org.gjt.bugrat.dbi.*;
import org.gjt.bugrat.dbi.*;
//EnhancedMimeMsg;
import org.gjt.bugrat.mail.StringDataSource;
public
class BugRatReport
extends BugRatServlet
{
public String
getServletInfo()
{
return "BugRat - Report servlet, version "
+ this.getVersionStr() + " by Tim Endres.";
}
public void
init( ServletConfig config )
throws ServletException
{
super.init( config );
}
public void
doGet( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException
{
BugRatRequest bReq = new BugRatRequest( req, res, this );
String pathInfo = bReq.getPathInfo();
if ( this.commonGet( bReq ) )
{
// Handled by the common GET code...
}
else if ( pathInfo == null || pathInfo.equals( "/" ))
{
// UNDONE - main menu? For now, sends Report Form
String action = bReq.getServletPath() + "/PostReport";
String hiddens =
"<INPUT type=\"hidden\" name=\"srcid\" value=\"0\">" +
"<INPUT type=\"hidden\" name=\"source\" value=\"W\">";
this.sendReportForm
( bReq, action, hiddens, null, null, false );
}
else if ( pathInfo.equalsIgnoreCase( "/ReportForm" ) )
{
String action = bReq.getServletPath() + "/PostReport";
String hiddens =
"<INPUT type=\"hidden\" name=\"srcid\" value=\"0\">" +
"<INPUT type=\"hidden\" name=\"source\" value=\"W\">";
this.sendReportForm
( bReq, action, hiddens, null, null, false );
}
else if ( pathInfo.equalsIgnoreCase( "/SelectPro" ) )
{
this.sendProjectForm( bReq );
}
else if ( pathInfo.startsWith( "/SelectCat/" ) )
{
String project =
pathInfo.substring( "/SelectCat/".length() );
if ( project.length() > 0 )
{
this.sendCategoryForm( bReq, project );
}
else
{
// UNDONE error handling...
}
}
else if ( pathInfo.startsWith( "/SelectSub/" ) )
{
String subPath =
pathInfo.substring( "/SelectSub/".length() );
int idx = subPath.indexOf( "/" );
String project = subPath.substring( 0, idx );
String category = subPath.substring( idx + 1 );
if ( project.length() > 0 && category.length() > 0 )
{
this.sendSubReportForm( bReq, project, category );
}
else
{
// UNDONE error handling...
}
}
else if ( pathInfo.equalsIgnoreCase( "/Help" )
|| pathInfo.equalsIgnoreCase( "/Help.html" ) )
{
this.sendHelpPage( bReq );
}
else if ( pathInfo.equalsIgnoreCase( "/HelpFields" )
|| pathInfo.equalsIgnoreCase( "/HelpFields.html" ) )
{
this.sendFieldsHelpPage( bReq );
}
else if ( pathInfo.equalsIgnoreCase( "/index" ) )
{
this.sendHelpPage( bReq );
}
else
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Error Unknown Command" );
this.reportError( bReq, cW,
"<h2>Request Not Recognized</h2>" +
"The request that you submitted <strong>'" +
pathInfo + "'</strong> was not recognized. " +
"This indicates that the link you followed " +
"is not valid. You might wish to notify the " +
"webmaster of the problem." );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
}
/**
* Write survey results to output file in response to the POSTed
* form. Write a "thank you" to the client.
*/
public void
doPost( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException
{
BugRatRequest bReq = new BugRatRequest( req, res, this );
String pathInfo = bReq.getPathInfo();
if ( pathInfo == null )
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - invalid PathInfo" );
this.reportError( bReq, cW,
"<h2>ERROR PathInfo Null</h2>" +
"The pathinfo data in the request was empty." );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
else if ( this.commonPost( bReq ) )
{
// Handled by the common GET code...
}
else if ( pathInfo.equalsIgnoreCase( "/SelectCat" ) )
{
String project = bReq.getParameterValues( "project" )[0];
// UNDONE proper error checking...
this.sendCategoryForm( bReq, project );
}
else if ( pathInfo.equalsIgnoreCase( "/SelectSub" ) )
{
String project = bReq.getParameterValues( "project" )[0];
String category = bReq.getParameterValues( "category" )[0];
// UNDONE proper error checking...
this.sendSubReportForm( bReq, project, category );
}
else if ( pathInfo.equalsIgnoreCase( "/PostSelect" ) )
{
this.processReportPOST( bReq, true );
}
else if ( pathInfo.equalsIgnoreCase( "/PostReport" ) )
{
this.processReportPOST( bReq, false );
}
else
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - invalid PathInfo" );
this.reportError( bReq, cW,
"<h2>ERROR PathInfo Invalid</h2>" +
"The pathinfo of '" + pathInfo + "' was not recognized." );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
}
private void
sendReportForm(
BugRatRequest bReq,
String action, String hiddens,
String project, String category, boolean haveProject )
throws IOException
{
Vector lpV = null;
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Bug Report Form" );
DBConfig config = this.getDBConfig();
String bgColor = config.getProperty( "reportServlet.bgColor" );
if ( bgColor == null ) bgColor = "#E0E0E0";
String hdrColor = config.getProperty( "reportServlet.hdrColor" );
if ( hdrColor == null ) hdrColor = bgColor;
String reqColor = config.getProperty( "reportServlet.reqColor" );
if ( reqColor == null ) bgColor = "#B0E0B0";
boolean newAccountRequiresAdmin = this.getNewUserRequiresAdmin();
// config.getBoolean
// ( "commonServlet.newPersonRequiresAdmin", true );
cW.print ( "<form method=\"POST\"" );
cW.println( " action=\"" + action + "\">" );
cW.println( hiddens );
if ( haveProject )
{
cW.println( "<INPUT type=\"hidden\" name=\"project\" " );
cW.println( " value=\"" + project + "\">" );
cW.println( "<INPUT type=\"hidden\" name=\"category\" " );
cW.println( " value=\"" + category + "\">" );
}
cW.println( "<table width=\"100%\" border=\"3\" cellpadding=\"0\">" );
cW.println( "<tr>" );
cW.print ( "<td align=\"center\" valign=\"top\" colspan=\"2\"" );
cW.println( " width=\"100%\" bgcolor=\"" + hdrColor + "\">" );
this.getOutput().sendTableTitle
( bReq, cW, "Submit Bug Report" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.print ( "<td align=\"center\" width=\"50%\" valign=\"top\"" );
cW.println( " bgcolor=\"" + reqColor + "\">" );
if ( haveProject )
{
String projectName = config.getProjectName( project );
String categoryName = config.getCategoryName( project, category );
cW.println( "<table border=\"0\" width=\"80%\" cellpadding=\"3\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "<strong>" );
cW.println( "Project:" );
cW.println( "</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( projectName );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "<strong>" );
cW.println( "Category:" );
cW.println( "</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( categoryName );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "<hr>" );
cW.println( "<strong>" );
cW.println( "SubCategory" );
cW.println( "</strong>" );
cW.println( "<br>" );
cW.println( "<SELECT NAME=\"subcat\" SIZE=8>" );
Vector subcats =
config.getCategorySubCats( project, category );
for ( int i = 0, sz = subcats.size() ; i < sz ; ++i )
{
Category pc = (Category) subcats.elementAt(i);
String cat = pc.getSubCategory();
String catName = pc.getName();
cW.println( "<OPTION VALUE=\"" + cat + "\">" );
cW.println( catName );
cW.println( "</OPTION>" );
}
cW.println( "</SELECT>" );
}
else
{
cW.println( "<strong>" );
cW.println( "Project / Category / SubCategory" );
cW.println( "</strong>" );
cW.println( "<br>" );
cW.println( "<SELECT NAME=\"pcs\" SIZE=12>" );
Vector projects = config.getProjects();
for ( int pi = 0, psz = projects.size() ; pi < psz ; ++pi )
{
Category pc = (Category) projects.elementAt(pi);
String proj = pc.getProject();
String projectName = pc.getName();
Vector categories = config.getProjectCategories( proj );
if ( pi > 0 )
cW.println( "<OPTION VALUE=\"SEP\"> --- </OPTION>" );
for ( int ci = 0, csz = categories.size() ; ci < csz ; ++ci )
{
Category cc = (Category) categories.elementAt(ci);
String cat = cc.getCategory();
String categoryName = cc.getName();
Vector subcats = config.getCategorySubCats( proj, cat );
for ( int si = 0, ssz = subcats.size() ; si < ssz ; ++si )
{
Category sc = (Category) subcats.elementAt(si);
String value =
sc.getProject() + "/" +
sc.getCategory() + "/" +
sc.getSubCategory();
String name =
projectName + " / " +
categoryName + " / " +
sc.getName();
cW.println( "<OPTION VALUE=\"" + value + "\">" );
cW.println( name );
cW.println( "</OPTION>" );
}
}
}
cW.println( "</SELECT>" );
}
cW.println( "</td>" );
cW.println( "<td align=\"center\" width=\"50%\">" );
cW.println( "<table bgcolor=\"" + reqColor + "\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Priority" );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.println( "<SELECT NAME=\"priority\" SIZE=\"1\">" );
lpV = config.getPriorities();
for ( int i = 0, sz = lpV.size() ; i < sz ; ++i )
{
LevelParam lp = (LevelParam) lpV.elementAt(i);
cW.println( "<OPTION VALUE=\"" + lp.getId() + "\">" );
cW.println( lp.getName() );
cW.println( "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Severity" );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.println( "<SELECT NAME=\"severity\" SIZE=\"1\">" );
lpV = config.getSeverities();
for ( int i = 0, sz = lpV.size() ; i < sz ; ++i )
{
LevelParam lp = (LevelParam) lpV.elementAt(i);
cW.println( "<OPTION VALUE=\"" + lp.getId() + "\">" );
cW.println( lp.getName() );
cW.println( "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Class" );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.println( "<SELECT NAME=\"class\" SIZE=\"1\">" );
lpV = config.getClasses();
for ( int i = 0, sz = lpV.size() ; i < sz ; ++i )
{
LevelParam lp = (LevelParam) lpV.elementAt(i);
cW.println( "<OPTION VALUE=\"" + lp.getId() + "\">" );
cW.println( lp.getName() );
cW.println( "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.println( "</td>" );
cW.println( "</tr>" );
//
// C O N F I D E N C E
//
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Confidence" );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
String defConfId = config.getDefaultConfidence();
cW.println( "<SELECT NAME=\"confidence\" SIZE=\"1\">" );
lpV = config.getConfidences();
for ( int i = 0, sz = lpV.size() ; i < sz ; ++i )
{
LevelParam lp = (LevelParam) lpV.elementAt(i);
cW.print( "<OPTION VALUE=\"" + lp.getId() + "\"" );
if ( lp.getId().equalsIgnoreCase( defConfId ) )
{
cW.print( " SELECTED" );
}
cW.println( ">" );
cW.println( lp.getName() );
cW.println( "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Project Release" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( "<INPUT type=\"text\" size=\"16\" name=\"release\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "<table bgcolor=\"#FFFFFF\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "JVM Release" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( "<INPUT type=\"text\" size=\"16\" name=\"envjvm\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "OS" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( "<INPUT type=\"text\" size=\"16\" name=\"envos\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "OS Release" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( "<INPUT type=\"text\" size=\"16\" name=\"envosrel\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"right\">" );
cW.println( "Platform" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( "<INPUT type=\"text\" size=\"16\" name=\"envplat\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"center\" colspan=\"2\" width=\"100%\">" );
cW.println( "<table border=\"0\" cellspacing=\"0\"" );
cW.println( " cellpadding=\"3\" width=\"100%\">" );
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td align=\"left\" width=\"100%\" colspan=\"2\">" );
cW.println( "<strong>Submitter:</strong>" );
cW.println( " " );
// If we have a user ID, then this servlet authenticates and we
// are logged in. Thus, use that login name to get the user id,
// and use that for the submitter. Otherwise, show the list.
//
Person p = null;
try {
int userId = this.getUserId( bReq );
if ( userId != 0 )
{
p = Person.getPerson( userId );
}
}
catch ( DBIException ex )
{ p = null; }
if ( p == null )
{
String promptOption =
"<OPTION VALUE=\"-1\"> Select Report Submitter... </OPTION>";
this.getOutput().sendPersonSelector
( bReq, cW, -1, -1, "submitter", promptOption, null );
if ( ! newAccountRequiresAdmin )
{
cW.print ( " " );
cW.print ( "<a href=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/EditPerson/0" );
cW.println( "\">" );
cW.println( "Create New User..." );
cW.println( "</a>" );
}
}
else
{
cW.println( p.getName() );
cW.print ( " ( " );
cW.print ( p.getEmail() );
cW.println( " )" );
cW.println( "<INPUT type=\"hidden\" name=\"submitter\" " );
cW.println( " value=\"" + p.getId() + "\">" );
}
cW.println( "</td>" );
cW.println( "</tr>" );
/*
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td align=\"left\">" );
cW.println( "<strong>Your Email Address:</strong>" );
cW.println( "</td>" );
cW.println( "<td align=\"left\">" );
cW.println( "<strong>Your Full Name:</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td align=\"left\">" );
cW.println( "<INPUT type=\"text\" size=\"36\" name=\"emailaddr\">" );
cW.println( "</td>" );
cW.println( "<td align=\"left\">" );
cW.println( "<INPUT type=\"text\" size=\"36\" name=\"fullname\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
*/
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<strong>Report Synopsis (required):</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<INPUT type=\"text\" size=\"72\" name=\"synopsis\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<strong>Report Description (optional):</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.print ( "<TEXTAREA name=\"repdesc\" rows=\"12\" cols=\"60\">" );
cW.println( "</TEXTAREA>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<strong>Additional Environment Description (optional):</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.print ( "<TEXTAREA name=\"envdesc\" rows=\"3\" cols=\"60\">" );
cW.println( "</TEXTAREA>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<strong>How To Reproduce (optional):</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.print ( "<TEXTAREA name=\"repro\" rows=\"6\" cols=\"60\">" );
cW.println( "</TEXTAREA>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.println( "<strong>Known Work Around (optional):</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" colspan=\"2\">" );
cW.print ( "<TEXTAREA name=\"around\" rows=\"6\" cols=\"60\">" );
cW.println( "</TEXTAREA>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td colspan=\"2\" width=\"100%\" align=\"center\">" );
cW.println( "<table width=\"100%\" cellpadding=\"8\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"center\">" );
cW.println( "<INPUT type=\"submit\" name=\"submit\"" );
cW.println( " value=\"Submit Report\">" );
cW.println( "</td>" );
cW.println( "<td align=\"center\">" );
cW.println( "<INPUT type=\"reset\" name=\"reset\"" );
cW.println( " value=\"Clear Report\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr bgcolor=\"" + reqColor + "\">" );
cW.println( "<td colspan=\"2\" width=\"100%\" align=\"center\">" );
cW.println( "<strong>Fields in the highlighted area are required.</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</center>" );
cW.println( "</form>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private void
sendHelpPage( BugRatRequest bReq )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Bug Report Help" );
this.sendPropertyHTML( bReq, cW, "reportServlet.helpHtml" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private void
sendFieldsHelpPage( BugRatRequest bReq )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Bug Report Fields Help" );
this.sendPropertyHTML( bReq, cW, "reportServlet.fieldHelpHtml" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private void
sendProjectForm( BugRatRequest bReq )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select A Project" );
Vector lpV = null;
DBConfig config = this.getDBConfig();
String bgColor = config.getProperty( "reportServlet.bgColor" );
// UNDONE This title should come from a table!
cW.println( "<h2>Select Project</h2>" );
cW.println( "Please select the project that your BugRat" );
cW.println( "report is to apply to. Once you have made your" );
cW.println( "selection and clicked 'Proceed', then you will" );
cW.println( "be presented with a list of categories to choose" );
cW.println( "from. Finally, you will be presented with the complete" );
cW.println( "report form to submit your report." );
cW.println( "<p>" );
String action = bReq.getServletPath() + "/SelectCat";
cW.print ( "<form method=\"POST\"" );
cW.print ( " action=\"" + action + "\">" );
cW.println( "<center>" );
cW.println( "Select Project" );
cW.println( "<SELECT NAME=\"project\" SIZE=1>" );
Vector projects = this.getDBConfig().getProjects();
for ( int pi = 0, psz = projects.size() ; pi < psz ; ++pi )
{
Category pc = (Category) projects.elementAt(pi);
String proj = pc.getProject();
String projectName = pc.getName();
cW.println( "<OPTION VALUE=\"" + proj + "\">"
+ projectName + "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.print ( "<INPUT type=\"submit\" name=\"submit\"" );
cW.println( " value=\"Proceed\">" );
cW.println( "</center>" );
cW.println( "</form>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private void
sendCategoryForm( BugRatRequest bReq, String project )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select A Category" );
Vector lpV = null;
DBConfig config = this.getDBConfig();
String bgColor = config.getProperty( "reportServlet.bgColor" );
cW.println( "<h2>Select Category</h2>" );
cW.println( "Please select the category that your BugRat" );
cW.println( "report is to apply to. Once you have made your" );
cW.println( "selection and clicked 'Proceed', then you will" );
cW.println( "be presented with the report form to submit." );
cW.println( "<p>" );
cW.println( "<center><strong>Current Project:</strong>" );
cW.println( this.getDBConfig().getProjectName( project ) );
cW.println( "</center><p>" );
String action = bReq.getServletPath() + "/SelectSub";
cW.print ( "<form method=\"POST\"" );
cW.print ( " action=\""+ action + "\">" );
cW.print ( "<INPUT type=\"hidden\" name=\"project\"" );
cW.println( " value=\"" + project + "\">" );
cW.println( "<center>" );
cW.println( "Select Category" );
cW.println( "<SELECT NAME=\"category\" SIZE=1>" );
Vector cats = config.getProjectCategories( project );
for ( int i = 0, sz =cats.size() ; i < sz ; ++i )
{
Category pc = (Category) cats.elementAt(i);
String id = pc.getCategory();
String name = pc.getName();
cW.println( "<OPTION VALUE=\"" + id + "\">"
+ name + "</OPTION>" );
}
cW.println( "</SELECT>" );
cW.print ( "<INPUT type=\"submit\" name=\"submit\"" );
cW.println( " value=\"Proceed\">" );
cW.println( "</center>" );
cW.println( "</form>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private void
sendSubReportForm( BugRatRequest bReq, String project, String category )
throws IOException
{
String action = bReq.getServletPath() + "/PostSelect";
String hidPrefix = "<INPUT type=\"hidden\" ";
String hiddens =
hidPrefix + "name=\"srcid\" value=\"0\">" +
hidPrefix + "name=\"source\" value=\"W\">";
this.sendReportForm
( bReq, action, hiddens, project, category, true );
}
private void
processReportPOST( BugRatRequest bReq, boolean hier )
throws IOException
{
DBConfig config = this.getDBConfig();
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Bug Report Form" );
String bgColor = config.getProperty( "reportServlet.bgColor" );
String okColor = config.getProperty( "reportServlet.okColor" );
String errColor = config.getProperty( "reportServlet.errColor" );
try {
String value;
String pcsStr = null;
String proName = null;
String catName = null;
String subName = null;
//
// V A L I D A T E
//
String[] valAry = bReq.getParameterValues( "submitter" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "report submitter" );
String submitterStr = valAry[0];
int submitterId = Integer.parseInt( submitterStr );
if ( submitterId == -1 )
{
throw this.new RequiredException
( "report submitter" );
}
valAry = bReq.getParameterValues( "confidence" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "confidence" );
String confStr = valAry[0];
valAry = bReq.getParameterValues( "priority" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "priority" );
String priStr = valAry[0];
valAry = bReq.getParameterValues( "severity" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "severity" );
String sevStr = valAry[0];
valAry = bReq.getParameterValues( "class" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "class" );
String clsStr = valAry[0];
valAry = bReq.getParameterValues( "synopsis" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "synopsis" );
String synStr = valAry[0];
valAry = bReq.getParameterValues( "release" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "release" );
String relStr = valAry[0];
valAry = bReq.getParameterValues( "envjvm" );
String jvmStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "envos" );
String osStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "envosrel" );
String osRelStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "envplat" );
String platStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "repdesc" );
String repDescStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "envdesc" );
String envDescStr = ( valAry == null ? null : valAry[0] );
valAry = bReq.getParameterValues( "around" );
String aroundDescStr = ( valAry == null ? null : valAry[0] );
if ( aroundDescStr != null && aroundDescStr.length() == 0 )
aroundDescStr = null;
valAry = bReq.getParameterValues( "repro" );
String reproDescStr = ( valAry == null ? null : valAry[0] );
if ( reproDescStr != null && reproDescStr.length() == 0 )
reproDescStr = null;
//
// P R O C E S S
//
if ( hier )
{
valAry = bReq.getParameterValues( "project" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "project name" );
proName = valAry[0];
valAry = bReq.getParameterValues( "category" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "category name" );
catName = valAry[0];
valAry = bReq.getParameterValues( "subcat" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException( "subcat name" );
subName = valAry[0];
}
else
{
valAry = bReq.getParameterValues( "pcs" );
if ( this.isEmptyParameter( valAry ) )
throw this.new RequiredException
( "project/category/subcat" );
pcsStr = valAry[0];
}
Report report = Report.getNewReport();
if ( hier )
{
report.setProject( proName );
report.setCategory( catName );
report.setSubCategory( subName );
}
else
{
String[] cats = this.splitString( pcsStr, "/" );
report.setProject( cats[0] );
report.setCategory( cats[1] );
report.setSubCategory( cats[2] );
}
report.setSource( SOURCE_WWW );
report.setSubmitter( submitterId );
report.setSubmitted( new Date() );
report.setResponsible
( config.getIncomingResponsible
( report.getProject(),
report.getCategory(),
report.getSubCategory() ) );
report.setState( config.getDefaultReportState() );
report.setConfidence( confStr );
report.setPriority( priStr );
report.setSeverity( sevStr );
report.setReportClass( clsStr );
report.getDescription().setSynopsis( synStr );
EnvDescription eDesc = report.getEnvDescription();
eDesc.setRelease( relStr );
eDesc.setJVM( jvmStr );
eDesc.setOS( osStr );
eDesc.setOSRelease( osRelStr );
eDesc.setPlatform( platStr );
eDesc.setDescription( envDescStr );
String mimeType = "text/plain";
if ( repDescStr != null && config.isTextHTML( repDescStr ) )
{
mimeType = "text/html";
}
report.getDescription().setMimeType( mimeType );
report.getDescription().setDescription( repDescStr );
report.getDescription().setEmail( null );
report.getDescription().setURL( "" );
//
// NOTE We do not require repro or work around.
//
// NOTE That both repro and around are committed
// when the report is committed.
//
if ( reproDescStr != null && reproDescStr.length() > 0 )
{
Description repro = report.getReproDescription();
if ( repro != null )
{
repro.setSynopsis( synStr );
repro.setDescription( reproDescStr );
}
else
{
repro = Description.getNewDescription();
repro.setSynopsis( synStr );
repro.setDescription( reproDescStr );
report.setReproDescription( repro );
}
}
if ( aroundDescStr != null && aroundDescStr.length() > 0 )
{
if ( this.debug ) this.log
( "BugRatReport.aroundDescStr = " + aroundDescStr );
Description around = report.getAroundDescription();
if ( around != null )
{
around.setSynopsis( synStr );
around.setDescription( aroundDescStr );
}
else
{
around = Description.getNewDescription();
around.setSynopsis( synStr );
around.setDescription( aroundDescStr );
report.setAroundDescription( around );
}
}
//
// C O M M I T
//
report.commit();
int repId = report.getId();
int respId = report.getResponsible();
if ( respId != 0 )
{
try {
String subject =
"BugRat Report #" + report.getId()
+ " has been filed.";
StringBuffer body = new StringBuffer();
body.append( "Bug report #" );
body.append( repId );
body.append( " has just been filed." );
body.append( "\n\n" );
body.append( "You can view the report at the following URL:\n\n" );
body.append( " <" );
body.append( bReq.getServletUrlPrefix() );
body.append( bReq.getViewerServletPath() );
body.append( "/ShowReport/" );
body.append( repId );
body.append( ">" );
body.append( "\n\n" );
body.append( "REPORT #" );
body.append( repId );
body.append( " Details.\n\n" );
StringWriter sW = new StringWriter();
PrintWriter pW = new PrintWriter( sW );
this.reportFmt.format
( report, bReq, pW, "text/plain", true );
pW.close();
body.append( sW.toString() );
Vector attach = null;
sW = new StringWriter();
pW = new PrintWriter( sW );
pW.println( "<html>" );
pW.println( "<head>" );
pW.println( "<title>" );
pW.println( "BugRat Report #" );
pW.println( repId );
pW.println( "</title>" );
pW.println( "</head>" );
pW.println( "<body>" );
pW.println( "<h2>" );
pW.println( "BugRat Report #" );
pW.println( repId );
pW.println( "</h2>" );
this.reportFmt.format
( report, bReq, pW, "text/html", true );
pW.print ( "<p>" );
pW.println( "<center>" );
pW.print ( "<a href=\"" );
pW.print ( bReq.getServletUrlPrefix() );
pW.print ( bReq.getViewerServletPath() );
pW.print ( "/ShowReport/" );
pW.print ( repId );
pW.println( "\">" );
pW.println( "View this report online..." );
pW.println( "</a>" );
pW.println( "</center>" );
pW.print ( "</p>" );
pW.println( "</body>" );
pW.println( "</html>" );
attach = new Vector();
StringDataSource ds =
new StringDataSource
( sW.getBuffer().toString(),
( "Report-" + repId + ".html" ),
"text/html" );
attach.addElement( ds );
Person p = Person.getPerson( respId );
if ( p != null )
{
this.mailQueue.addMailJob
( subject, body.toString(), null,
p.getEmail(), null, attach );
}
}
catch ( MessagingException ex )
{
this.log
( "Failed sending mail notice for report #"
+ repId + " filing.", ex );
}
}
cW.println( "<h2>Report Successfully Filed</h2>" );
cW.println( "<table border=\"5\" cellpadding=\"5\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"center\" bgcolor=\"#FFFFFF\">" );
cW.println( "Report ID = " );
cW.println( "<strong>" );
cW.println( "" + report.getId() );
cW.println( "</strong>" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\" bgcolor=\"" + okColor + "\">" );
cW.println( "Your BugRat report has been successfully filed.<br>" );
cW.println( "The report id shown above can be used to find this" );
cW.println( "report in the future, and is the recommended" );
cW.println( "bug reference in all correspondence." );
cW.println( "<p>" );
cW.println( "You may" );
cW.println( "<a href=\"" );
cW.print ( bReq.getViewerServletPath() + "/ShowReport/" );
cW.print ( "" + report.getId() );
cW.println( "\">" );
cW.println( "review the report online" );
cW.println( "</a>" );
cW.println( "to verify proper filing." );
cW.println( "<p>" );
cW.println( "The web address (url) for your report is:<br>" );
cW.println( "<B>" );
cW.print ( bReq.getServletUrlPrefix() );
cW.print ( bReq.getViewerServletPath() );
cW.print ( "/ShowReport/" );
cW.println( "" + report.getId() );
cW.println( "</B>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
}
catch ( DBIException ex )
{
ex.printStackTrace( System.err );
cW.println( "<h2> Error Processing Report </h2>" );
cW.println( "<table border=\"5\" cellpadding=\"5\">" );
cW.println( "<tr>" );
cW.println( "<td bgcolor=\"#FFFFFF\">" );
cW.println( "An error occurred trying to process your" );
cW.println( "BugRat report. The report was not stored," );
cW.println( "or was partially stored and needs to be" );
cW.println( "backed out. Please report the following" );
cW.println( "information to the BugRat Administrator." );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td bgcolor=\"" + errColor + "\">" );
cW.println( "<strong>SQLException:</strong><p>" );
cW.print ( "<PRE>" );
cW.println( ex.getMessage() );
cW.println( "</PRE>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
}
catch ( RequiredException ex )
{
cW.println( "<h2> Missing Required Field </h2>" );
cW.println( "You have a missing field that is required." );
cW.println( "Please use the 'Back' key in your browser" );
cW.println( "to go back to the previous page, which will" );
cW.println( "be your partially completed report form." );
cW.println( "Fill in the missing field and resubmit." );
cW.println( "<p>" );
cW.println( "The missing field was <strong> '" );
cW.println( ex.getMessage() + "'.</strong>" );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
private class
RequiredException extends Exception
{
public
RequiredException( String msg )
{
super( msg );
}
}
}