org.pentaho.reporting.libraries.resourceloader.Resource Java Examples

The following examples show how to use org.pentaho.reporting.libraries.resourceloader.Resource. 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: 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 #2
Source File: Prd4626Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBugExists() throws Exception {
  final URL resource = getClass().getResource( "Prd-4626.prpt" );
  assertNotNull( resource );

  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource parsed = mgr.createDirectly( resource, MasterReport.class );
  final MasterReport report = (MasterReport) parsed.getResource();

  final PrintReportProcessor pr = new PrintReportProcessor( report );
  final int numberOfPages = pr.getNumberOfPages();
  assertEquals( 4, numberOfPages );

  final ByteArrayOutputStream out = new ByteArrayOutputStream();
  PdfReportUtil.createPDF( report, out );
}
 
Example #3
Source File: ReportGenerator.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parses an XML file which is loaded using the given file. All needed relative file- and resourcespecification are
 * loaded using the parent directory of the file <code>file</code> as base.
 *
 * @param file
 *          the report template file.
 * @return the parsed report.
 * @throws java.io.IOException
 *           if an I/O error occurs.
 */
public MasterReport parseReport( final File file ) throws IOException, ResourceException {
  if ( file == null ) {
    throw new NullPointerException();
  }
  if ( file.isDirectory() ) {
    throw new IOException( "File is not a directory." );
  }
  final File contentBase = file.getCanonicalFile().getParentFile();
  final ResourceManager resourceManager = new ResourceManager();
  final ResourceKey contextKey = resourceManager.createKey( contentBase );

  // Build the main key. That key also contains all context/parse-time
  // parameters as they will influence the resulting report. It is not
  // wise to keep caching independent from that.
  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( file, map );
  final Resource resource = resourceManager.create( key, contextKey, MasterReport.class );
  return (MasterReport) resource.getResource();
}
 
Example #4
Source File: Prd4626Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testPerformance() throws Exception {
  if ( "false".equals( ClassicEngineBoot.getInstance().getGlobalConfig().getConfigProperty
    ( "org.pentaho.reporting.engine.classic.test.ExecuteLongRunningTest" ) ) ) {
    return;
  }
  final URL resource = getClass().getResource( "Prd-4626.prpt" );
  assertNotNull( resource );

  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource parsed = mgr.createDirectly( resource, MasterReport.class );
  final MasterReport report = (MasterReport) parsed.getResource();

  for ( int i = 0; i < 10; i += 1 ) {
    DebugReportRunner.execGraphics2D( report );
  }

  final StopWatch sw = new StopWatch();
  sw.start();
  for ( int i = 0; i < 100; i += 1 ) {
    DebugReportRunner.execGraphics2D( report );
  }
  sw.stop();
  DebugLog.log( sw.toString() );

}
 
Example #5
Source File: Prd2887Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testOverlapWarning() throws Exception {
  final URL url = getClass().getResource( "Prd-2887.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 Band b1 = (Band) report.getPageHeader().getElement( 0 );
  b1.getElement( 0 ).setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, "Null Field1" );
  b1.getElement( 1 ).setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, "Null Field2" );
  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getPageHeader() );
  //ModelPrinter.print(logicalPageBox);

  final DebugOutputProcessorMetaData metaData = new DebugOutputProcessorMetaData();
  metaData.initialize( report.getConfiguration() );

  final TableLayoutProducer tlb = new TableLayoutProducer( metaData );
  tlb.update( logicalPageBox, false );
  final TableContentProducer tcp = new TestTableContentProducer( tlb.getLayout(), metaData );
  tcp.compute( logicalPageBox, false );
  //    final SheetLayout layout = tlb.getLayout();
}
 
Example #6
Source File: LookAndFeelStep.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private AbstractReportDefinition loadDefinitionFromFile( final File filename ) {
  try {
    final ResourceKey selectedFile = resourceManager.createKey( filename );
    final Resource directly = resourceManager.create( selectedFile, null, new Class[] { MasterReport.class } );
    final MasterReport resource = (MasterReport) directly.getResource();
    final DocumentBundle bundle = resource.getBundle();
    if ( bundle == null ) {
      // Ok, that should not happen if we work with the engine's parsers, but better safe than sorry.
      final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle( resource.getContentBase() );
      documentBundle.getWriteableDocumentMetaData().setBundleType( ClassicEngineBoot.BUNDLE_TYPE );
      resource.setBundle( documentBundle );
      resource.setContentBase( documentBundle.getBundleMainKey() );
    } else {
      final MemoryDocumentBundle mem = new MemoryDocumentBundle( resource.getContentBase() );
      BundleUtilities.copyStickyInto( mem, bundle );
      BundleUtilities.copyMetaData( mem, bundle );
      resource.setBundle( mem );
      resource.setContentBase( mem.getBundleMainKey() );
    }

    return (AbstractReportDefinition) resource.derive();
  } catch ( Exception ex ) {
    getDesignTimeContext().error( ex );
    return null;
  }
}
 
