Java Code Examples for org.pentaho.reporting.libraries.resourceloader.ResourceManager#registerDefaults()

The following examples show how to use org.pentaho.reporting.libraries.resourceloader.ResourceManager#registerDefaults() . 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: Prd3431IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testAsExcelOutput() throws ResourceException, ReportProcessingException, IOException, SAXException,
  ParserConfigurationException, InvalidFormatException {
  final URL url = getClass().getResource( "Prd-3431.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  final MemoryByteArrayOutputStream mbos = new MemoryByteArrayOutputStream();
  ExcelReportUtil.createXLS( report, new NoCloseOutputStream( mbos ) );

  final ByteArrayInputStream bin = new ByteArrayInputStream( mbos.getRaw(), 0, mbos.getLength() );
  final Workbook workbook = WorkbookFactory.create( bin );
  assertEquals( 4, workbook.getNumberOfSheets() );
  assertEquals( "Summary", workbook.getSheetAt( 0 ).getSheetName() );
  assertEquals( "AuthorPublisher A", workbook.getSheetAt( 1 ).getSheetName() );
  assertEquals( "AuthorPublisher B", workbook.getSheetAt( 2 ).getSheetName() );
  assertEquals( "AuthorPublisher C", workbook.getSheetAt( 3 ).getSheetName() );
}
 
Example 2
Source File: SubBandParsingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testParsing() throws Exception {
  final URL url = getClass().getResource( "subband.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final Band band = report.getReportHeader();
  assertEquals( 2, band.getElementCount() );
  for ( int i = 0; i < 2; i++ ) {
    final Band subband = (Band) band.getElement( i );
    assertEquals( 2, subband.getElementCount() );
    for ( int x = 0; x < 2; x++ ) {
      final Band bandLowest = (Band) subband.getElement( x );
      assertTrue( bandLowest.getElementCount() > 0 );
    }
  }
}
 
Example 3
Source File: ParseDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void main(String[] args) throws ResourceException
{
  ClassicEngineBoot.getInstance().start();

  final File text = new File("/home/src/pentaho-report-designer/rd-1.7-rc1/samples/Invoice.report");
  final ResourceManager resManager = new ResourceManager();
  resManager.registerDefaults();

  final Resource directly = resManager.createDirectly(text, MasterReport.class);
  final MasterReport resource = (MasterReport) directly.getResource();

  final PreviewDialog dialog = new PreviewDialog(resource);
  dialog.setModal(true);
  dialog.pack();
  dialog.setVisible(true);
  System.exit(0);
}
 
Example 4
Source File: SerializationGoldTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testResourceLabelAfterSerialization() throws Exception {
  final File url = GoldTestBase.locateGoldenSampleReport( "Prd-3514.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport org = (MasterReport) directly.getResource();

  final MasterReport report = postProcess( org );

  RelationalGroup relationalGroup = report.getRelationalGroup( 0 );
  GroupHeader header = relationalGroup.getHeader();
  Band band = (Band) header.getElement( 0 );
  Element element = band.getElement( 1 );
  assertTrue( element.getElementType() instanceof ResourceMessageType );
  element.setName( "DateTitleField" );
  //    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1);
  LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, header, false, false );
  RenderNode dateTitleField = MatchFactory.findElementByName( logicalPageBox, "DateTitleField" );
  assertNotNull( dateTitleField );
  //    ModelPrinter.INSTANCE.print(logicalPageBox);
}
 
Example 5
Source File: Prd4625Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBugExists() throws Exception {
  final URL source = getClass().getResource( "Prd-4625.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final MasterReport report = (MasterReport) mgr.createDirectly( source, MasterReport.class ).getResource();

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

  // Wanna see how the model looks like? Uncomment the following line ..
  // ModelPrinter.INSTANCE.print(logicalPageBox);

  final RenderNode[] elementsByNodeType =
    MatchFactory.findElementsByElementType( logicalPageBox, new LegacyChartType() );
  assertEquals( 2, elementsByNodeType.length );
}
 
Example 6
Source File: TableToHtmlExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testExportToXml() throws Exception {
  final URL url = getClass().getResource( "Prd-3931.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 4, 0, 0 ) );

  final LogicalPageBox pageBox = DebugReportRunner.layoutPage( report, 0 );
  // ModelPrinter.INSTANCE.print(pageBox);
}
 
Example 7
Source File: Prd3857Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGoldRun3() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "trafficlighting.xml" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  report.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 3, 8, 0 ) );

  DebugReportRunner.createXmlFlow( report );
}
 
Example 8
Source File: VerticalAlignmentFailureIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFontDoesNotCrash() throws Exception {
  final URL url = getClass().getResource( "vertical-alignment-failure.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();

  DebugReportRunner.executeAll( resource );

}
 
Example 9
Source File: Prd3620IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testHeadless() throws Exception {
  final URL url = getClass().getResource( "Prd-3620-small.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  DebugReportRunner.createXLS( report );
}
 
Example 10
Source File: TableToHtmlExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testHtmlExportFullComplexText() throws Exception {
  final URL url = getClass().getResource( "Prd-3931.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );
  report.getReportConfiguration()
      .setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "true" );

  final Group rootGroup = report.getRootGroup();
  assertTrue( rootGroup instanceof CrosstabGroup );

  final CrosstabGroup ct = (CrosstabGroup) rootGroup;
  ct.setPrintColumnTitleHeader( true );
  ct.setPrintDetailsHeader( false );

  final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream();
  HtmlReportUtil.createStreamHTML( report, outputStream );

  final String htmlText = new String( outputStream.toByteArray(), "UTF-8" );
  DebugLog.log( htmlText );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2003</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2004</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2005</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Product Line</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Market</td>" ) );
}
 
Example 11
Source File: EmployeeListingWaqrIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFailure() throws Exception {
  final URL target = EmployeeListingWaqrIT.class.getResource( "EmployeeListing.waqr.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setDataFactory( new TableDataFactory( "default", new DefaultTableModel( 1, 1 ) ) );
  DebugReportRunner.executeAll( report );

}
 
Example 12
Source File: Prd3857IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testRowBoxesEstablishOwnBlockContext() throws Exception {
  // this report defines that the group as well as all bands within that group are row-layout.
  // therefore the two itembands end on the same row.

  // The itemband did not define a width, not even a 100% width, and thus ends with a width of auto/zero.
  // therefore the itemband shrinks to the minimal size that still encloses all elements.
  // the elements that have percentage width are resolved against the block context.
  // A band without a width defined (the itemband!), does not establish an own block-context, so it
  // takes the block context of the parent, or as fallback: page.

  final File file = GoldTestBase.locateGoldenSampleReport( "Prd-3479.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );
  final RenderNode[] itembands = MatchFactory.findElementsByElementType( logicalPageBox, ItemBandType.INSTANCE );

  assertEquals( 2, itembands.length );
  assertEquals( 48208843, itembands[0].getWidth() );
  assertEquals( 48208843, itembands[1].getWidth() );
  assertEquals( 48208843, itembands[1].getX() );
}
 
Example 13
Source File: Prd4125Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testDesignTime() throws ResourceException {
  URL resource = getClass().getResource( "Prd-4125.prpt" );
  ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  MasterReport report = (MasterReport) mgr.createDirectly( resource, MasterReport.class ).getResource();

  DesignTimeDataSchemaModel model = new DesignTimeDataSchemaModel( report );
  String[] columnNames = model.getColumnNames();
  assertEquals( 26, columnNames.length );
}
 
Example 14
Source File: MultipageExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSecondPageFormatting() throws Exception {
  final URL target = MultipageExportIT.class.getResource( "multipage.prpt" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  // DebugReportRunner.createXLS(report);
}
 
Example 15
Source File: LayoutValidationUtils.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
static List<LogicalPageBox> loadPages( String file, int expectedPages ) throws Exception {
  ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  Resource resource = resourceManager
    .createDirectly( LayoutValidationUtils.class.getResource( "pagination/" + file ), MasterReport.class );
  MasterReport report = (MasterReport) resource.getResource();

  int[] pages = new int[ expectedPages ];
  for ( int i = 0; i < expectedPages; i++ ) {
    pages[ i ] = i;
  }
  return DebugReportRunner.layoutPagesStrict( report, expectedPages, pages );
}
 
Example 16
Source File: Prd3857IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGoldRun3857Visually() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "Prd-3857-001.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  // DebugReportRunner.createXmlFlow(report);
  DebugReportRunner.showDialog( report );
}
 
Example 17
Source File: Prd3319IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLoadSaveFromDisk() throws Exception {
  final ResourceKey key = createImageKey();

  final Element element = new Element();
  element.setElementType( new ContentType() );
  element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, key );
  // .. save it.
  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( element );

  saveReport( report, new File( "bin/test-tmp/prd-3319-load-save-disk-1.prpt" ) );

  // load it to establish the context in all resource-keys ..
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource resource =
      mgr.createDirectly( new File( "bin/test-tmp/prd-3319-load-save-disk-1.prpt" ), MasterReport.class );

  // save it once, that changes the bundle ...
  final MasterReport report2 = (MasterReport) resource.getResource();
  saveReport( report2, new File( "bin/test-tmp/prd-3319-load-save-disk-2.prpt" ) );
  // save it twice, that triggers the crash...
  saveReport( report2, new File( "bin/test-tmp/prd-3319-load-save-disk-2.prpt" ) );

  final ProcessingContext processingContext = new DefaultProcessingContext();
  final DebugExpressionRuntime runtime = new DebugExpressionRuntime( new DefaultTableModel(), 0, processingContext );

  final Element reportElement = report2.getReportHeader().getElement( 0 );
  Object attribute = reportElement.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE );

  assertTrue( attribute instanceof ResourceKey );
  ResourceKey atKey = (ResourceKey) attribute;
  assertEquals( "http://127.0.0.1:65535/image.jpg", atKey.getIdentifierAsString() );
}
 
Example 18
Source File: DebugReportRunner.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport parseGoldenSampleReport( final String name ) throws ResourceException {
  final File file = GoldTestBase.locateGoldenSampleReport( name );
  if ( file == null ) {
    throw new ResourceException( "Unable to locate report '" + name + "' in the golden samples." );
  }

  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  return (MasterReport) mgr.createDirectly( file, MasterReport.class ).getResource();
}
 
Example 19
Source File: Prd3857IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGoldRun() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "Prd-3239.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 3, 8, 0 ) );

  DebugReportRunner.createXmlFlow( report );
  DebugReportRunner.showDialog( report );
}
 
Example 20
Source File: Prd3159IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLoadSaveFromDisk() throws Exception {
  ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource orgRes = mgr.createDirectly( Prd3159IT.class.getResource( "Prd-3159.prpt" ), MasterReport.class );
  // .. save it.
  final MasterReport report = (MasterReport) orgRes.getResource();
  saveReport( report, new File( "bin/test-tmp/prd-3159-load-save-disk-1.prpt" ) );

  // load it to establish the context in all resource-keys ..
  final Resource resource =
      mgr.createDirectly( new File( "bin/test-tmp/prd-3159-load-save-disk-1.prpt" ), MasterReport.class );

  // save it once, that changes the bundle ...
  final MasterReport report2 = (MasterReport) resource.getResource();
  saveReport( report2, new File( "bin/test-tmp/prd-3159-load-save-disk-2.prpt" ) );
  // save it twice, that triggers the crash...
  saveReport( report2, new File( "bin/test-tmp/prd-3159-load-save-disk-2.prpt" ) );

  final ProcessingContext processingContext = new DefaultProcessingContext();
  final DebugExpressionRuntime runtime = new DebugExpressionRuntime( new DefaultTableModel(), 0, processingContext );

  final Element reportElement = (Element) report2.getPageHeader().getElement( 4 );
  final Object designValue = reportElement.getElementType().getDesignValue( runtime, reportElement );
  final DefaultImageReference image = (DefaultImageReference) designValue;
  assertEquals( 456, image.getImageWidth() );
  assertEquals( 69, image.getImageHeight() );

}