org.pentaho.reporting.engine.classic.core.MasterReport Java Examples

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeightComputationIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testNestedRows() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  final URL target = LayoutIT.class.getResource( "layout-matrix.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, true );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), true, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  new ValidateRunner().startValidation( logicalPageBox );
}
 
Example #2
Source File: Prd2324IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public byte[] generate( final MasterReport report ) throws ReportProcessingException, IOException {
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  final StreamRepository targetRepository = new StreamRepository( null, outputStream, "report" ); //$NON-NLS-1$
  final ContentLocation targetRoot = targetRepository.getRoot();

  final PageableHtmlOutputProcessor outputProcessor = new PageableHtmlOutputProcessor( report.getConfiguration() );
  final HtmlPrinter printer = new AllItemsHtmlPrinter( report.getResourceManager() );
  printer.setContentWriter( targetRoot, new DefaultNameGenerator( targetRoot, "index", "html" ) ); //$NON-NLS-1$//$NON-NLS-2$
  outputProcessor.setPrinter( printer );

  outputProcessor.setFlowSelector( new ReportPageSelector( 0 ) );
  final PageableReportProcessor proc = new PageableReportProcessor( report, outputProcessor );
  proc.processReport();
  proc.close();

  outputStream.flush();
  outputStream.close();
  return outputStream.toByteArray();
}
 
Example #3
Source File: ParameterReportController.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Invoked when the target of the listener has changed its state.
 *
 * @param e
 *          a ChangeEvent object
 */
public void stateChanged( final ChangeEvent e ) {
  final PreviewPane previewPane = getPreviewPane();
  if ( previewPane == null ) {
    return;
  }
  final ReportParameterValues properties = getControllerPane().getReportParameterValues();
  final MasterReport masterReport = previewPane.getReportJob();
  final ReportParameterValues reportParameters = masterReport.getParameterValues();
  final String[] strings = properties.getColumnNames();
  for ( int i = 0; i < strings.length; i++ ) {
    final String propertyName = strings[i];
    reportParameters.put( propertyName, properties.get( propertyName ) );
  }
  previewPane.setReportJob( masterReport );
}
 
Example #4
Source File: Sample4.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Generates a simple HTML report and returns the HTML output back to the browser
 */
private void generateReport( final HttpServletRequest req, final HttpServletResponse resp ) throws ServletException, IOException {
  // Generate the report definition
  final MasterReport report = createReportDefinition();
  // Run the report and save the HTML output to a byte stream
  resp.setContentType( "text/html" ); // Change to "application/pdf" for PDF output
  OutputStream out = resp.getOutputStream();
  try {
    // Use the HtmlReportUtil to generate the report to a Stream HTML
    HtmlReportUtil.createStreamHTML( report, out );
    //NOTE: Changing this to use PDF is simple:
    // 1. Change the above setContent call to use "application/pdf"
    // 2. Instead of HtmlReportUtil, use the following line:
    // PdfReportUtil.createPDF(report, out)
  } catch ( ReportProcessingException rpe ) {
    rpe.printStackTrace();
  } finally {
    out.close();
  }
}
 
