try {
outputStream = new ByteArrayOutputStream();
} catch ( Exception e ) {
getLogger().error( e );
}
ReportSpec reportSpec = new ReportSpec();
reportSpec.setReportName( reportName );
reportSpec.setHorizontalOffset( horizontalOffset );
reportSpec.setIncludeSrc( getPath() );
reportSpec.setQuery( "no query" ); //$NON-NLS-1$
reportSpec.setReportSpecChoice( new ReportSpecChoice() );
reportSpec.getReportSpecChoice().setJndiSource( "SampleData" ); //$NON-NLS-1$
reportSpec.setCalculateGrandTotals( createGrandTotals );
reportSpec.setTopMargin( 10 );
reportSpec.setBottomMargin( 10 );
reportSpec.setLeftMargin( 10 );
reportSpec.setRightMargin( 10 );
reportSpec.setUseRowBanding( createRowBanding );
reportSpec.setColumnHeaderGap( columnHeaderGap );
if ( rowBandingColor != null ) {
reportSpec.setRowBandingColor( rowBandingColor );
}
if ( columnHeaderBackgroundColor != null ) {
reportSpec.setColumnHeaderBackgroundColor( columnHeaderBackgroundColor );
}
if ( columnHeaderForegroundColor != null ) {
reportSpec.setColumnHeaderFontColor( columnHeaderForegroundColor );
}
if ( columnHeaderFontFace != null ) {
reportSpec.setColumnHeaderFontName( columnHeaderFontFace );
}
if ( columnHeaderFontSize != null ) {
reportSpec.setColumnHeaderFontSize( Integer.parseInt( columnHeaderFontSize ) );
}
reportSpec.setOrientation( orientation );
Object[] colHeaders = resultSet.getMetaData().getColumnHeaders()[0];
int totalWidth = reportSpec.getLeftMargin() + reportSpec.getRightMargin();
List groupsList = new LinkedList();
List details = new LinkedList();
// leading spacer
if ( spacerWidth > 0 ) {
Field spacer = new Field();
spacer.setName( "" ); //$NON-NLS-1$
spacer.setDisplayName( "" ); //$NON-NLS-1$
spacer.setType( Types.VARCHAR );
spacer.setFormat( "" ); //$NON-NLS-1$
spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
spacer.setWidth( new BigDecimal( spacerWidth ) );
spacer.setWidthLocked( true );
totalWidth += spacerWidth;
spacer.setExpression( "none" ); //$NON-NLS-1$
spacer.setIsWidthPercent( false );
spacer.setIsDetail( true );
reportSpec.addField( spacer );
}
for ( int i = 0; i < colHeaders.length; i++ ) {
// System.out.println("header [" + i + "] = " + colHeaders[i]);
Class typeClass = null;
for ( int j = 0; j < resultSet.getRowCount(); j++ ) {
Object value = resultSet.getValueAt( j, i );
if ( ( value != null ) && !value.toString().equals( "" ) ) { //$NON-NLS-1$
typeClass = value.getClass();
}
}
String columnName = colHeaders[i].toString();
Field f = new Field();
f.setName( columnName );
f.setNullString( getNullString() );
if ( isGroup( columnName ) ) {
f.setDisplayName( getGroupLabel( columnName, i ) );
} else if ( i < displayNames.length ) {
f.setDisplayName( displayNames[i] );
} else {
f.setDisplayName( columnName );
}
f.setIsWidthPercent( false );
f.setWidth( new BigDecimal( getWidth( columnName ) ) );
f.setWidthLocked( true );
f.setIsDetail( !isGroup( columnName ) );
if ( f.getIsDetail() ) {
details.add( f );
} else {
groupsList.add( f );
}
f.setBackgroundColor( "#FFFFFF" ); //$NON-NLS-1$
f.setType( getType( typeClass ) );
if ( ( itemHides == null ) || ( itemHides.length == 0 ) ) {
f.setUseItemHide( getType( typeClass ) == Types.NUMERIC ? false : true );
} else {
f.setUseItemHide( useItemHide( columnName ) );
}
f.setVerticalAlignment( "middle" ); //$NON-NLS-1$
f.setFormat( getColumnFormat( columnName ) );
String alignment = getColumnAlignment( columnName );
if ( alignment != null ) {
f.setHorizontalAlignment( alignment );
} else {
if ( f.getIsDetail() && ( f.getType() == Types.NUMERIC ) ) {
f.setHorizontalAlignment( "right" ); //$NON-NLS-1$
}
}
if ( f.getIsDetail() && ( f.getType() == Types.NUMERIC ) ) {
f.setExpression( "sum" ); //$NON-NLS-1$
} else {
f.setExpression( "none" ); //$NON-NLS-1$
}
f.setCalculateGroupTotals( createSubTotals );
reportSpec.addField( f );
if ( ( spacerWidth > 0 ) && f.getIsDetail() ) {
// spacer
Field spacer = new Field();
spacer.setName( "" ); //$NON-NLS-1$
spacer.setDisplayName( "" ); //$NON-NLS-1$
spacer.setType( Types.VARCHAR );
spacer.setFormat( "" ); //$NON-NLS-1$
spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
spacer.setWidth( new BigDecimal( spacerWidth ) );
spacer.setWidthLocked( true );
totalWidth += spacerWidth;
spacer.setExpression( "none" ); //$NON-NLS-1$
spacer.setIsWidthPercent( false );
spacer.setIsDetail( true );
reportSpec.addField( spacer );
}
}
for ( int i = 0; i < details.size(); i++ ) {
Field f = (Field) details.get( i );
totalWidth += f.getWidth().intValue();
}
if ( createTotalColumn ) {
Field f = new Field();
f.setName( "TOTAL_COLUMN" ); //$NON-NLS-1$
f.setDisplayName( totalColumnName );
f.setType( Types.NUMERIC );
f.setFormat( totalColumnFormat );
f.setHorizontalAlignment( "right" ); //$NON-NLS-1$
f.setVerticalAlignment( "middle" ); //$NON-NLS-1$
f.setWidth( new BigDecimal( totalColumnWidth ) );
f.setWidthLocked( true );
f.setExpression( "sum" ); //$NON-NLS-1$
f.setIsWidthPercent( false );
f.setIsDetail( true );
reportSpec.addField( f );
totalWidth += totalColumnWidth;
if ( spacerWidth > 0 ) {
// spacer
Field spacer = new Field();
spacer.setName( "" ); //$NON-NLS-1$
spacer.setDisplayName( "" ); //$NON-NLS-1$
spacer.setType( Types.VARCHAR );
spacer.setFormat( "" ); //$NON-NLS-1$
spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
spacer.setWidth( new BigDecimal( spacerWidth ) );
spacer.setWidthLocked( true );
totalWidth += spacerWidth;
spacer.setExpression( "none" ); //$NON-NLS-1$
spacer.setIsWidthPercent( false );
spacer.setIsDetail( true );
reportSpec.addField( spacer );
}
}
try {
reportSpec.setUseCustomPageFormat( true );
int width = 612;
int height = 792;
if ( orientation.equalsIgnoreCase( "landscape" ) ) { //$NON-NLS-1$
width = height;
height = 612;
}
// w totalWidth
// - = ------------
// h scaledHeight
int scaledHeight = ( height * totalWidth ) / width;
if ( orientation.equalsIgnoreCase( "landscape" ) ) { //$NON-NLS-1$
reportSpec.setCustomPageFormatHeight( totalWidth );
reportSpec.setCustomPageFormatWidth( scaledHeight );
ReportGenerationUtility.createJFreeReportXML( reportSpec, outputStream, scaledHeight, totalWidth,
createTotalColumn, totalColumnName, totalColumnWidth, spacerWidth );
} else {
reportSpec.setCustomPageFormatHeight( scaledHeight );
reportSpec.setCustomPageFormatWidth( totalWidth );
ReportGenerationUtility.createJFreeReportXML( reportSpec, outputStream, totalWidth, scaledHeight,
createTotalColumn, totalColumnName, totalColumnWidth, spacerWidth );
}
} catch ( Exception e ) {
//ignore