Package org.gjt.bugrat.text

Source Code of org.gjt.bugrat.text.BugFormatter

package org.gjt.bugrat.text;

import java.io.PrintWriter;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;

import org.gjt.bugrat.db.Bug;
import org.gjt.bugrat.db.DBConfig;
import org.gjt.bugrat.db.Description;
import org.gjt.bugrat.db.EnvDescription;
import org.gjt.bugrat.servlet.BugRatRequest;


public
class    BugFormatter
extends    BugRatFormatter
  {
  protected SimpleDateFormat    dateFmt;
  protected DBConfig        dbConfig;

  public
  BugFormatter( DBConfig config, SimpleDateFormat dateFmt )
    {
    super();
    this.dateFmt = dateFmt;
    this.dbConfig = config;
    }

  private void
  formatText(
      Bug bug, BugRatRequest bReq,
      PrintWriter cW, boolean absURLs )
    {
    cW.print  ( "Project: " );
    cW.println( this.dbConfig.getProjectName( bug.getProject() ) );

    cW.print  ( "Category: " );
    cW.println
      ( this.dbConfig.getCategoryName
        ( bug.getProject(), bug.getCategory() ) );

    cW.print  ( "SubCategory: " );
    cW.println
      ( this.dbConfig.getSubCategoryName
        ( bug.getProject(), bug.getCategory(),
          bug.getSubCategory() ) );

    cW.print  ( "Class: " );
    cW.println( this.dbConfig.getClassName( bug.getBugClass() ) );

    cW.print  ( "State: " );
    cW.println( this.dbConfig.getStateName( bug.getState() ) );

    cW.print  ( "Priority: " );   
    cW.println( this.dbConfig.getPriorityName( bug.getPriority() ) );

    cW.print  ( "Severity: " );
    cW.println( this.dbConfig.getSeverityName( bug.getSeverity() ) );

    cW.print  ( "Confidence: " );
    cW.println( this.dbConfig.getConfidenceName( bug.getConfidence() ) );

    EnvDescription eDesc = bug.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( bug.getDescription().getSynopsis() );

    cW.println( "" );
    cW.println( "Description:" );
    cW.println( bug.getDescription().getDescription() );
    }

  private void
  formatHTML(
      Bug bug, BugRatRequest bReq,
      PrintWriter cW, boolean absURLs )
    {
    String contextStr =
      ( absURLs ? bReq.getServletUrlPrefix() : "" )
        + bReq.getServletContext();

    Description desc = bug.getDescription();
    EnvDescription eDesc = bug.getEnvDescription();
    Description repro = bug.getReproDescription();
    Description around = bug.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( bug.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
        ( bug.getProject(), bug.getCategory() ) );

    cW.println( "</td>" );
    cW.println( "<td width=\"50%\">" );

    cW.println( "<strong>SubCategory:</strong>" );
    cW.println
      ( this.dbConfig.getSubCategoryName
        ( bug.getProject(), bug.getCategory(),
          bug.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( bug.getBugClass() ) );

    cW.println( "</td>" );
    cW.println( "<td width=\"50%\">" );

    cW.println( "<strong>State:</strong>" );
    cW.println( this.dbConfig.getStateName( bug.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( bug.getPriority() ) );

    cW.println( "</td>" );
    cW.println( "<td width=\"50%\">" );

    cW.println( "<strong>Severity:</strong>" );
    cW.println( this.dbConfig.getSeverityName( bug.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( bug.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>" );

    StringBuffer openDateStr = new StringBuffer();
    FieldPosition openPos = new FieldPosition(0);
    this.dateFmt.format( bug.getOpenDate(), openDateStr, openPos );

    cW.println( "<strong>Date Opened:</strong>" );
    cW.println( openDateStr.toString() );
    cW.println( "<br>" );

    StringBuffer closeDateStr = new StringBuffer();
    if ( bug.getCloseDate() == null )
      {
      closeDateStr.append( "Not closed." );
      }
    else
      {
      FieldPosition closePos = new FieldPosition(0);
      this.dateFmt.format( bug.getCloseDate(), closeDateStr, closePos );
      }

    cW.println( "<strong>Date Closed:</strong>" );
    cW.println( closeDateStr.toString() );
    cW.println( "<br>" );

    cW.println( "<strong>Responsible:</strong>" );

    String responsible = null;
    if ( bug.getResponsible() == 0 )
      {
      responsible = "Not assigned";
      }
    else
      {
      responsible =
        this.dbConfig.formatPerson( bug.getResponsible() );
      }

    cW.println( responsible );

    cW.println( "<p>" );
    cW.println( "<DL>" );
    cW.println( "<DT><strong>Synopsis:</strong>" );
    cW.println( "<DD>" );
    cW.println( bug.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(
      Bug bug, 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( bug, bReq, cW, absURLs );
      }
    else
      {
      this.formatText( bug, bReq, cW, absURLs );
      }
    }
  }
TOP

Related Classes of org.gjt.bugrat.text.BugFormatter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.