Example #5
Source File: PlainTextExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testExport() throws Exception {
  final URL url = getClass().getResource( "plain-text-export.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  assertNotNull( report );
  final String rdefBeforeFirst = writeReport( report );
  final String utf16 = exportReport( report, "UTF-16" );
  final String rdefAfterFirst = writeReport( report );
  assertEquals( rdefBeforeFirst, rdefAfterFirst );
  final String utf8 = exportReport( report, "UTF-8" );
  assertEquals( utf8, utf16 );
}
 
Example #6
Source File: StyleInheritanceIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testStyleInheritanceOnSubReport() throws Exception {
  SubReport bandedSr = new SubReport();
  bandedSr.getReportHeader().addElement( createLabel( "Banded-SubReport-Header-Label" ) );

  SubReport inlineSr = new SubReport();
  inlineSr.getReportHeader().addElement( createLabel( "Inline-SubReport-Header-Label" ) );

  MasterReport report = new MasterReport();
  report.getReportFooter().addElement( inlineSr );
  report.getReportFooter().addElement( bandedSr );
  report.setStyleDefinition( createStyleDefinition( "selected-font" ) );

  LogicalPageBox box = DebugReportRunner.layoutPage( report, 0 );

  RenderNode inlineElement = MatchFactory.findElementByName( box, "Inline-SubReport-Header-Label" );
  assertNotNull( inlineElement );
  assertEquals( "selected-font", inlineElement.getStyleSheet().getStyleProperty( TextStyleKeys.FONT ) );

  RenderNode bandedElement = MatchFactory.findElementByName( box, "Banded-SubReport-Header-Label" );
  assertNotNull( bandedElement );
  assertEquals( "selected-font", bandedElement.getStyleSheet().getStyleProperty( TextStyleKeys.FONT ) );
}
 
Example #7
Source File: FieldMappingTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testParameterMapping() {
  final PlainParameter parameter = new PlainParameter( "P", Number.class );
  final DefaultParameterDefinition defaultParameterDefinition = new DefaultParameterDefinition();
  defaultParameterDefinition.addParameterDefinition( parameter );

  final MasterReport report = new MasterReport();
  report.setParameterDefinition( defaultParameterDefinition );

  final DefaultDesignTimeContext context = new DefaultDesignTimeContext( report );
  final DataSchema dataSchema = context.getDataSchemaModel().getDataSchema();
  final DataAttributes attributes = dataSchema.getAttributes( "P" );
  final Object o =
      attributes.getMetaAttribute( MetaAttributeNames.Core.NAMESPACE, MetaAttributeNames.Core.TYPE, Class.class,
          new DefaultDataAttributeContext() );
  assertEquals( "Number.class expected", Number.class, o );
}
 
Example #8
Source File: BSFReportPreProcessor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public MasterReport performPreDataProcessing( final MasterReport definition,
    final DefaultFlowController flowController ) throws ReportProcessingException {
  if ( preDataScript == null || language == null || StringUtils.isEmpty( preDataScript, true ) ) {
    return definition;
  }

  try {
    final BSFManager interpreter = new BSFManager();
    interpreter.declareBean( "definition", definition, MasterReport.class ); //$NON-NLS-1$
    interpreter.declareBean( "flowController", flowController, DefaultFlowController.class ); //$NON-NLS-1$
    final Object o = interpreter.eval( getLanguage(), "expression", 1, 1, preDataScript );
    if ( o instanceof MasterReport == false ) {
      throw new ReportDataFactoryException( "Not a MasterReport" );
    }
    return (MasterReport) o; //$NON-NLS-1$

  } catch ( BSFException e ) {
    throw new ReportDataFactoryException( "Failed to initialize the BSF-Framework", e );
  }
}
 
Example #9
Source File: MinChunkWidthIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testMinChunkWidth() throws Exception {
  if ( DebugReportRunner.isSafeToTestComplexText() == false ) {
    return;
  }

  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.setCompatibilityLevel( null );
  basereport.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "true" );

  final URL target = LayoutIT.class.getResource( "min-chunkwidth.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, true );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), true, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485 or 400
  // and that only two lines exist for each
  ModelPrinter.INSTANCE.print( logicalPageBox );
  new ValidateRunner( false, true ).startValidation( logicalPageBox );
}
 
Example #10
Source File: ExportActionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testPerformAction() {
  action = new ExportAction( actionPlugin, previewPane );

  doReturn( false ).when( actionPlugin ).isEnabled();
  action.actionPerformed( null );
  verify( actionPlugin, never() ).performExport( any( MasterReport.class ) );

  doReturn( true ).when( actionPlugin ).isEnabled();
  doReturn( null ).when( previewPane ).getReportJob();
  action.actionPerformed( null );
  verify( actionPlugin, never() ).performExport( any( MasterReport.class ) );

  MasterReport report = mock( MasterReport.class );
  doReturn( report ).when( previewPane ).getReportJob();
  doReturn( report ).when( report ).clone();
  action.actionPerformed( null );
  verify( actionPlugin ).performExport( report );
}
 
Example #11
Source File: ExcelReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void processFlowXls( final MasterReport report, OutputStream fout )
  throws ReportProcessingException, IOException {
  try {
    final FlowExcelOutputProcessor target =
      new FlowExcelOutputProcessor( report.getConfiguration(), fout, report.getResourceManager() );
    target.setUseXlsxFormat( false );
    final FlowReportProcessor reportProcessor = new FlowReportProcessor( report, target );
    reportProcessor.processReport();
    reportProcessor.close();
    fout.close();
    fout = null;
  } finally {
    if ( fout != null ) {
      try {
        fout.close();
      } catch ( Exception e ) {
        // ignore
      }
    }
  }
}
 
Example #12
Source File: Prd5573IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test( expected = ReportProcessingException.class )
public void testReport() throws Exception {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", new DefaultTableModel( 10, 1 ) ) );
  report.setQuery( "query" );

  final Band table = TableTestUtil.createTable( 1, 1, 6, true );
  final ReportElement cell = table.getElement( 0 )
    .getChildElementByType( new BandType() )
    .getChildElementByType( new BandType() );

  cell.getStyle().setStyleProperty( ElementStyleKeys.HEIGHT, 700f );
  table.setName( "table" );
  report.getReportHeader().addElement( table );
  report.getReportHeader().setLayout( "block" );

  DebugReportRunner.layoutPages( report, 0, 1, 2 );

}
 
Example #13
Source File: StraightToPNG.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Reads the report from the specified template file.
 *
 * @param templateURL the template location.
 * @return a report.
 * @throws ParseException if the report could not be parsed.
 */
private MasterReport parseReport(final URL templateURL)
    throws ParseException
{
  try
  {
    final ResourceManager mgr = new ResourceManager();
    final Resource resource = mgr.createDirectly(templateURL, MasterReport.class);
    final MasterReport report = (MasterReport) resource.getResource();
    // this demo adds the image at runtime just to show how this could be
    // done. Usually such images get referenced from the XML itself without
    // using manual coding.
    final URL imageURL = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/demo/opensource/gorilla.jpg", StraightToPNG.class);
    final Image image = Toolkit.getDefaultToolkit().createImage(imageURL);
    final WaitingImageObserver obs = new WaitingImageObserver(image);
    obs.waitImageLoaded();
    report.getParameterValues().put("logo", image);
    return report;
  }
  catch (Exception e)
  {
    throw new ParseException("Failed to parse the report", e);
  }
}
 
Example #14
Source File: Prd4497IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayout() throws Exception {
  // this report should generate only two pages of content. With the bug still active, it generates 3.
  MasterReport report = DebugReportRunner.parseGoldenSampleReport( "Prd-4497.prpt" );
  LogicalPageBox pageBox = DebugReportRunner.layoutPageStrict( report, 2, 0 );
  Assert.assertEquals( StrictGeomUtility.toInternalValue( 784 ), pageBox.getPageEnd() );
  RenderNode[] elementsByNodeType = MatchFactory.findElementsByNodeType( pageBox, LayoutNodeTypes.TYPE_BOX_TABLE );
  Assert.assertEquals( 1, elementsByNodeType.length );
  RenderBox box = (RenderBox) elementsByNodeType[0];

  // ModelPrinter.INSTANCE.print(box);
  RenderNode lastChild = box.getLastChild();

  Assert.assertEquals( StrictGeomUtility.toInternalValue( 804 ), lastChild.getY2() );
  Assert.assertEquals( StrictGeomUtility.toInternalValue( 800 ), box.getCachedHeight() );
  Assert.assertEquals( StrictGeomUtility.toInternalValue( 804 ), box.getHeight() );
}
 
Example #15
Source File: Prd5321IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests the rendering of text in compatibility mode. In this mode elements that do not define an explicit height can
 * be limited in growth to their defined minimum height. This auto-limit only takes place outside of crosstabs (which
 * were not available in pre-5.0 releases) and if the element is contained in a parent band that uses an canvas-layout
 * for its child elements.
 *
 * @throws Exception
 */
@Test
public void testCompatibilityMode() throws Exception {
  URL resource = getClass().getResource( "Prd-5321-2.prpt" );
  ResourceManager mgr = new ResourceManager();
  MasterReport report = (MasterReport) mgr.createDirectly( resource, MasterReport.class ).getResource();
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );
  report.setCompatibilityLevel( ClassicEngineBoot.VERSION_3_8 );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );

  RenderNode[] paragraphs = MatchFactory.findElementsByNodeType( logicalPageBox, LayoutNodeTypes.TYPE_BOX_PARAGRAPH );
  Assert.assertEquals( 4, paragraphs.length );
  for ( RenderNode paragraph : paragraphs ) {
    ParagraphRenderBox pb = (ParagraphRenderBox) paragraph;
    Assert.assertNotNull( pb.getFirstChild() );
    Assert.assertSame( pb.getFirstChild(), pb.getLastChild() );
  }
}
 