Example #7
Source File: Prd3245IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws ResourceException {
  final URL url = getClass().getResource( "Prd-3245.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.execGraphics2D( report );

  if ( GraphicsEnvironment.isHeadless() ) {
    return;
  }

  final PreviewDialog previewDialog = new PreviewDialog( report );
  previewDialog.pack();
  previewDialog.setModal( true );
  previewDialog.setVisible( true );
}
 
Example #8
Source File: Sample3.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the report definition which will be used to generate the report. In this case, the report will be
 * loaded and parsed from a file contained in this package.
 *
 * @return the loaded and parsed report definition to be used in report generation.
 */
private MasterReport getReportDefinition() {
  try {
    // Using the classloader, get the URL to the reportDefinition file
    // NOTE: We will re-use the report definition from SAMPLE1
    final ClassLoader classloader = this.getClass().getClassLoader();
    final URL reportDefinitionURL = classloader
        .getResource( "org/pentaho/reporting/engine/classic/samples/Sample1.prpt" );

    // Parse the report file
    final ResourceManager resourceManager = new ResourceManager();
    final Resource directly = resourceManager.createDirectly( reportDefinitionURL, MasterReport.class );
    return (MasterReport) directly.getResource();
  } catch ( ResourceException e ) {
    e.printStackTrace();
  }
  return null;
}
 
Example #9
Source File: Prd3857Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testGoldRun5a() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "Income Statement.xml" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );

  final Band element = (Band) report.getReportHeader().getElement( 2 );
  element.setName( "Tester" );
  element.getElement( 0 ).setName( "m1" );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader() );
  //ModelPrinter.INSTANCE.print(logicalPageBox);
  final RenderNode m1 = MatchFactory.findElementByName( logicalPageBox, "m1" );
  assertEquals( StrictGeomUtility.toInternalValue( 234 ), m1.getX() );
}
 
Example #10
Source File: Prd3857Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testGoldRun4() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "Income Statement.xml" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );

  final Band element = (Band) report.getReportHeader().getElement( 2 );
  element.setName( "Tester" );
  element.getElement( 0 ).setName( "m1" );
  report.getReportHeader().getElement( 3 ).setName( "image" );

  final LogicalPageBox pageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
  //ModelPrinter.INSTANCE.print(pageBox);

  final RenderNode m1 = MatchFactory.findElementByName( pageBox, "m1" );
  assertEquals( StrictGeomUtility.toInternalValue( 234 ), m1.getX() );
  final RenderNode img = MatchFactory.findElementByName( pageBox, "image" );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), img.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 234 ), img.getWidth() );
}
 
Example #11
Source File: ReplacedContentIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReplacedContentRel() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final URL target = LayoutIT.class.getResource( "replaced-content-relative.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  PageFormat pageFormat = report.getPageDefinition().getPageFormat( 0 );
  DebugLog.log( PageFormatFactory.printPageFormat( pageFormat ) );
  final Band containerBand = report.getReportHeader();

  // Each character (regarless of font or font-size) will be 8pt high and 4pt wide.
  // this makes this test independent of the fonts installed on the system we run on.
  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, containerBand, true, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  // ModelPrinter.INSTANCE.print(logicalPageBox);
  new ValidateRelativeRunner().startValidation( logicalPageBox );
}
 
Example #12
Source File: DrillDownProfileEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void load( final File file ) {
  try {
    final ResourceManager resourceManager = new ResourceManager();
    final Resource resource = resourceManager.createDirectly( file, DrillDownProfileCollection.class );
    final DrillDownProfileCollection typeCollection = (DrillDownProfileCollection) resource.getResource();
    final DrillDownProfile[] types = typeCollection.getData();
    for ( int i = 0; i < types.length; i++ ) {
      final DrillDownProfile metaData = types[ i ];
      if ( metaData != null ) {
        drillDownProfiles.addElement( metaData );
      }
    }
  } catch ( Exception e ) {
    DrillDownProfileEditor.logger.error( "Failed:", e );
  }
}
 
