package org.gjt.bugrat.text;
import java.io.PrintWriter;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import org.gjt.bugrat.db.DBConfig;
import org.gjt.bugrat.db.Report;
import org.gjt.bugrat.db.Description;
import org.gjt.bugrat.db.EnvDescription;
import org.gjt.bugrat.servlet.BugRatRequest;
public
class ReportFormatter
extends BugRatFormatter
{
protected SimpleDateFormat dateFmt;
protected DBConfig dbConfig;
public
ReportFormatter( DBConfig config, SimpleDateFormat dateFmt )
{
super();
this.dateFmt = dateFmt;
this.dbConfig = config;
}
private void
formatText(
Report rep, BugRatRequest bReq,
PrintWriter cW, boolean absURLs )
{
cW.print ( "Project: " );
cW.println( this.dbConfig.getProjectName( rep.getProject() ) );
cW.print ( "Category: " );
cW.println
( this.dbConfig.getCategoryName
( rep.getProject(), rep.getCategory() ) );
cW.print ( "SubCategory: " );
cW.println
( this.dbConfig.getSubCategoryName
( rep.getProject(), rep.getCategory(),
rep.getSubCategory() ) );
cW.print ( "Class: " );
cW.println( this.dbConfig.getClassName( rep.getReportClass() ) );
cW.print ( "State: " );
cW.println( this.dbConfig.getStateName( rep.getState() ) );
cW.print ( "Priority: " );
cW.println( this.dbConfig.getPriorityName( rep.getPriority() ) );
cW.print ( "Severity: " );
cW.println( this.dbConfig.getSeverityName( rep.getSeverity() ) );
cW.print ( "Confidence: " );
cW.println( this.dbConfig.getConfidenceName( rep.getConfidence() ) );
EnvDescription eDesc = rep.getEnvDescription();
if ( eDesc != null )
{
cW.println( "Environment: " );
cW.print ( " Release: " );
cW.println( eDesc.getRelease() );
cW.print ( " JVM Release: " );
cW.println( eDesc.getJVM() );
cW.print ( " Operating System: " );
cW.println( eDesc.getOS() );
cW.print ( " OS Release: " );
cW.println( eDesc.getOSRelease() );
cW.print ( " Platform: " );
cW.println( eDesc.getPlatform() );
}
cW.println( "" );
cW.println( "Synopsis: " );
cW.println( rep.getDescription().getSynopsis() );
cW.println( "" );
cW.println( "Description:" );
cW.println( rep.getDescription().getDescription() );
}
private void
formatHTML(
Report rep, BugRatRequest bReq,
PrintWriter cW, boolean absURLs )
{
String contextStr =
( absURLs ? bReq.getServletUrlPrefix() : "" )
+ bReq.getServletContext();
Description desc = rep.getDescription();
EnvDescription eDesc = rep.getEnvDescription();
Description repro = rep.getReproDescription();
Description around = rep.getAroundDescription();
cW.println( "<table width=\"100%\" cellspacing=\"0\"" );
cW.println( " cellpadding=\"0\">" );
cW.println( "<tr>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Project:</strong>" );
cW.println( this.dbConfig.getProjectName( rep.getProject() ) );
cW.println( "</td>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Release:</strong>" );
cW.println( (eDesc == null)
? "Unknown" : eDesc.getRelease() );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Category:</strong>" );
cW.println( this.dbConfig.getCategoryName
( rep.getProject(), rep.getCategory() ) );
cW.println( "</td>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>SubCategory:</strong>" );
cW.println
( this.dbConfig.getSubCategoryName
( rep.getProject(), rep.getCategory(),
rep.getSubCategory() ) );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Class:</strong>" );
cW.println( this.dbConfig.getClassName( rep.getReportClass() ) );
cW.println( "</td>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>State:</strong>" );
cW.println( this.dbConfig.getStateName( rep.getState() ) );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Priority:</strong>" );
cW.println( this.dbConfig.getPriorityName( rep.getPriority() ) );
cW.println( "</td>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Severity:</strong>" );
cW.println( this.dbConfig.getSeverityName( rep.getSeverity() ) );
cW.println( "</td>" );
cW.println( "</tr>" );
cW.println( "<tr>" );
cW.println( "<td width=\"50%\">" );
cW.println( "<strong>Confidence:</strong>" );
cW.println( this.dbConfig.getConfidenceName( rep.getConfidence() ) );
cW.println( "<br>" );
cW.println( "</td>" );
if ( desc.hasEmail() )
{
cW.println( "<td width=\"50%\">" );
cW.print ( "<a href=\"" );
cW.print ( contextStr );
cW.print ( "/" );
cW.print ( bReq.getViewerServletName() );
cW.print ( "/ShowEmail/" );
cW.println( desc.getEmailId() );
cW.println( "\">" );
cW.println( "<strong>" );
cW.println( "View Original Email" );
cW.println( "</strong>" );
cW.println( "</a>" );
cW.println( "</td>" );
}
cW.println( "</tr>" );
cW.println( "</table>" );
cW.println( "<p>" );
cW.println( "<strong>Submitter:</strong>" );
cW.println( this.dbConfig.formatPerson( rep.getSubmitter() ) );
cW.println( "<br>" );
StringBuffer dateStr = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
this.dateFmt.format( rep.getSubmitted(), dateStr, pos );
cW.println( "<strong>Date Submitted:</strong>" );
cW.println( dateStr.toString() );
cW.println( "<br>" );
cW.println( "<strong>Responsible:</strong>" );
String responsible = null;
if ( rep.getResponsible() == 0 )
{
responsible = "Not assigned";
}
else
{
responsible =
this.dbConfig.formatPerson( rep.getResponsible() );
}
cW.println( responsible );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>Synopsis:</strong>" );
cW.println( "<DD>" );
cW.println( rep.getDescription().getSynopsis() );
cW.println( "</DL>" );
if ( eDesc == null )
{
cW.println( "<strong>Environment:</strong>" );
cW.println( "Environment Not Defined" );
}
else
{
cW.println( "<DL>" );
cW.print ( "<DT><strong> " );
cW.print ( "Environment:</strong> " );
cW.println( "(jvm, os, osrel, platform)" );
cW.println( "<DD>" );
cW.print ( eDesc.getJVM() );
cW.print ( ", " );
cW.print ( eDesc.getOS() );
cW.print ( ", " );
cW.print ( eDesc.getOSRelease() );
cW.print ( ", " );
cW.println( eDesc.getPlatform() );
cW.println( "</DL>" );
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>Additional Environment Description:</strong>" );
cW.println( "<DD>" );
cW.println( eDesc.getDescription() );
cW.println( "</DL>" );
}
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>Report Description:</strong>" );
cW.println( "<DD>" );
cW.println( desc.getDescription() );
cW.println( "</DL>" );
if ( repro != null )
{
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>How To Reproduce:</strong>" );
cW.println( "<DD>" );
cW.println( repro.getDescription() );
cW.println( "</DL>" );
}
if ( around != null )
{
cW.println( "<p>" );
cW.println( "<DL>" );
cW.println( "<DT><strong>Workaround:</strong>" );
cW.println( "<DD>" );
cW.println( around.getDescription() );
cW.println( "</DL>" );
}
}
public void
format(
Report rep, BugRatRequest bReq,
PrintWriter cW, String mimeType, boolean absURLs )
{
// UNDONE - clean up this code to use proper MIME classes.
if ( mimeType.equalsIgnoreCase( "text/html" ) )
{
this.formatHTML( rep, bReq, cW, absURLs );
}
else
{
this.formatText( rep, bReq, cW, absURLs );
}
}
}