package org.gjt.bugrat.servlet;
import java.io.*;
import java.util.*;
import java.text.FieldPosition;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import org.gjt.bugrat.db.*;
import org.gjt.bugrat.dbi.*;
import org.gjt.bugrat.text.BugFormatter;
import org.gjt.bugrat.text.ReportFormatter;
public
class DefaultBugRatHTML
implements BugRatHTML, BugRatConstants
{
protected DBConfig dbConfig = null;
protected BugRatServlet servlet = null;
protected SimpleDateFormat dateFmt = null;
protected BugFormatter bugFmt = null;
protected ReportFormatter reportFmt = null;
public
DefaultBugRatHTML( BugRatServlet servlet, DBConfig dbConfig )
{
this.servlet = servlet;
this.dbConfig = dbConfig;
this.dateFmt =
new SimpleDateFormat
( "MMM d yyyy, hh:mm:ss z" );
this.bugFmt =
new BugFormatter( this.dbConfig, this.dateFmt );
this.reportFmt =
new ReportFormatter( this.dbConfig, this.dateFmt );
}
public void
sendCommonHeader( BugRatRequest bReq, PrintWriter cW )
{
this.sendCommonHeader( bReq, cW, "BugRat Servlet" );
}
public void
sendCommonHeader( BugRatRequest bReq, PrintWriter cW, String title )
{
String htmlHead = this.dbConfig.getProperty( "servletCommon.htmlHead" );
String htmlBody = this.dbConfig.getProperty( "servletCommon.htmlBody" );
if ( htmlHead != null && htmlBody != null )
{
Object[] fmtArgs =
{
bReq.getServletContext(),
bReq.getAdminServletName(),
bReq.getReportServletName(),
bReq.getViewerServletName(),
title
};
cW.println( BugRatServlet.format( htmlHead, fmtArgs ) );
cW.println( BugRatServlet.format( htmlBody, fmtArgs ) );
}
else
{
cW.println( "<html>" );
cW.println( "<head>" );
cW.println( "<title>" );
cW.println( title );
cW.println( "</title>" );
cW.println( "</head>" );
cW.println( "<body bgcolor=\"#FFFFFF\">" );
}
}
public void
sendCommonTrailer( BugRatRequest bReq, PrintWriter cW )
{
String htmlTail = this.dbConfig.getProperty( "servletCommon.htmlTail" );
if ( htmlTail != null )
{
Object[] fmtArgs =
{
bReq.getServletContext(),
bReq.getAdminServletName(),
bReq.getReportServletName(),
bReq.getViewerServletName()
};
cW.println( BugRatServlet.format( htmlTail, fmtArgs ) );
}
else
{
cW.println( "</body></html>" );
}
}
public void
listCategories( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Categories" );
cW.println( "<H2>Project / Category / Subcategory</H2>" );
cW.println( "Click on any of the categories listed below" );
cW.println( "to set the person responsible or change the" );
cW.println( "category description." );
cW.println( "<p>" );
Vector projects = this.dbConfig.getProjects();
String adminServletPath = bReq.getAdminServletPath();
for ( int i = 0, psz = projects.size(); i < psz ; i ++ )
{
Category project = (Category) projects.elementAt( i );
String projStr = project.getProject();
String projName = this.dbConfig.getProjectName( projStr );
cW.println( "<A HREF=\"" );
cW.println( adminServletPath );
cW.println( "/EditCategory/" );
cW.println( projStr );
cW.println( "\">" );
cW.println( "<B>Project '" + projName + "'</B>" );
cW.println( "</A>" );
cW.println( "<BR>" );
Vector categories =
this.dbConfig.getProjectCategories( projStr );
for ( int j = 0, csz = categories.size() ; j < csz ; j ++ )
{
Category category = ( Category ) categories.elementAt( j );
String catStr = category.getCategory();
String catName =
this.dbConfig.getCategoryName( projStr, catStr );
for ( int ni = 0 ; ni < 16 ; ++ni )
{ cW.print( " " ); }
cW.println( "<A HREF=\"" );
cW.println( adminServletPath );
cW.println( "/EditCategory/" );
cW.println( projStr );
cW.println( "/" );
cW.println( catStr );
cW.println( "\">" );
cW.println( catName );
cW.println( "</A>" );
cW.println( "<BR>" );
Vector subcats =
this.dbConfig.getCategorySubCats( projStr, catStr );
for ( int k = 0, ssz = subcats.size() ; k < ssz ; k ++ )
{
Category subcat = ( Category ) subcats.elementAt( k );
String subStr = subcat.getSubCategory();
String subName =
this.dbConfig.getSubCategoryName
( projStr, catStr, subStr);
for ( int ni = 0 ; ni < 32 ; ++ni )
{ cW.print( " " ); }
cW.println( "<A HREF=\"" );
cW.println( adminServletPath );
cW.println( "/EditCategory/" );
cW.println( projStr );
cW.println( "/" );
cW.println( catStr );
cW.println( "/" );
cW.println( subStr );
cW.println( "\">" );
cW.println( subName );
cW.println( "</A>" );
cW.println( "<BR>" );
}
}
if ( i < (psz - 1) )
{
cW.println( "<HR>" );
}
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
listPeople( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - People" );
cW.println( "<H2>People In Database</H2>" );
cW.println( "<table width=\"100%\" border=\"1\">" );
cW.println( "<tr>" );
cW.println( "<td>ID</td>" );
cW.println( "<td>Name</td>" );
cW.println( "<td>Email</td>" );
cW.println( "<td>Org</td>" );
cW.println( "<td>Phone</td>" );
cW.println( "<td>FAX</td>" );
cW.println( "<td>URL</td>" );
cW.println( "<td>Type</td>" );
cW.println( "</tr>" );
Vector pV = this.dbConfig.getSortedPersons();
for ( int i = 0, sz = pV.size() ; i < sz ; ++i )
{
Person per = (Person) pV.elementAt(i);
cW.println( "<tr>" );
cW.println( "<td>" + per.getId() + "</td>" );
cW.println( "<td>" + per.getName() + "</td>" );
cW.println( "<td><a href=\"mailto:" + per.getEmail()
+ "\">" + per.getEmail() + "</A>" + "</td>" );
cW.println( "<td> " + per.getOrganization() + "</td>" );
cW.println( "<td> " + per.getPhone() + "</td>" );
cW.println( "<td> " + per.getFAX() + "</td>" );
cW.println( "<td> " + per.getURL() + "</td>" );
cW.println( "<td>" + per.getType() + "</td>" );
cW.println( "</tr>" );
}
cW.println( "</table>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendSelectProject( BugRatRequest bReq, String action )
throws IOException
{
bReq.getResponse().setContentType( "text/html" );
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select A Project" );
cW.println( "<H2>Select A Project</H2>" );
cW.println( "<ul>" );
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
cW.println( "<li>" );
cW.println( "<strong>" );
cW.println( projectName );
cW.println( "</strong>" );
cW.println( "<ul>" );
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.println( projStr );
cW.println( "\">" );
cW.println( "Show all bug reports in project." );
// cW.println( projectName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/SelectReports/" );
cW.println( projStr );
cW.println( "\">" );
cW.println( "Narrow to a project category." );
// cW.println( projectName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "</ul>" );
cW.println( "</li>" );
cW.println( "<p>" );
}
cW.println( "</ul>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendSelectCategory( BugRatRequest bReq, String project, String action )
throws IOException
{
bReq.getResponse().setContentType( "text/html" );
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select A Category" );
String projectName = this.dbConfig.getProjectName( project );
// cW.println( "<H2>Select A Category in " + projectName + "</H2>" );
cW.println( "<H2>" + projectName + "</H2>" );
cW.println( "<ul>" );
Vector cats = this.dbConfig.getProjectCategories( project );
for ( int i = 0, sz = cats.size() ; i < sz ; ++i )
{
Category cc = (Category) cats.elementAt(i);
String catStr = cc.getCategory();
String catName = cc.getName();
cW.println( "<li>" );
cW.println( "<strong>" );
// cW.println( projectName );
// cW.println( " / " );
cW.println( catName );
cW.println( "</strong>" );
cW.println( "<ul>" );
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.println( project );
cW.print ( "/" );
cW.println( catStr );
cW.println( "\">" );
cW.println( "Show all bug reports in category." );
// cW.println( projectName );
// cW.println( " / " );
// cW.println( catName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/SelectReports/" );
cW.println( project );
cW.print ( "/" );
cW.println( catStr );
cW.println( "\">" );
cW.println( "Narrow to a project subcategory." );
// cW.println( projectName );
// cW.println( " / " );
// cW.println( catName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "</ul>" );
cW.println( "</li>" );
cW.println( "<p>" );
}
cW.println( "</ul>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendSelectSubCategory(
BugRatRequest bReq, String project,
String category, String action )
throws IOException
{
bReq.getResponse().setContentType( "text/html" );
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select A Subcategory" );
String projectName = this.dbConfig.getProjectName( project );
String catName = this.dbConfig.getCategoryName( project, category );
cW.println
// ( "<H2>Select A Subcategory in "
( "<H2>"
+ projectName
+ " / "
+ catName
+ "</H2>" );
cW.println( "<ul>" );
Vector cats =
this.dbConfig.getCategorySubCats( project, category );
for ( int i = 0, sz = cats.size() ; i < sz ; ++i )
{
Category sc = (Category) cats.elementAt(i);
String subStr = sc.getSubCategory();
String subName = sc.getName();
cW.println( "<li>" );
cW.println( "<strong>" );
// cW.println( projectName );
// cW.println( " / " );
// cW.println( catName );
// cW.println( " / " );
cW.println( subName );
cW.println( "</strong>" );
cW.println( "<ul>" );
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.println( project );
cW.print ( "/" );
cW.println( category );
cW.print ( "/" );
cW.println( subStr );
cW.println( "\">" );
cW.println( "Show all bug reports in subcategory." );
// cW.println( projectName );
// cW.println( " / " );
// cW.println( catName );
// cW.println( " / " );
// cW.println( subName );
cW.println( "</i></A>" );
cW.println( "</li>" );
cW.println( "</ul>" );
cW.println( "</li>" );
cW.println( "<p>" );
}
cW.println( "</ul>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendSelectAll( BugRatRequest bReq, String action )
throws IOException
{
bReq.getResponse().setContentType( "text/html" );
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select Report Level" );
cW.println( "<H2>Select The Report Level</H2>" );
cW.println( "<ul>" );
Vector projects = this.dbConfig.getProjects();
for ( int pi = 0, psz = projects.size() ; pi < psz ; ++pi )
{
Category pc = (Category) projects.elementAt(pi);
String projStr = pc.getProject();
String projectName = pc.getName();
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.println( projStr );
cW.println( "\">" );
// cW.println( projStr );
// cW.println( " " );
cW.println( projectName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "<ul>" );
Vector cats = this.dbConfig.getProjectCategories( projStr );
for ( int ci = 0, csz = cats.size() ; ci < csz ; ++ci )
{
Category cc = (Category) cats.elementAt(ci);
String catStr = cc.getCategory();
String catName = cc.getName();
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.print ( projStr );
cW.println( "/" );
cW.println( catStr );
cW.println( "\">" );
// cW.println( catStr );
// cW.println( " " );
cW.println( catName );
cW.println( "</A>" );
cW.println( "</li>" );
cW.println( "<ul>" );
Vector subs =
this.dbConfig.getCategorySubCats( projStr, catStr );
for ( int si = 0, ssz = subs.size() ; si < ssz ; ++si )
{
Category sc = (Category) subs.elementAt(si);
String subStr = sc.getSubCategory();
String subName = sc.getName();
cW.println( "<li>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" );
cW.print ( action );
cW.print ( "/" );
cW.print ( projStr );
cW.print ( "/" );
cW.print ( catStr );
cW.print ( "/" );
cW.print ( subStr );
cW.println( "\">" );
// cW.println( subStr );
// cW.println( " " );
cW.println( subName );
cW.println( "</A>" );
cW.println( "</li>" );
}
cW.println( "</ul>" );
}
cW.println( "</ul>" );
cW.println( "<p>" );
}
cW.println( "</ul>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showAllProjectReports( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select Project" );
cW.println( "<h2>Show All Reports In Project</h2>" );
cW.println( "Click on the link of the project you " );
cW.println( "are interested in from the list below " );
cW.println( "to see the list of reports." );
cW.print ( "<FORM method=\"POST\" action=\"" );
cW.print ( bReq.getServletPath() );
cW.println( "/ShowReports\">" );
cW.println( "Project:<br>" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"scope\" value=\"project\">" );
cW.println( "<SELECT name=\"project\" size=\"10\">" );
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
cW.print ( "<OPTION value=\"" + projStr + "\">" );
cW.println( projectName );
}
cW.println( "</SELECT>" );
cW.println( "<br>" );
cW.print ( "<INPUT type=\"submit\"" );
cW.println( " name=\"submit\" value=\"Show Reports\">" );
cW.println( "</FORM>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showAllProjectBugs( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Select Project" );
cW.println( "<h2>Show All Bugs In Project</h2>" );
cW.println( "Use this form to show all of the bugs in the." );
cW.println( "project that you specify. Select the project you" );
cW.println( "are interested in from the list below, and click" );
cW.println( "the 'Show Bugs' button to see the list of bugs." );
cW.println( "<FORM method=\"POST\" action=\"ShowBugs\">" );
cW.println( "Project:<br>" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"scope\" value=\"project\">" );
cW.println( "<SELECT name=\"project\" size=\"10\">" );
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
cW.print ( "<OPTION value=\"" + projStr + "\">" );
cW.println( projectName );
}
cW.println( "</SELECT>" );
cW.println( "<br>" );
cW.print ( "<INPUT type=\"submit\"" );
cW.println( " name=\"submit\" value=\"Show Bugs\">" );
cW.println( "</FORM>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showAllStatistics( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Statistics" );
int openCount = 0;
int closeCount = 0;
int notAssignedCount = 0;
int reportCount = 0;
int bugCount = 0;
cW.println( "<h2>Statistics By Project</h2>" );
cW.println( "<TABLE>" );
cW.println( "<TH>Project <TD> # Reports <TD> # Bugs <TD> # Unassigned Bugs <TD> # Open Bugs <TD> # Closed Bugs" );
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
int thisOpenCount = 0;
int thisCloseCount = 0;
int thisNotAssignedCount = 0;
cW.print ( "<TR><TD>" + projectName);
try {
Vector reports =
Report.matchReports
( "SELECT * FROM "
+ "report WHERE "
+ "project = "
+ "\"" + projStr + "\""
);
cW.print ( "<TD align=\"center\">" + reports.size() );
reportCount = reportCount + reports.size();
Vector bugs = Bug.matchBugs( "SELECT * FROM bug WHERE " +
"project = " + "\"" + projStr + "\"");
for ( int p = 0, bsz = bugs.size() ; p < bsz; ++ p )
{
Bug bug = (Bug) bugs.elementAt(p);
if ( bug.getResponsible() == 0 )
{
thisNotAssignedCount++;
notAssignedCount++;
}
if ( bug.getState().equals( "C" ) )
{
thisCloseCount++;
closeCount++;
}
if ( !bug.getState().equals( "C" ) &&
!bug.getState().equals( "R" ))
{
thisOpenCount++;
openCount++;
}
}
cW.println ( "<TD align=\"center\">" + bugs.size() );
bugCount = bugCount + bugs.size();
cW.println ( "<TD align=\"center\">" + thisNotAssignedCount );
cW.println ( "<TD align=\"center\">" + thisOpenCount );
cW.println ( "<TD align=\"center\">" + thisCloseCount );
}
catch ( DBIException ex )
{
cW.println( "<h2>Error Getting Statistics</h2>" );
cW.println( "An error occurred trying to get the" );
cW.println( "statistics for the projects." );
cW.println( "The message was:<br>" );
cW.println( ex.getMessage() );
}
}
cW.println(" <TR><TD><HR><TD><HR><TD><HR><TD><HR><TD><HR><TD><HR> " );
cW.println(" <TR><TD>Total In Database " );
cW.println(" <TD align=\"center\">" + reportCount );
cW.println(" <TD align=\"center\">" + bugCount );
cW.println(" <TD align=\"center\">" + notAssignedCount );
cW.println(" <TD align=\"center\">" + openCount );
cW.println(" <TD align=\"center\">" + closeCount );
cW.println( "</TABLE>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showReport( BugRatRequest bReq, PrintWriter cW, int id )
throws IOException
{
try {
Report rep = Report.getReport( id );
if ( rep == null )
{
throw new DBIException
( "Report #" + id + " can not be found" );
}
Description desc = rep.getDescription();
EnvDescription eDesc = rep.getEnvDescription();
Description repro = rep.getReproDescription();
Description around = rep.getAroundDescription();
cW.print ( "<h2>Bug Report #" );
cW.print ( id );
cW.println( "</h2>" );
this.reportFmt.format
( rep, bReq, cW, "text/html", false );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<strong>Current Links To Bugs:</strong>" );
Vector repV =
Bug.matchBugs(
"SELECT * from bug, repbug WHERE " +
" repbug.report = " + id +
" AND bug.id = repbug.bug "
);
if ( repV.size() == 0 )
{
cW.println( "<DD>" );
cW.println( "This report is not linked to any bugs." );
}
else
{
for ( int i = 0, sz = repV.size(); i < sz ; i++ )
{
Bug bug = (Bug) repV.elementAt( i );
cW.println( "<DD>" );
cW.println( "<a href=\""
+ bReq.getServletPath()
+ "/ShowBug/" +
bug.getId() + "\">Bug #" );
cW.println( bug.getId() + "</A> - " +
bug.getDescription().getSynopsis() );
cW.println( "<BR>" );
}
}
cW.println( "</DL>" );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<strong>Comments:</strong>" );
Vector cmtV = Comment.getComments( "R", id );
if ( cmtV.size() == 0 )
{
cW.println( "<DD>" );
cW.println( "This report has no additional comments." );
}
else
{
for ( int i = 0, sz = cmtV.size(); i < sz ; i++ )
{
Comment cmt = (Comment) cmtV.elementAt( i );
cW.println( "<DD>" );
cW.println( "<a href=\""
+ bReq.getServletPath()
+ "/ShowComment/" +
cmt.getId() + "\">Comment #" );
cW.println( cmt.getId() + "</A> - " );
cW.println( cmt.getDescription().getSynopsis() );
cW.println( "<BR>" );
}
}
cW.println( "</DL>" );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<strong>Menu</strong>" );
if ( bReq.allowsReportComments()
&& ( (! bReq.getCommentsRequireAdmin())
|| bReq.isAdmin() ) )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/AddReportComment/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Add Comment To Report" );
cW.println( "</A>" );
}
if ( bReq.isAdmin() )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/LinkReport/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Link Report To A Bug" );
cW.println( "</A>" );
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/ReassignReport/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Reassign this report to another person." );
cW.println( "</A>" );
if ( ! rep.isClosed() )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/CloseReport/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Close this report." );
cW.println( "</A>" );
}
}
else
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/ShowReport/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "View report with admin servlet." );
cW.println( "</A>" );
}
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/MailReport/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Email report to someone." );
cW.println( "</A>" );
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/ShowReportActions/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Show action history." );
cW.println( "</A>" );
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.println( "/\">" );
cW.println( "Back To Index" );
cW.println( "</A>" );
cW.println( "</DL>" );
}
catch ( DBIException ex )
{
this.servlet.log
( "showing report #" + id, ex );
this.reportError
( bReq, cW,
"Could not retrieve Report #"
+ id + ", " + ex.getMessage() );
}
}
public void
showBug( BugRatRequest bReq, PrintWriter cW, int id )
throws IOException
{
try {
Bug bug = Bug.getBug( id );
if ( bug == null )
{
throw new DBIException
( "Bug #" + id + " can not be found" );
}
cW.print ( "<h2>Bug #" );
cW.print ( id );
cW.println( " Details" );
cW.println( "</h2>" );
this.bugFmt.format
( bug, bReq, cW, "text/html", false );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<STRONG>Reports Linked To This Bug:</STRONG>" );
Vector repV = Report.matchReports
(
"SELECT report.id " +
"FROM report, repbug " +
"WHERE report.id = repbug.report " +
"AND repbug.bug = " + id
);
if ( repV.size() == 0 )
{
cW.println( "<DD>" );
cW.println( "There are no Reports linked to this bug." );
}
else
{
for ( int i = 0, sz = repV.size(); i < sz ; i ++ )
{
Report rep = (Report) repV.elementAt( i ) ;
cW.println( "<DD>" );
cW.print ( "<a href=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/ShowReport/" );
cW.print ( rep.getId() );
cW.println( "\">" );
cW.print ( "Rep #" );
cW.println( rep.getId() );
cW.println( "</A> - " );
cW.println( rep.getDescription().getSynopsis() );
cW.println( "<BR>" );
}
}
cW.println( "</DL>" );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<strong>Comments:</strong>" );
Vector cmtV = Comment.getComments( "B", id );
if ( cmtV.size() == 0 )
{
cW.println( "<DD>" );
cW.println( "This report has no additional comments." );
}
else
{
for ( int i = 0, sz = cmtV.size(); i < sz ; i++ )
{
Comment cmt = (Comment) cmtV.elementAt( i );
cW.println( "<DD>" );
cW.println( "<a href=\""
+ bReq.getServletPath()
+ "/ShowComment/" +
cmt.getId() + "\">Comment #" );
cW.println( cmt.getId() + "</A> - " );
cW.println( cmt.getDescription().getSynopsis() );
cW.println( "<BR>" );
}
}
cW.println( "</DL>" );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT>" );
cW.println( "<strong>Menu</strong>" );
if ( bReq.allowsBugComments() && bReq.isAdmin() )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/AddBugComment/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Add a new comment to this bug." );
cW.println( "</A>" );
}
if ( bReq.isAdmin() )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/ReassignBug/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Reassign this bug to another person." );
cW.println( "</A>" );
if ( ! bug.isClosed() )
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/CloseBug/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Close this bug." );
cW.println( "</A>" );
}
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/EditBug/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Edit this bug." );
cW.println( "</A>" );
}
else
{
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getAdminServletPath() );
cW.print ( "/ShowBug/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "View bug with admin servlet." );
cW.println( "</A>" );
}
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/MailBug/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Email bug to someone." );
cW.println( "</A>" );
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/ShowBugActions/" );
cW.print ( id );
cW.println( "\">" );
cW.println( "Show action history." );
cW.println( "</A>" );
cW.println( "<DD>" );
cW.print ( "<A HREF=\"" );
cW.print ( bReq.getServletPath() );
cW.println( "/\">" );
cW.println( "Back To Index" );
cW.println( "</A>" );
cW.println( "</DL>" );
}
catch ( DBIException ex )
{
this.reportError
( bReq, cW,
"Could not retrieve Bug #"
+ id + ", " + ex.getMessage() );
}
}
public void
showComment( BugRatRequest bReq, PrintWriter cW, int id )
throws IOException
{
try {
Comment cmt = Comment.getComment( id );
if ( cmt == null )
{
throw new DBIException
( "Comment.getComment(" + id + ") returns null" );
}
Description desc = cmt.getDescription();
cW.print ( "<h2>Comment #" );
cW.print ( id );
cW.println( "</h2>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>Synopsis:</strong>" );
cW.println( "<DD>" );
cW.println( desc.getSynopsis() );
cW.println( "<p>" );
cW.println( "<DT><strong>Comment:</strong>" );
cW.println( "<DD>" );
// UNDONE - Convert 'text/plain' to 'text/html'!
//
cW.println( desc.getDescription() );
cW.println( "</DL>" );
}
catch ( DBIException ex )
{
this.reportError
( bReq, cW,
"Could not retrieve Comment #"
+ id + ", " + ex.getMessage() );
}
}
public void
sendCommentHTML( BugRatRequest bReq, PrintWriter cW, Comment cmt )
throws IOException, DBIException
{
Person p = Person.getPerson( cmt.getCommentorId() );
String personName = p.getName();
String personEmail = p.getEmail();
cW.println( "<h3>" + cmt.getDescription().getSynopsis() + "</h3>" );
cW.println( "Comment #" + cmt.getId() + " by " + personName + "." );
cW.print ( "<A HREF=\"mailto:" );
cW.print ( personEmail );
cW.println( "\">" );
cW.println( "Send email to " + personName + "." );
cW.println( "</a>" );
cW.println( "<p>" );
// UNDONE - Convert 'text/plain' to 'text/html'!
//
cW.println( cmt.getDescription().getDescription() );
cW.println( "<p>" );
}
public void
showComments( BugRatRequest bReq, String context, int id )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader
( bReq, cW, "BugRat - " + context + " #" + id + " Comments" );
cW.println( "<h2>Comments for " + context + " #" + id + "</h2>" );
try {
Vector comments =
Comment.getComments
( (context.equalsIgnoreCase("report") ? "R" : "B"), id );
for ( int i = 0, sz = comments.size() ; i < sz ; ++i )
{
Comment cmt = (Comment) comments.elementAt(i);
this.sendCommentHTML( bReq, cW, cmt );
if ( i < (sz - 1) )
{
cW.println( "<hr>" );
}
}
}
catch ( DBIException ex )
{
this.reportError
( bReq, cW, "error showing comments for '"
+ context + "' id =" + id );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendActionHTML( BugRatRequest bReq, PrintWriter cW, BugRatAction action )
throws IOException, DBIException
{
int actorId = action.getActorId();
Person p = Person.getPerson( actorId );
String personName = (p == null) ? ("#"+actorId) : p.getName();
String personEmail = (p == null) ? null : p.getEmail();
cW.print ( "<B>Action #" + action.getId() + "</B>" );
cW.print ( " " );
cW.print ( personName );
if ( personEmail != null )
{
cW.print ( " ( " );
cW.print ( "<A HREF=\"mailto:" );
cW.print ( personEmail );
cW.print ( "\">" );
cW.print ( personEmail );
cW.print ( "</A>" );
cW.print ( " )" );
}
cW.print ( ", " );
StringBuffer dBuf = new StringBuffer();
this.dateFmt.format
( action.getActionTime(), dBuf, new FieldPosition(0) );
cW.println( dBuf );
cW.println( "<br>" );
cW.println( "<blockquote>" );
cW.println( action.getComment() ); // UNDONE escape HTML!
if ( action.getType().equals( ACTION_MODIFY )
&& action.getArgOne() > 0 )
{
Description actDesc =
Description.getDescription( action.getArgOne() );
if ( actDesc != null )
{
cW.print ( "<pre>" );
cW.print ( actDesc.getDescription() );
cW.println( "</pre>" );
}
}
cW.println( "</blockquote>" );
}
// NOTE
// REVIEW
// Really, the action vector should come from the caller.
// We are the "outputter", NOT the "data gatherer"!
//
public void
showActions( BugRatRequest bReq, String context, int id )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader
( bReq, cW, "BugRat - " + context + " #" + id + " Action History" );
cW.println( "<h2>Action History for " + context + " #" + id + "</h2>" );
boolean sentActions = false;
try {
Vector actions =
BugRatAction.getActions
( ( context.equalsIgnoreCase( "bug" )
? TARGET_BUG : TARGET_REPORT ), id );
for ( int i = 0, sz = actions.size() ; i < sz ; ++i )
{
BugRatAction act = (BugRatAction) actions.elementAt(i);
this.sendActionHTML( bReq, cW, act );
sentActions = true;
if ( i < (sz - 1) )
{
cW.println( "<hr>" );
}
}
}
catch ( DBIException ex )
{
this.reportError
( bReq, cW, "error showing comments for '"
+ context + "' id =" + id );
}
if ( ! sentActions )
{
cW.println( "<strong>" );
cW.println( "No actions have been recorded for this " + context + "." );
cW.println( "</strong>" );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showAllReports( BugRatRequest bReq, String options )
throws IOException
{
bReq.getResponse().setContentType( "text/html" );
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - All Reports" );
if ( options == null )
options = new String ( "" );
boolean hits = false;
try {
// Get All Projects
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
//
// NOTE
// REVIEW
// UNDONE
// THESE SQL STATEMENTS ARE USING A "LEFT JOIN" OPERATOR
// SPECIFIC TO MYSQL BECAUSE MYSQL DOES NOT SUPPORT SUB-SELECTS
// (OTHERWISE KNOWN AS SUB-QUERIES). WE SHOULD HAVE A FLAG THAT
// INDICATES THE DB SUPPORTS SUBQUERIES SO WE CAN USE MORE
// 'STANDARD' SQL.
//
// NOTE also that these are retrieved from the DB properties
// named 'sql.showreports.linked', and 'sql.showreports.unlinked'.
//
// 'linked' select:
// SELECT DISTINCT report.id
// FROM report, repbug
// WHERE report.project = 'jcvs'
// AND report.id = repbug.report
//
// 'unlinked' select:
// SELECT DISTINCT report.id
// FROM report
// LEFT JOIN repbug ON report.id = repbug.report
// WHERE repbug.report is NULL
// AND report.project = 'jcvs'
//
// If you had sub-selects, you would do this:
// SELECT DISTINCT report.id
// FROM report
// WHERE report.project = 'jcvs'
// AND 0 = ( SELECT COUNT(*) FROM repbug WHERE repbug.report = report.id )
//
String matchString =
this.dbConfig.getProperty
( "sql.showreports." + options, null );
if ( matchString == null )
{
throw new DBIException
( "you have not defined the property '"
+ "sql.showreports." + options + "'" );
}
Object[] fmtArgs = { projStr };
String sqlStatement =
BugRatServlet.format( matchString, fmtArgs );
// System.err.println
// ( "MATCH SQL = '" + sqlStatement + "'" );
Vector repV = Report.matchReports( sqlStatement );
String title =
"Reports For Project " + projectName;
if ( repV.size() != 0 )
{
hits = true;
cW.println( "<table width=\"100%\" border=\"3\"" );
cW.println( " cellspacing=\"3\" bgcolor=\"#D0FFD0\">" );
cW.println( "<tr bgcolor=\"#FFFFFF\">" );
cW.println( "<td>" );
this.showReports( bReq, cW, title, repV, "ShowReport" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
if ( i < (sz-1) )
cW.println( "<p>" );
}
}
}
catch ( DBIException ex )
{
cW.println( "<h2>Error Getting Reports</h2>" );
cW.println( "An error occurred trying to get the" );
if ( options.equalsIgnoreCase( "linked" ) )
cW.println( " linked " );
cW.println( "reports for all projects." );
cW.println( "The message was:<br>" );
cW.println( ex.getMessage() );
}
if ( ! hits )
{
cW.println( "<H2>Database Empty</H2>" );
cW.println( "There were no reports in the Database." );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showAllBugs( BugRatRequest bReq )
throws IOException
{
bReq.getResponse().setContentType("text/html");
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - All Bugs" );
boolean hits = false;
try {
// Get All Bugs
Vector projects = this.dbConfig.getProjects();
for ( int i = 0, sz = projects.size() ; i < sz ; ++i )
{
Category pc = (Category) projects.elementAt(i);
String projStr = pc.getProject();
String projectName = pc.getName();
Vector bugV = Bug.matchBugs
(
"SELECT bug.id " +
"FROM bug " +
"WHERE bug.project = '" + projStr + "'"
);
String title =
"Bugs For Project " + projectName;
if ( bugV.size() != 0 )
{
this.showBugs( bReq, cW, title, bugV, "ShowBug" );
hits = true;
}
}
}
catch ( DBIException ex )
{
cW.println( "<h2>Error Getting Bugs</h2>" );
cW.println( "An error occurred trying to get the" );
cW.println( "bugs for all projects." );
cW.println( "The message was:<br>" );
cW.println( ex.getMessage() );
}
if ( !hits )
{
cW.println( "<H2>Database Empty</H2>" );
cW.println( "There are no bugs in the Database." );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
showBugs(
BugRatRequest bReq, PrintWriter cW,
String title, Vector bugV, String action )
{
DBConfig cfg = this.dbConfig;
cW.println( "<table border=\"0\" width=\"100%\"" );
cW.println( " cellspacing=\"0\" cellpadding=\"3\">" );
cW.println( "<tr bgcolor=\"#A0F0A0\">" );
cW.println( "<th colspan=\"5\">" );
cW.println( "<font size=\"+1\">" );
cW.println( title );
cW.println( "</font>" );
cW.println( "</th>" );
cW.println( "</tr>" );
cW.println( "<tr bgcolor=\"#FFFF90\">" );
// cW.println( "<tr>" );
cW.println( "<th align=\"left\">ID</th>" );
cW.println( "<th align=\"left\">Project</th>" );
cW.println( "<th align=\"left\">Category</th>" );
cW.println( "<th align=\"left\">SubCat</th>" );
cW.println( "<th align=\"left\">State</th>" );
cW.println( "</tr>" );
for ( int i = 0, sz = bugV.size() ; i < sz ; ++i )
{
Bug bug = (Bug) bugV.elementAt(i);
cW.println( "<tr bgcolor=\"#F0F0F0\">" );
cW.print ( "<td align=\"center\">" );
cW.print ( "<a href=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" + action + "/" );
cW.print ( bug.getId() );
cW.println( "\">" );
cW.println( "<strong>" );
cW.println( bug.getId() );
cW.println( "</strong>" );
cW.println( "</a>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getProjectName( bug.getProject() ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getCategoryName
( bug.getProject(), bug.getCategory() ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getSubCategoryName
( bug.getProject(), bug.getCategory(),
bug.getSubCategory() ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getStateName( bug.getState() ) );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "</td>" );
cW.println( "<td colspan=\"4\">" );
cW.println( "<strong>" );
cW.println( bug.getDescription().getSynopsis() );
cW.println( "</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td height=\"6\" colspan=\"5\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
}
cW.println( "</table>" );
}
public void
showReports(
BugRatRequest bReq, PrintWriter cW,
String title, Vector repV, String action )
{
DBConfig cfg = this.dbConfig;
cW.println( "<table border=\"0\" width=\"100%\"" );
cW.println( " cellspacing=\"0\" cellpadding=\"3\">" );
cW.println( "<tr bgcolor=\"#A0F0A0\">" );
cW.println( "<th colspan=\"5\">" );
cW.println( "<font size=\"+1\">" );
cW.println( title );
cW.println( "</font>" );
cW.println( "</th>" );
cW.println( "</tr>" );
cW.println( "<tr bgcolor=\"#FFFF90\">" );
// cW.println( "<tr>" );
cW.println( "<th align=\"left\">ID</th>" );
cW.println( "<th align=\"left\">Project</th>" );
cW.println( "<th align=\"left\">Category</th>" );
cW.println( "<th align=\"left\">SubCat</th>" );
cW.println( "<th align=\"left\">State</th>" );
cW.println( "</tr>" );
for ( int i = 0, sz = repV.size() ; i < sz ; ++i )
{
Report report = (Report) repV.elementAt(i);
String repProject = report.getProject();
String repCat = report.getCategory();
String repSubCat = report.getSubCategory();
String repId =
(new Integer( report.getId() )).toString();
cW.println( "<tr bgcolor=\"#F0F0F0\">" );
cW.print ( "<td align=\"center\">" );
cW.print ( "<a href=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/" + action + "/" );
cW.print ( repId );
cW.println( "\">" );
cW.println( "<strong>" );
cW.println( repId );
cW.println( "</strong>" );
cW.println( "</a>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getProjectName( repProject ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getCategoryName
( repProject, repCat ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getSubCategoryName
( repProject, repCat, repSubCat ) );
cW.println( "</td>" );
cW.println( "<td>" );
cW.println( cfg.getStateName( report.getState() ) );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "</td>" );
cW.println( "<td colspan=\"4\">" );
cW.println( "<strong>" );
cW.println( report.getDescription().getSynopsis() );
cW.println( "</strong>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td height=\"6\" colspan=\"5\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
}
cW.println( "</table>" );
}
public void
showEmailMessage( BugRatRequest bReq, PrintWriter cW, int id )
throws IOException
{
try {
DBConfig config = this.dbConfig;
EmailMsg email = EmailMsg.getEmailMsg( id );
if ( email == null )
throw new DBIException
( "Email Message #" + id + " can not be found" );
EmailContent cont = email.getContent();
if ( cont == null )
throw new DBIException
( "Email Message #" + id + " has null content" );
cW.println( "<PRE>" );
cW.write( new String( cont.getContent() ) );
cW.println( "</PRE>" );
}
catch ( DBIException ex )
{
this.reportError
( bReq, cW,
"Could not retrieve Email #"
+ id + ", " + ex.getMessage() );
}
}
public void
sendBugIDForm( BugRatRequest bReq, String action )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Enter Bug ID" );
cW.println( "<H2>Choose Bug By Bug ID</H2>" );
cW.println( "Please type in the ID of the bug you would like to view." );
cW.println( "<BR>" );
cW.println
( "<FORM method=\"POST\" action=\""
+ bReq.getServletPath()
+ action
+ "\">" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"scope\" value=\"ID\">" );
cW.println( "<INPUT type=\"text\" name=\"bugId\" > ");
cW.println( "<INPUT type=\"submit\" name=\"submit\"" );
cW.println( " value=\"Find Bug\">" );
cW.println( "</FORM>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendReportIDForm( BugRatRequest bReq, String action )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Enter Report ID" );
cW.println( "<H2>Choose Report By Report ID</H2>" );
cW.println( "Please type in the ID of the report you would like to view." );
cW.println( "<BR>" );
cW.println
( "<FORM method=\"POST\" action=\""
+ bReq.getServletPath()
+ action
+ "\">" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"scope\" value=\"ID\">" );
cW.println( "<INPUT type=\"text\" name=\"reportId\" > ");
cW.println( "<INPUT type=\"submit\" name=\"submit\"" );
cW.println( " value=\"Find Report\">" );
cW.println( "</FORM>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
processChooseBug( BugRatRequest bReq )
throws IOException
{
DBConfig config = this.dbConfig;
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Bug ID" );
String[] valAry = bReq.getParameterValues( "bugId" );
if ( this.isEmptyParameter( valAry ) )
{
cW.println( "<H2>Bug ID Required</H2> " );
cW.println( "You must enter a value for the Bug Id!" );
cW.println( "Please press BACK on your browser, " );
cW.println( "enter a Bug Id, and try again." );
}
else
{
String bugIdStr = valAry[0];
int bugId = -1;
try { bugId = Integer.parseInt( bugIdStr ); }
catch ( NumberFormatException ex )
{ bugId = -1; };
this.showBug( bReq, cW, bugId );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
processChooseReport( BugRatRequest bReq )
throws IOException
{
DBConfig config = this.dbConfig;
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Report ID" );
String[] valAry = bReq.getParameterValues( "reportId" );
if ( this.isEmptyParameter( valAry ) )
{
cW.println( "<H2>Report ID Required</H2> " );
cW.println( "You must enter a value for the Report Id!" );
cW.println( "Please press BACK on your browser, " );
cW.println( "enter a Report Id, and try again." );
}
else
{
String reportIdStr = valAry[0];
int reportId = -1;
try { reportId = Integer.parseInt( reportIdStr ); }
catch ( NumberFormatException ex )
{ reportId = -1; };
this.showReport( bReq, cW, reportId );
}
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendCommentForm( BugRatRequest bReq, String tgtName, int id )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader
( bReq, cW, "BugRat - " + tgtName + " #" + id + " Comment" );
cW.println( "<h2>Adding Comment To " + tgtName + " #" + id + "</h2>" );
cW.println( "Use this form to add a new comment to the " );
cW.println( tgtName );
cW.println( " with ID #" + id + "." );
cW.print ( "<FORM method=\"POST\" action=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/AddComment\">" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"target\" value=\"" + tgtName + "\">" );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"id\" value=\"" + id + "\">" );
cW.println( "<table width=\"100%\" border=\"0\">" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "Commentor: " );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
String promptOption =
"<OPTION VALUE=\"-1\"> Select Comment Author... </OPTION>";
this.sendPersonSelector
( bReq, cW, -1, -1, "commentor", promptOption, null );
if ( ! this.servlet.getNewUserRequiresAdmin() )
{
cW.print ( " " );
cW.print ( "<a href=\"" );
cW.print ( bReq.getServletPath() );
cW.print ( "/EditPerson/0" );
cW.println( "\">" );
cW.println( "Create New User..." );
cW.println( "</a>" );
}
cW.println( "</td>" );
cW.println( "</tr>" );
/*
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "Email Address: " );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.print ( "<INPUT type=\"textfield\" size=\"64\"" );
cW.println( " name=\"email\" value=\"\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "Full Name: " );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.print ( "<INPUT type=\"textfield\" size=\"64\"" );
cW.println( " name=\"name\" value=\"\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
*/
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "Synopsis: " );
cW.println( "</td>" );
cW.println( "<td width=\"100%\">" );
cW.print ( "<INPUT type=\"textfield\" size=\"64\"" );
cW.println( " name=\"synopsis\" value=\"\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td colspan=\"2\" align=\"center\" width=\"100%\">" );
cW.print ( "<textarea rows=12 cols=64 name=\"comment\">" );
cW.print ( "</textarea>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td colspan=\"2\" align=\"center\" width=\"100%\">" );
cW.print ( "<INPUT type=\"submit\"" );
cW.print ( " name=\"submit\" value=\"Add Comment To " );
cW.println( tgtName + "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</FORM>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendImage( BugRatRequest bReq )
throws IOException
{
String pathInfo = bReq.getPathInfo();
String imgName = pathInfo.substring( "/images/".length() );
String imageRsrc = imgName;
if ( imgName.indexOf( "/" ) > 0 )
imageRsrc = "/" + imgName;
else
imageRsrc = "/org/gjt/bugrat/images/" + imgName;
OutputStream os = null;
boolean contentSet = false;
try {
InputStream img =
this.getClass().getResourceAsStream( imageRsrc );
if ( img != null )
{
String contentType = "image/gif";
if ( imageRsrc.endsWith( ".jpg" )
|| imageRsrc.endsWith( ".jpeg" ) )
{
contentType = "image/jpeg";
}
bReq.getResponse().setContentType( contentType );
contentSet = true;
os = bReq.getResponse().getOutputStream();
byte[] buf = new byte[ 16 * 1024 ];
for ( ; ; )
{
int num = img.read( buf );
if ( num == -1 ) break;
os.write( buf, 0, num );
}
os.close();
img.close();
}
else
{
throw new IOException
( "getResourceAsStream("+imageRsrc+") returned null" );
}
}
catch ( IOException ex )
{
String errMsg =
"Could not send image '"
+ imgName + "' from '" + imageRsrc + "'";
this.servlet.log( errMsg, ex );
if ( ! contentSet )
{
bReq.getResponse().setContentType("text/html");
try {
PrintWriter cW = bReq.getResponse().getWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Error Unknown Image" );
this.reportError( bReq, cW, errMsg );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
catch ( IOException ex2 )
{
this.servlet.log
( "sending image error message", ex2 );
}
}
else if ( os != null )
{
try { os.close(); }
catch ( IOException ex2 )
{
this.servlet.log
( "closing os under exception", ex2 );
}
}
}
}
public void
reportError( BugRatRequest bReq, PrintWriter cW, String errorHtml )
throws IOException
{
cW.println( "<h2>Error Occurred</h2>" );
cW.println( "An error occurred processing your request." );
cW.println( "You might <a href=\"mailto:" );
cW.println( this.dbConfig.getAdminEmailAddress() );
cW.println( "\">" );
cW.println( "mail a bug report to the webmaster,</a>" );
cW.print ( "or <a href=\"");
cW.print ( bReq.getReportServletPath() );
cW.println( "/ReportForm\">" );
cW.println( "use the BugRat system to report the problem.</a>" );
cW.println( "<p>" );
cW.println( "The error message is:<br>" );
cW.println( "<strong>" );
cW.println( errorHtml );
cW.println( "</strong>" );
}
public void
sendTableTitle( BugRatRequest bReq, PrintWriter cW, String title )
throws IOException
{
String logo = this.dbConfig.getProperty( "reportServlet.logoURL" );
String ratURL = this.dbConfig.getProperty( "reportServlet.ratURL" );
if ( logo == null )
{
cW.println( "<center><strong>" );
cW.println( "<font size=\"+2\">" );
cW.println( title );
cW.println( "</font>" );
cW.println( "</strong></center>" );
}
else
{
cW.println( "<table width=\"100%\" border=\"0\">" );
cW.println( "<tr>" );
cW.println( "<td align=\"left\">" );
cW.println( "<strong>" );
cW.println( "<font size=\"+2\">" );
cW.println( title );
cW.println( "</font>" );
cW.println( "</strong>" );
cW.println( "</td>" );
cW.println( "<td align=\"right\">" );
if ( ratURL != null )
cW.println( "<a href=\"" + ratURL + "\">" );
cW.print ( "<img border=\"0\" src=\"" );
cW.print ( bReq.getServletContext() );
cW.print ( "/images/" );
cW.print ( logo );
cW.println( "\">" );
if ( ratURL != null )
cW.println( "</a>" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
}
}
/**
* Outputs the HTML that provides a combobox selector to select
* a person for any purpose.
*/
public void
sendPersonSelector(
BugRatRequest bReq, PrintWriter cW, int selId, int avoidId,
String fieldName, String preOptions, String postOptions )
throws IOException
{
cW.print ( "<SELECT NAME=\"" );
cW.print ( fieldName );
cW.println( "\" SIZE=\"1\">" );
if ( preOptions != null )
{
cW.println( preOptions );
}
Vector pV = this.dbConfig.getSortedPersons();
for ( int i = 0, sz = pV.size() ; i < sz ; ++i )
{
Person per = (Person) pV.elementAt(i);
if ( per.getId() == avoidId )
continue;
cW.print ( "<OPTION VALUE=\"" );
cW.print ( per.getId() );
cW.print ( "\"" );
if ( per.getId() == selId )
{
cW.print ( " SELECTED" );
}
cW.println( ">" );
cW.println( per.getName() );
cW.println( "</OPTION>" );
}
if ( postOptions != null )
{
cW.println( postOptions );
}
cW.println( "</SELECT>" );
}
public void
sendSelectPersonPage( BugRatRequest bReq )
throws IOException
{
PrintWriter cW = bReq.getHTMLWriter();
this.sendCommonHeader( bReq, cW, "BugRat - Choose Person" );
cW.println( "<h2>Select Person To Edit</h2>" );
cW.println( "<table width=\"100%\" border=\"0\">" );
cW.println( "<tr>" );
cW.println( "<th>ID</th>" );
cW.println( "<th>T</th>" );
cW.println( "<th>Name</th>" );
cW.println( "<th>Email</th>" );
cW.println( "<th>Org</th>" );
cW.println( "</tr>" );
Vector pV = this.dbConfig.getSortedPersons();
for ( int i = 0, sz = pV.size() ; i < sz ; ++i )
{
Person per = (Person) pV.elementAt(i);
String editURL =
bReq.getServletPath()
+ "/EditPerson/"
+ per.getId();
if ( (i % 3) == 0 )
{
cW.println( "<tr bgcolor=\"#F0F0F0\">" );
}
else
{
cW.println( "<tr>" );
}
cW.print ( "<td><A HREF=\"" );
cW.print ( editURL );
cW.println( "\">" );
cW.println( per.getId() );
cW.println( "</td>" );
cW.println( "<td>" + per.getType() + "</td>" );
cW.print ( "<td><A HREF=\"" );
cW.print ( editURL );
cW.println( "\">" );
cW.println( per.getName() );
cW.println( "</td>" );
cW.println( "<td>" + per.getEmail() + "</td>" );
cW.println( "<td>" + per.getOrganization() + "</td>" );
cW.println( "</tr>" );
}
cW.println( "</table>" );
this.sendCommonTrailer( bReq, cW );
cW.close();
}
public void
sendEditPersonForm
( BugRatRequest bReq, PrintWriter cW,
int personId, boolean committed )
throws IOException
{
String propValue = "";
Person p = null;
boolean newAccountRequiresAdmin = bReq.getNewUserRequiresAdmin();
try { p = Person.getPerson( personId ); }
catch ( DBIException ex )
{ p = null; }
if ( p == null )
{
cW.println( "<h2>Create New Person</h2>" );
cW.println( "Fill in the person's information " );
cW.println( "and click the Save button." );
}
else
{
cW.println( "<h2>" );
if ( committed )
{
cW.println( "Committed " );
}
else
{
cW.println( "Edit " );
}
cW.println( "Person #" + p.getId() + "</h2>" );
cW.println( "Use this form to edit the user's information." );
cW.println( "Click the Save button to commit your changes." );
}
cW.print ( "<FORM method=\"POST\" action=\"" );
if ( newAccountRequiresAdmin )
{
cW.print ( bReq.getAdminServletPath() );
}
else
{
cW.print ( bReq.getServletPath() );
}
cW.println( "/CommitPerson\">" );
String idStr = (p == null) ? "0" : ( "" + p.getId() );
cW.print ( "<INPUT type=\"hidden\"" );
cW.println( " name=\"id\" value=\"" + idStr + "\">" );
cW.println( "<table border=\"0\" callspacing=\"3\">" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>Full Name:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"name\" value=\"" );
cW.print ( (p == null) ? "" : p.getName() );
cW.println( "\">" );
cW.println( "<td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>EMail Address:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"email\" value=\"" );
cW.print ( (p == null) ? "" : p.getEmail() );
cW.println( "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
if ( p == null )
{
// New users MUST be 'Anonymous' until Admin edits them....
cW.print ( "<INPUT type=\"hidden\" name=\"type\" value=\"" );
cW.print (PERSON_ANON );
cW.println( "\">" );
}
else
{
// Otherwise, let the type be editted...
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>Category:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
// UNDONE - These values should come from dbConfig!
String[] types =
{
PERSON_ADMIN,
PERSON_ANON,
PERSON_USER
};
String[] names =
{
"Administrator",
"Public User",
"BugRat User"
};
cW.println( "<SELECT name=\"type\" size=\"1\">" );
for ( int i = 0 ; i < types.length ; ++i )
{
cW.print( "<OPTION value=\"" );
cW.print( types[i] );
cW.print( "\"" );
if ( p != null && p.getType().equals( types[i] ) )
{
cW.print( " SELECTED" );
}
cW.print( ">" );
cW.println( names[i] );
}
cW.println( "</SELECT>" );
cW.println( "</td>" );
cW.println( "</tr>" );
}
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>Home Page URL:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"url\" value=\"" );
cW.print ( (p == null) ? "" : p.getURL() );
cW.println( "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>Organization:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"org\" value=\"" );
cW.print ( (p == null) ? "" : p.getOrganization() );
cW.println( "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>Phone:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"phone\" value=\"" );
cW.print ( (p == null) ? "" : p.getPhone() );
cW.println( "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td>" );
cW.println( "<strong>FAX:</strong>" );
cW.println( "</td>" );
cW.println( "<td>" );
cW.print ( "<INPUT type=\"textfield\" size=\"48\"" );
cW.print ( " name=\"fax\" value=\"" );
cW.print ( (p == null) ? "" : p.getFAX() );
cW.println( "\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td colspan=\"2\" align=\"center\">" );
cW.print ( "<INPUT type=\"submit\"" );
cW.print ( " name=\"submit\" value=\"Save Person\">" );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "</FORM>" );
}
private boolean
isEmptyParameter( String[] parm )
{
return
( parm == null
|| parm.length == 0
|| parm[0].length() == 0 );
}
}