Example #13
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 #14
Source File: Prd2974IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testRunNonStickyEverything() throws Exception {
  final URL url = getClass().getResource( "Prd-2974-2.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.getPageFooter().setSticky( false );
  report.getPageFooter().addElement( createLabel() );
  report.getPageFooter().setName( "Master-Footer" );
  report.getReportHeader().getSubReport( 0 ).getPageFooter().setName( "Subreport-Footer" );
  report.getReportHeader().getSubReport( 0 ).getPageFooter().setSticky( false );
  report.getReportHeader().getSubReport( 0 ).getReportHeader().addElement( createLabel( "ReportHeader-label" ) );

  report.getReportConfiguration().setConfigProperty(
      "org.pentaho.reporting.engine.classic.core.modules.output.pageable.xml.Encoding", "UTF-8" );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );
  assertNull( MatchFactory.match( logicalPageBox.getFooterArea(), new FooterTextMatcher( "Label" ) ) );
  assertNotNull( MatchFactory.match( logicalPageBox.getFooterArea(), new FooterTextMatcher( "XASDAS" ) ) );
}
 
Example #15
Source File: Prd3562IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testRunReport() throws Exception {
  final URL url = getClass().getResource( "Prd-3562.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  PrintReportProcessor p = new PrintReportProcessor( report );
  p.paginate();
  assertTrue( p.isPaginated() );
  assertFalse( p.isError() );

  final PageDrawable pageDrawable = p.getPageDrawable( 1 );

  //
  // DebugReportRunner.createPDF(report);

}
 
Example #16
Source File: Prd2863IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testRunSample() throws Exception {
  final URL url = getClass().getResource( "Prd-2863.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.getReportConfiguration().setConfigProperty(
      "org.pentaho.reporting.engine.classic.core.modules.output.pageable.xml.Encoding", "UTF-8" );
  final ByteArrayOutputStream out = new ByteArrayOutputStream();
  XmlPageReportUtil.createXml( report, out );
  final String outText = out.toString( "UTF-8" );

  int count = 0;
  int occurence = -1;
  do {
    occurence = outText.indexOf( ">Label</text>", occurence + 1 );
    if ( occurence > -1 ) {
      count += 1;
    }
  } while ( occurence != -1 );
  assertEquals( 2, count );
}
 
Example #17
Source File: WidthComputationIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayoutMatrix() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.setCompatibilityLevel( null );
  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();

  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
  // ModelPrinter.INSTANCE.print(logicalPageBox);
  new ValidateRunner().startValidation( logicalPageBox );
}
 
Example #18
Source File: DataFactoryRegistry.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void registerFromXml( final URL dataFactoryMetaSource ) throws IOException {
  if ( dataFactoryMetaSource == null ) {
    throw new NullPointerException( "Error: Could not find the data-factory meta-data description file" );
  }

  try {
    final Resource resource =
        resourceManager.createDirectly( dataFactoryMetaSource, DataFactoryMetaDataCollection.class );
    final DataFactoryMetaDataCollection typeCollection = (DataFactoryMetaDataCollection) resource.getResource();
    final DataFactoryMetaData[] types = typeCollection.getFactoryMetaData();
    for ( int i = 0; i < types.length; i++ ) {
      final DataFactoryMetaData metaData = types[i];
      if ( metaData != null ) {
        register( metaData );
      }
    }
  } catch ( Exception e ) {
    DataFactoryRegistry.logger.error( "Failed:", e );
    throw new IOException( "Error: Could not parse the element meta-data description file" );
  }
}
 
