Java Code Examples for org.pentaho.reporting.libraries.resourceloader.Resource#getResource()

The following examples show how to use org.pentaho.reporting.libraries.resourceloader.Resource#getResource() . 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: CellSpanIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLargeCrosstab() throws Exception {
  final URL url = getClass().getResource( "Prd-3929-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.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 4, 0, 0 ) );

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

  final RenderNode[] cell2a = MatchFactory.findElementsByName( logicalPageBox, "header-#1" );
  for ( int i = 0; i < cell2a.length; i += 1 ) {
    final RenderBox cellParent = cell2a[i].getParent();
    assertEquals( cell2a[i].getWidth(), cellParent.getWidth() );
  }
}
 
Example 2
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 3
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 4
Source File: HyperlinkFormulasIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void getFormulas() throws ResourceException {
  final URL url = getClass().getResource( "Prd-3883.prpt" );
  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 ReportElement chart = findChart( report );
  assertNotNull( chart );
  final Expression attributeExpression =
    chart.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE );
  assertNotNull( attributeExpression );
  assertTrue( attributeExpression instanceof ChartExpression );
  ChartExpression chartExpression = (ChartExpression) attributeExpression;
  final String[] hyperlinkFormulas = chartExpression.getHyperlinkFormulas();
  assertNotNull( hyperlinkFormulas );
  assertEquals( 1, hyperlinkFormulas.length );
  assertTrue( hyperlinkFormulas[ 0 ].startsWith( "=DRILLDOWN" ) );
}
 
Example 5
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 6
Source File: Prd4109Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testItemBandLayout() throws ResourceException, ReportProcessingException, ContentProcessingException {
  final URL url = ReportLayouterTest.class.getResource( "Prd-4109.prpt" );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource resource = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) resource.getResource();

  final ReportLayouter l = new ReportLayouter
    ( new ReportRenderContext( report, report, null, new GlobalAuthenticationStore() ) );
  final LogicalPageBox layout = l.layout();

  ModelPrinter.INSTANCE.print( layout );
  assertNotNull( MatchFactory.findElementsByElementType( layout, ItemBandType.INSTANCE ) );
  assertNotNull( MatchFactory.findElementsByElementType( layout, SubReportType.INSTANCE ) );

}
 
Example 7
Source File: AbstractXmlReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parses an external file using LibLoader and returns the parsed result as an object of type
 * <code>targetClass</code>. The file is given as relative pathname (relative to the current source file). The current
 * helper-methods are used as parse-parameters for the external parsing.
 *
 * @param file        the file to be parsed.
 * @param targetClass the target type of the parse operation.
 * @param map         the map of parse parameters.
 * @return the result, never null.
 * @throws ParseException           if parsing the result failed for some reason.
 * @throws ResourceLoadingException if there was an IO error loading the resource.
 * @see #deriveParseParameters()
 */
protected Object performExternalParsing( final String file, final Class targetClass, final Map map )
  throws ParseException, ResourceLoadingException {
  try {
    final ResourceManager resourceManager = rootHandler.getResourceManager();
    final ResourceKey source = rootHandler.getSource();

    final ResourceKey target = resourceManager.deriveKey( source, file, map );
    final DependencyCollector dc = rootHandler.getDependencyCollector();

    final Resource resource = resourceManager.create( target, rootHandler.getContext(), targetClass );
    dc.add( resource );
    return resource.getResource();
  } catch ( ResourceLoadingException rle ) {
    throw rle;
  } catch ( ResourceException e ) {
    throw new ParseException( "Failure while loading data: " + file, e, getLocator() );
  }

}
 
Example 8
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 9
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 10
Source File: AbstractXmlDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected MasterReport parseReport() throws ReportDefinitionException
{
  final URL in = getReportDefinitionSource();
  if (in == null)
  {
    throw new ReportDefinitionException("ReportDefinition Source is invalid");
  }

  try
  {
    ResourceManager manager = new ResourceManager();
    Resource res = manager.createDirectly(in, MasterReport.class);
    return (MasterReport) res.getResource();
  }
  catch (Exception e)
  {
    throw new ReportDefinitionException("Parsing failed", e);
  }
}
 