Example #16
Source File: PropertyUpdatePreviewHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void attemptPreview()
{
  try
  {
    final MasterReport report = handler.createReport();

    final PreviewDialog frame = new PreviewDialog(report);
    frame.setToolbarFloatable(true);
    frame.setReportController(new DemoReportController());
    frame.pack();
    LibSwingUtil.positionFrameRandomly(frame);
    frame.setVisible(true);
    frame.requestFocus();
  }
  catch (ReportDefinitionException e)
  {
    logger.error("Unable to create the report; report definition contained errors.", e);
    AbstractDemoFrame.showExceptionDialog(handler.getPresentationComponent(), "report.definitionfailure", e);
  }
}
 
Example #17
Source File: XmlTableReportUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void createFlowXML( final MasterReport report, final OutputStream outputStream )
  throws ReportProcessingException {
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( outputStream == null ) {
    throw new NullPointerException();
  }

  final XmlTableOutputProcessor outputProcessor =
      new XmlTableOutputProcessor( outputStream, new XmlTableOutputProcessorMetaData(
          XmlTableOutputProcessorMetaData.PAGINATION_MANUAL ) );
  final FlowReportProcessor sp = new FlowReportProcessor( report, outputProcessor );
  sp.processReport();
  sp.close();
}
 
Example #18
Source File: PreviewHtmlAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
public void actionPerformed( final ActionEvent e ) {
  if ( getActiveContext() == null ) {
    return;
  }

  final MasterReport reportElement = getActiveContext().getContextRoot();
  final Component parent = getReportDesignerContext().getView().getParent();
  final Window window = LibSwingUtil.getWindowAncestor( parent );
  if ( PreviewParametersDialog.process( window, reportElement ) ) {
    final ReportProgressDialog dialog;
    if ( window instanceof JDialog ) {
      dialog = new ReportProgressDialog( (JDialog) window );
    } else if ( window instanceof JFrame ) {
      dialog = new ReportProgressDialog( (JFrame) window );
    } else {
      dialog = new ReportProgressDialog();
    }

    final Thread t = new Thread( new ExportTask( reportElement, dialog ) );
    t.setDaemon( true );
    t.start();
  }
}
 