Example #19
Source File: Pre419IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testPre419() throws Exception {
  final URL target = Pre419IT.class.getResource( "Pre-419.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( basereport, report.getReportHeader(), false, true );
  // 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 #20
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 #21
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 #22
Source File: ExtraFooterIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testExtraFooterOnMigration() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "Prd-2974-2.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = tuneForMigrationMode( (MasterReport) directly.getResource() );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );
  // ModelPrinter.print(logicalPageBox);
  final RenderBox srb = (RenderBox) logicalPageBox.getFooterArea().getFirstChild();
  assertTrue( srb.getFirstChild() instanceof ProgressMarkerRenderBox );
}
 
Example #23
Source File: ExternalEncoding.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ExternalEncoding( final String name,
                         final EncodingCore core,
                         final Resource resource ) {
  this.name = name;
  this.core = core;
  this.resource = resource;
}
 
Example #24
Source File: ReportWritingUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport saveAndLoad( MasterReport report ) throws Exception {
  final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
  BundleWriter.writeReportToZipStream( report, bout );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();

  final Resource resource = mgr.createDirectly( bout.toByteArray(), MasterReport.class );
  return (MasterReport) resource.getResource();
}
 
Example #25
Source File: Prd3515Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testChartReport() throws ResourceException, IOException, ReportProcessingException {
  final URL url = getClass().getResource( "Prd-3515.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.createPDF( report );
  //System.out.println (new String(bytes, "UTF-8"));
}
 
Example #26
Source File: GoldSaveLoadIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected MasterReport postProcess( final MasterReport originalReport ) throws Exception {
  final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
  BundleWriter.writeReportToZipStream( originalReport, bout );
  assertTrue( bout.getLength() > 0 );
  /*
   * final File f = File.createTempFile("test-output-", ".prpt", new File ("test-output")); final FileOutputStream
   * outputStream = new FileOutputStream(f); outputStream.write(bout.toByteArray()); outputStream.close();
   */
  final ResourceManager mgr = new ResourceManager();
  final Resource reportRes = mgr.createDirectly( bout.toByteArray(), MasterReport.class );
  return (MasterReport) reportRes.getResource();
}
 
Example #27
Source File: Prd4542Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static MasterReport loadReport( final Object selectedFile, final ResourceManager resourceManager )
  throws ResourceException, IOException {
  final Resource directly = resourceManager.createDirectly( selectedFile, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();
  final DocumentBundle bundle = resource.getBundle();
  if ( bundle == null ) {
    // Ok, that should not happen if we work with the engine's parsers, but better safe than sorry.
    final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle( resource.getContentBase() );
    documentBundle.getWriteableDocumentMetaData().setBundleType( ClassicEngineBoot.BUNDLE_TYPE );
    resource.setBundle( documentBundle );
    resource.setContentBase( documentBundle.getBundleMainKey() );
  } else {
    final MemoryDocumentBundle mem = new MemoryDocumentBundle( resource.getContentBase() );
    BundleUtilities.copyStickyInto( mem, bundle );
    BundleUtilities.copyMetaData( mem, bundle );
    resource.setBundle( mem );
    resource.setContentBase( mem.getBundleMainKey() );
  }

  final Object visible =
    resource.getBundle().getMetaData().getBundleAttribute( ClassicEngineBoot.METADATA_NAMESPACE, "visible" );//NON-NLS
  if ( "true".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.TRUE );//NON-NLS
  } else if ( "false".equals( visible ) )//NON-NLS
  {
    resource.setAttribute( AttributeNames.Pentaho.NAMESPACE, "visible", Boolean.FALSE );//NON-NLS
  }
  return resource;
}
 
Example #28
Source File: InteractiveHtmlDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  try
  {
    final ResourceManager resourceManager = new ResourceManager();
    final Resource directly = resourceManager.createDirectly(getReportDefinitionSource(), MasterReport.class);
    return (MasterReport) directly.getResource();
  }
  catch (Exception rde)
  {
    throw new ReportDefinitionException("Failed", rde);
  }
}
 
Example #29
Source File: Prd3609IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPrd3609() throws ResourceException, IOException, ReportProcessingException {
  final URL url = getClass().getResource( "Prd-3609.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 byte[] bytes = DebugReportRunner.createXmlTablePageable( report );
  System.out.println( new String( bytes, "UTF-8" ) );
}
 
Example #30
Source File: Prd4343Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testValidateXYLineChartItemLabels() throws ResourceException, Exception {
  final URL url = getClass().getResource( "Prd-4343.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );
  final RenderNode renderNode = MatchFactory.findElementByName( logicalPageBox, "xy-chart" );
  assertTrue( renderNode instanceof RenderableReplacedContentBox );

  final RenderableReplacedContentBox xyChart = (RenderableReplacedContentBox) renderNode;
  RenderableReplacedContent xyChartContent = xyChart.getContent();
  assertTrue( xyChartContent.getRawObject() instanceof DrawableWrapper );

  final DrawableWrapper drawable = (DrawableWrapper) xyChartContent.getRawObject();
  assertTrue( drawable.getBackend() instanceof JFreeChartReportDrawable );
  final JFreeChartReportDrawable jFreeChartReportDrawable = (JFreeChartReportDrawable) drawable.getBackend();
  final JFreeChart xyLineChart = jFreeChartReportDrawable.getChart();
  final XYPlot xyLinePlot = xyLineChart.getXYPlot();

  assertTrue( xyLinePlot.getRenderer() instanceof XYLineAndShapeRenderer );
  final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyLinePlot.getRenderer();
  assertNotNull( renderer );
  assertTrue( renderer.getBaseLinesVisible() );
  assertNotNull( renderer.getBaseItemLabelGenerator() );
  assertTrue( renderer.getBaseItemLabelGenerator() instanceof StandardXYItemLabelGenerator );
}