Example 11
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 12
Source File: PdfEncryptionValidateIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSaveEncrypted() throws Exception {
  final URL url = getClass().getResource( "pdf-encryption-validate.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 byte[] b = createPDF( report );
  final PdfReader reader = new PdfReader( b, DocWriter.getISOBytes( "Duck" ) );
  assertTrue( reader.isEncrypted() );
}
 
Example 13
Source File: TotalGroupCountIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGroupCount() throws Exception {
  final URL url = getClass().getResource( "aggregate-function-test.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setDataFactory( new TableDataFactory( "default", new AggregateTestDataTableModel() ) );
  final RelationalGroup g = report.getGroupByName( "default" );
  if ( g != null ) {
    report.removeGroup( g );
  }
  report.addExpression( new TotalGroupCountVerifyFunction() );

  final TotalGroupCountFunction f = new TotalGroupCountFunction();
  f.setName( "continent-total-gc" );
  f.setGroup( "Continent Group" );
  f.setDependencyLevel( 1 );
  report.addExpression( f );

  final TotalGroupCountFunction f2 = new TotalGroupCountFunction();
  f2.setName( "total-gc" );
  f2.setDependencyLevel( 1 );
  report.addExpression( f2 );

  DebugReportRunner.execGraphics2D( report );

}
 
Example 14
Source File: SubBandParsingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPreview() 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();

  DebugReportRunner.execGraphics2D( report );
}
 
Example 15
Source File: Prd3159IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLoadSave() throws Exception {
  final ResourceKey key = createImageKey();

  final Element element = new Element();
  element.setElementType( new ContentType() );
  element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, key );

  // first, create the report with an embedded resource in it.
  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( element );
  // .. save it.
  saveReport( report, new File( "bin/test-tmp/prd-3159-load-save-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-3159-load-save-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-2.prpt" ) );
  // save it twice, that triggers the crash...
  saveReport( report2, new File( "bin/test-tmp/prd-3159-load-save-2.prpt" ) );

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

  final Element reportElement = (Element) report2.getReportHeader().getElement( 0 );
  final Object designValue = reportElement.getElementType().getDesignValue( runtime, reportElement );
  final DefaultImageReference image = (DefaultImageReference) designValue;
  assertEquals( 20, image.getImageWidth() );
  assertEquals( 20, image.getImageHeight() );

}
 
Example 16
Source File: CrosstabRenderIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLegacyRendering() throws Exception {
  final URL url = getClass().getResource( "CrosstabTest.prpt" );
  final ResourceManager manager = new ResourceManager();
  manager.registerDefaults();
  final Resource res = manager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) res.getResource();
  report.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 4, 0, 0 ) );

  final LogicalPageBox box = DebugReportRunner.layoutPage( report, 0 );
  // ModelPrinter.print(box);
}
 
Example 17
Source File: Prd3857Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGoldRun8() throws Exception {
  final File file = GoldTestBase.locateGoldenSampleReport( "OrderDetailReport.xml" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final Resource directly = mgr.createDirectly( file, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setAttribute( AttributeNames.Internal.NAMESPACE, AttributeNames.Internal.COMAPTIBILITY_LEVEL, null );
  report.getReportHeader().getElement( 3 ).setName( "image" );

  final LogicalPageBox pageBox = DebugReportRunner.layoutPage( report, 0 );
  //ModelPrinter.INSTANCE.print(pageBox);
  final RenderNode img = MatchFactory.findElementByName( pageBox, "image" );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), img.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 270 ), img.getWidth() );
}
 
Example 18
Source File: SimpleStyleRuleMatcher.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private StyleSheet parseStyleSheet( final ResourceKey key,
                                    final ResourceKey context ) {
  try {
    final Resource resource = resourceManager.create
      ( key, context, StyleSheet.class );
    return (StyleSheet) resource.getResource();
  } catch ( ResourceException e ) {
    // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage());
  }
  return null;
}
 
Example 19
Source File: PageableHtmlOutputIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPagination() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }
  final URL target = PageableHtmlOutputIT.class.getResource( "pageable-html-output-report.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.createPageableHTML( report );
}
 
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 );
}