Example #19
Source File: Pir868Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSample()
  throws ResourceException, ReportProcessingException, ContentProcessingException {
  final URL reportURL = getClass().getResource( "Pir-868.prpt" );
  final ResourceManager mgr = new ResourceManager();
  final MasterReport report = (MasterReport) mgr.createDirectly( reportURL, MasterReport.class ).getResource();

  final LogicalPageBox pageDH = DebugReportRunner.layoutSingleBand( report, report.getDetailsHeader(), false, false );
  final LogicalPageBox pageIB = DebugReportRunner.layoutSingleBand( report, report.getItemBand(), false, false );

  final RenderNode[] dhRow = MatchFactory.findElementsByNodeType( pageDH, LayoutNodeTypes.TYPE_BOX_ROWBOX );
  final RenderNode[] ibRow = MatchFactory.findElementsByNodeType( pageIB, LayoutNodeTypes.TYPE_BOX_ROWBOX );
  ModelPrinter.INSTANCE.print( pageDH );
  ModelPrinter.INSTANCE.print( pageIB );

  assertEquals( 1, dhRow.length );
  assertEquals( 1, ibRow.length );
  assertEquals( dhRow[ 0 ].getWidth(), ibRow[ 0 ].getWidth() );
  assertEquals( dhRow[ 0 ].getX(), ibRow[ 0 ].getX() );
}
 
Example #20
Source File: PaddingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testPaddingFromFile() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final URL target = LayoutIT.class.getResource( "padding-test.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader() );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  // ModelPrinter.print(logicalPageBox);

}
 
