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

The following examples show how to use org.pentaho.reporting.libraries.resourceloader.ResourceManager#createDirectly() . 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: 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 2
Source File: WidthComputationIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayoutMatrixLegacy() throws Exception {
  final MasterReport basereport = new MasterReport();
  basereport.setPageDefinition( new SimplePageDefinition( new PageFormat() ) );
  basereport.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 3, 8, 0 ) );
  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 3
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 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: StraightToPlainText.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();
    // plain text does not support images, so we do not care about the logo ..
    report.getParameterValues().put("logo", null);
    return report;
  }
  catch (Exception e)
  {
    throw new ParseException("Failed to parse the report", e);
  }
}
 
Example 6
Source File: StraightToPDF.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();
    final URL imageURL = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/demo/opensource/gorilla.jpg", StraightToPDF.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 7
Source File: Prd3620IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testDialog() throws Exception {
  if ( GraphicsEnvironment.isHeadless() ) {
    return;
  }

  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();

  final PreviewDialog dialog = new PreviewDialog( report );
  dialog.setModal( true );
  dialog.pack();
  dialog.setVisible( true );
}
 
Example 8
Source File: Prd2864IT.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-2849.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();
  HtmlReportUtil.createZIPHTML( report, out, "report.html" );
  // final String outText = out.toString("UTF-8");
  // assertTrue(outText.indexOf("<p>Here is my HTML.</p>") > 0);
  /*
   * 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);
   */
  // System.out.println(outText);
}
 
Example 9
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 10
Source File: Prd4581IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPrptStyleParsing() throws ResourceException {
  final URL resource = getClass().getResource( "Prd-4581.prptstyle" );
  assertNotNull( resource );

  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource loaded = mgr.createDirectly( resource, ElementStyleDefinition.class );
  final ElementStyleDefinition style = (ElementStyleDefinition) loaded.getResource();
  assertEquals( 1, style.getRuleCount() );
  final ElementStyleSheet rule = style.getRule( 0 );
  assertNotNull( rule );

  assertEquals( "Arial", rule.getStyleProperty( TextStyleKeys.FONT ) );
}
 
Example 11
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 12
Source File: OpenReportAction.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 13
Source File: Pre34IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSubReportDoesNotCrash() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }

  final URL url = getClass().getResource( "Pre-34.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 14
Source File: LayoutAutoParagraphIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLayout2() throws Exception {
  final URL url = getClass().getResource( "layout-auto-paragraph-2.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport resource = (MasterReport) directly.getResource();
  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( resource, resource.getReportHeader() );
  // ModelPrinter.print(logicalPageBox);
  // XmlPageReportUtil.createXml(resource, new NoCloseOutputStream(System.out));
}
 
Example 15
Source File: AbstractReportProcessorTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testIsLimitNotReachedForNumberOfRowsLessQueryLimit() throws Exception {
  //When data source enforce limit itself
  // report with 148 rows
  final URL url = getClass().getResource( "report1.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.setQueryLimit( 149 );
  final AbstractReportProcessor reportProcessor = new DummyReportProcessor( report );
  reportProcessor.prepareReportProcessing();
  assertEquals( reportProcessor.isQueryLimitReached(), false );
}
 
Example 16
Source File: XPathQueryTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFromBundle() throws Exception {

    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    final Resource res =
      manager.createDirectly( XPathQueryTest.class.getResource( "xpath-bundle-test.prpt" ), MasterReport.class );
    final MasterReport report = (MasterReport) res.getResource();

    final CompoundDataFactory dataFactory = (CompoundDataFactory) report.getDataFactory();
    final XPathDataFactory xpathDataFactory = (XPathDataFactory) dataFactory.getReference( 0 );
    xpathDataFactory.initialize( new DesignTimeDataFactoryContext( report ) );
    xpathDataFactory.queryData( "default", new StaticDataRow() );
    xpathDataFactory.close();
  }
 
Example 17
Source File: CSSParserTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testParseInitialStyleSheet() throws Exception {
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();

  final Resource directly = resourceManager.createDirectly
    ( "res://org/pentaho/reporting/libraries/css/initial.css", StyleSheet.class );
  assertNotNull( directly.getResource() );
}
 
Example 18
Source File: StyleDefinitionUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * When an object implementing interface <code>Runnable</code> is used to create a thread, starting the thread
 * causes the object's <code>run</code> method to be called in that separately executing thread.
 * <p/>
 * The general contract of the method <code>run</code> is that it may take any action whatsoever.
 *
 * @see Thread#run()
 */
public void run() {
  try {
    final ResourceManager mgr = new ResourceManager();
    final Resource directly = mgr.createDirectly( file, ElementStyleDefinition.class );
    styleDefinition = (ElementStyleDefinition) directly.getResource();
  } catch ( Exception e ) {
    this.exception = e;
  }
}
 
Example 19
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() );

}
 
Example 20
Source File: Prd2400IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testRunSample() throws ResourceException {
  final URL url = getClass().getResource( "Prd-2400.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.addExpression( new EventMonitorFunction() );

  DebugReportRunner.execGraphics2D( report );
}