Example #21
Source File: ItemMinFunctionIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws Exception {
  final TableModel tableModel = createTableModel();
  final MasterReport report = createReport( tableModel );

  report.addExpression( create( "cell-sum", VALUE, null, COLUMN_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#cell-sum", true, null ) );

  report.addExpression( create( "detail-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#detail-sum", true, COLUMN_DIMENSION_B ) );

  report.addExpression( create( "row-b-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-b-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "row-a-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-a-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "column-a-sum", VALUE, null, COLUMN_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-a-sum", true, null ) );

  report.addExpression( create( "column-b-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-b-sum", true, COLUMN_DIMENSION_B ) );

  DebugReportRunner.execGraphics2D( report );
}
 
Example #22
Source File: Prd3154IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws Exception {
  final URL url = getClass().getResource( "Prd-3154.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  // having images in the header does not add any information, but slows down the report processing.
  PageHeader pageHeader = report.getPageHeader();
  pageHeader.removeElement( pageHeader.getElement( 5 ) );
  pageHeader.removeElement( pageHeader.getElement( 0 ) );

  List<LogicalPageBox> logicalPageBoxes = DebugReportRunner.layoutPages( report, 0, 1 );
  for ( LogicalPageBox box : logicalPageBoxes ) {
    RenderNode[] elementsByElementType = MatchFactory.findElementsByElementType( box, PageHeaderType.INSTANCE );
    Assert.assertEquals( 1, elementsByElementType.length );
    Assert.assertTrue( elementsByElementType[0] instanceof RenderBox );
    RenderBox ph = (RenderBox) elementsByElementType[0];
    Assert.assertEquals( 4, ph.getChildCount() );
  }
}
 
Example #23
Source File: PreviewCsvAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
public void actionPerformed( final ActionEvent e ) {
  if ( getActiveContext() == null ) {
    return;
  }

  final MasterReport reportElement = getActiveContext().getContextRoot();
  final Component parent = getReportDesignerContext().getView().getParent();
  final Window window = LibSwingUtil.getWindowAncestor( parent );
  if ( PreviewParametersDialog.process( window, reportElement ) ) {
    final ReportProgressDialog dialog;
    if ( window instanceof JDialog ) {
      dialog = new ReportProgressDialog( (JDialog) window );
    } else if ( window instanceof JFrame ) {
      dialog = new ReportProgressDialog( (JFrame) window );
    } else {
      dialog = new ReportProgressDialog();
    }

    final Thread t = new Thread( new ExportTask( reportElement, dialog ) );
    t.setDaemon( true );
    t.start();
  }
}
 
Example #24
Source File: NestedRowsIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testNestedRows() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  final URL target = LayoutIT.class.getResource( "nested-rows.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), false, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each

  // This test works on some invalid assumptions and therefore cannot validate properly.
  // within a canvas context there is no inherent size for elements and thus the labels are not visible at all.

  // new ValidateRunner().startValidation(logicalPageBox);
}
 
Example #25
Source File: Prd3930IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLargeTableSingleBandBlockTableExport() throws Exception {
  final MasterReport report = new MasterReport();
  final Band table = TableTestUtil.createTable( 2, 1, 100, true );
  table.setName( "table" );
  table.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 50f );
  report.getReportHeader().addElement( table );
  report.getReportHeader().setLayout( BandStyleKeys.LAYOUT_BLOCK );

  final ByteArrayOutputStream bout = new ByteArrayOutputStream();
  XmlTableReportUtil.createFlowXML( report, bout );
  final String text = bout.toString( "UTF-8" );
  for ( int i = 0; i < 100; i += 1 ) {
    assertTrue( text.contains( "value=\"Data-" + i + "-0" ) );
    assertTrue( text.contains( "value=\"Data-" + i + "-1" ) );
    assertTrue( text.contains( ">Data-" + i + "-0</text>" ) );
    assertTrue( text.contains( ">Data-" + i + "-1</text>" ) );
  }
}
 
Example #26
Source File: ItemSumFunctionIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws Exception {
  final TableModel tableModel = createTableModel();
  final MasterReport report = createReport( tableModel );

  report.addExpression( create( "cell-sum", VALUE, null, COLUMN_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#cell-sum", true, null ) );

  report.addExpression( create( "detail-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#detail-sum", true, COLUMN_DIMENSION_B ) );

  report.addExpression( create( "row-b-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_B ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-b-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "row-a-sum", VALUE, COLUMN_DIMENSION_A, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#row-a-sum", true, COLUMN_DIMENSION_A ) );

  report.addExpression( create( "column-a-sum", VALUE, null, COLUMN_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-a-sum", true, null ) );

  report.addExpression( create( "column-b-sum", VALUE, COLUMN_DIMENSION_B, ROW_DIMENSION_A ) );
  report.addExpression( new ValidateFunctionResultExpression( "#column-b-sum", true, COLUMN_DIMENSION_B ) );

  DebugReportRunner.execGraphics2D( report );
}
 
Example #27
Source File: Prd5321IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testTextRenderingComplex() throws Exception {
  if ( !DebugReportRunner.isSafeToTestComplexText() ) {
    return;
  }
  Assert.assertTrue( DebugReportRunner.isSafeToTestComplexText() );

  URL resource = getClass().getResource( "Prd-5321.prpt" );
  ResourceManager mgr = new ResourceManager();
  MasterReport report = (MasterReport) mgr.createDirectly( resource, MasterReport.class ).getResource();
  report.getReportConfiguration()
      .setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "true" );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );

  Assert.assertEquals( 6,
      MatchFactory.findElementsByNodeType( logicalPageBox, LayoutNodeTypes.TYPE_BOX_PARAGRAPH ).length );
  Assert.assertEquals( 8, MatchFactory
      .findElementsByNodeType( logicalPageBox, LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT ).length );

  TestPdfLogicalPageDrawable pdf = createDrawableForTest( report, logicalPageBox );
  pdf.draw();
  Assert.assertEquals( 8, pdf.textRendering );
}
 
Example #28
Source File: WeirdLayoutIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayout() throws ResourceException, ContentProcessingException, ReportProcessingException {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final URL target = WeirdLayoutIT.class.getResource( "weird-layouting.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final Band band = report.getReportHeader();
  band.setName( "ReportHeader1" );

  DebugReportRunner.layoutSingleBand( report, band, false, true );

}
 
Example #29
Source File: AlignmentRightApiIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a report format by calling API methods directly.
 *
 * @return A report.
 */
public MasterReport createReport() {

  final MasterReport report = new MasterReport();
  report.setName( "Survey Scale Demo Report" );

  // use A4...
  final PageFormatFactory pff = PageFormatFactory.getInstance();
  final Paper paper = pff.createPaper( PageSize.A4 );
  pff.setBorders( paper, PAGE_MARGIN_TOP, PAGE_MARGIN_LEFT, PAGE_MARGIN_BOTTOM, PAGE_MARGIN_RIGHT );
  final PageFormat format = pff.createPageFormat( paper, PageFormat.PORTRAIT );
  report.setPageDefinition( new SimplePageDefinition( format ) );

  setupWatermark( report );
  setupPageHeader( report );
  // // REPORT GROUP /////////////////////////////////////////////////////////////////////////
  setupGroup( report );
  // // ITEM BAND ////////////////////////////////////////////////////////////////////////////
  setupItemBand( report );
  // // PAGE FOOTER //////////////////////////////////////////////////////////////////////////
  setupPageFooter( report );

  report.getParameterValues().put( "RESPONDENT_NAME", "Dave" );
  report.setDataFactory( new TableDataFactory( "default", new SurveyScaleDemoTableModel() ) );
  return report;
}
 
Example #30
Source File: ReportGenerator.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parses the report from a given SAX-InputSource.
 *
 * @param input
 *          the report definition location.
 * @param contentBase
 *          the report's context (used to load content that has been referenced with relative URLs).
 * @return the parsed report.
 * @throws ResourceException
 *           if parsing or loading failed for some reason.
 * @throws IOException
 *           if an IO-related error occurs.
 */
public MasterReport parseReport( final InputSource input, final URL contentBase ) throws IOException,
  ResourceException {
  if ( input.getCharacterStream() != null ) {
    // Sourceforge Bug #1712734. We cannot safely route the character-stream through libloader.
    // Therefore we skip libloader and parse the report directly. This is for backward compatibility,
    // all other xml-based objects will still rely on LibLoader.

    return parseReportDirectly( input, contentBase );
  }

  final byte[] bytes = extractData( input );
  final ResourceManager resourceManager = new ResourceManager();
  final ResourceKey contextKey;
  if ( contentBase != null ) {
    contextKey = resourceManager.createKey( contentBase );
  } else {
    contextKey = null;
  }
  final HashMap map = new HashMap();

  final Iterator it = this.helperObjects.keySet().iterator();
  while ( it.hasNext() ) {
    final String name = (String) it.next();
    map.put( new FactoryParameterKey( name ), helperObjects.get( name ) );
  }

  final ResourceKey key = resourceManager.createKey( bytes, map );
  final Resource resource = resourceManager.create( key, contextKey, MasterReport.class );
  return (MasterReport) resource.getResource();
}