public void testRun() throws Exception {
    final URL url = getClass().getResource("Pre-492.prpt");
    assertNotNull(url);
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport report = (MasterReport) directly.getResource();

    try {
      final ZipRepository zipRepository = new ZipRepository(new NullOutputStream());
      final ContentLocation root = zipRepository.getRoot();
      final ContentLocation data =
          RepositoryUtilities.createLocation(
              zipRepository, RepositoryUtilities.splitPath("data", "/"));

      final DebugFlowOutputProcessor outputProcessor = new DebugFlowOutputProcessor();

      final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
      printer.setContentWriter(root, new DefaultNameGenerator(root, "report"));
      printer.setDataWriter(data, new DefaultNameGenerator(data, "content"));
      printer.setUrlRewriter(new SingleRepositoryURLRewriter());
      outputProcessor.setPrinter(printer);

      final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
      sp.processReport();
      sp.close();
      zipRepository.close();
    } catch (IOException ioe) {
      throw ioe;
    } catch (ReportProcessingException re) {
      throw re;
    } catch (Exception re) {
      throw new ReportProcessingException("Failed to process the report", re);
    }
  }
  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);

    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());
  }
  /**
   * Validate that the banded subreport contained in an inline subreport page-footer content DOES
   * NOT show up in the layout-editor
   *
   * @throws Exception
   */
  public void testInlineBandedSubReport() throws Exception {
    final URL resource = getClass().getResource("Prd-4637.prpt");
    assertNotNull(resource);

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

    final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore();
    final ReportRenderContext masterContext =
        new ReportRenderContext(report, report, null, globalAuthenticationStore);
    final SubReport subReport = (SubReport) report.getReportHeader().getElement(0);
    final ReportRenderContext subContext =
        new ReportRenderContext(report, subReport, masterContext, globalAuthenticationStore);

    final SubReport subReport2 = subReport.getReportHeader().getSubReport(0);
    final ReportRenderContext subSubContext =
        new ReportRenderContext(report, subReport2, subContext, globalAuthenticationStore);

    final TestRootBandRenderer r =
        new TestRootBandRenderer(subReport.getPageFooter(), subSubContext);

    final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108);
    graphics2D.expect("Any Text Printed Is An Error!");
    assertTrue(graphics2D.hitClip(10, 10, 1, 1));
    r.draw(graphics2D);
  }
  public static MasterReport createReport(final Serializable fileId)
      throws ResourceException, IOException {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final HashMap helperObjects = new HashMap();
    // add the runtime context so that PentahoResourceData class can get access
    // to the solution repo

    ResourceKey key = null;

    IUnifiedRepository unifiedRepository =
        PentahoSystem.get(IUnifiedRepository.class, PentahoSessionHolder.getSession());
    RepositoryFile repositoryFile = unifiedRepository.getFileById(fileId);
    if (repositoryFile != null) {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + repositoryFile.getPath(),
              helperObjects);
    } else {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + fileId,
              helperObjects);
    }

    final Resource resource = resourceManager.create(key, null, MasterReport.class);
    return (MasterReport) resource.getResource();
  }
  public void testErrorHandlingBad() throws Exception {
    final URL url = getClass().getResource("Prd-3985.prpt");
    final ResourceManager mgr = new ResourceManager();
    final MasterReport report =
        (MasterReport) mgr.createDirectly(url, MasterReport.class).getResource();
    report
        .getReportConfiguration()
        .setConfigProperty(
            "org.pentaho.reporting.engine.classic.core.FailOnAttributeExpressionErrors", "true");

    final FormulaExpression function = new FormulaExpression();
    function.setName("Test");
    function.setFormula("=MULTIVALUEQUERY(\"Bad\")");

    report
        .getReportHeader()
        .setAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, function);

    try {
      DebugReportRunner.createPDF(report);
      Assert.fail();
    } catch (Exception e) {
      // ignored
    }
  }
예제 #6
0
  public void testParseStyleRule() throws Exception {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();

    StyleSheetParserUtil.getInstance()
        .parseStyleRule(
            null, "* { width: 10% }", null, null, resourceManager, StyleKeyRegistry.getRegistry());
  }
예제 #7
0
  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());
  }
  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);
  }
  protected MasterReport postProcess(final MasterReport originalReport) throws Exception {
    final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream();
    BundleWriter.writeReportToZipStream(originalReport, bout);
    assertTrue(bout.getLength() > 0);

    final ResourceManager mgr = new ResourceManager();
    mgr.registerDefaults();
    final Resource reportRes = mgr.createDirectly(bout.toByteArray(), MasterReport.class);
    return (MasterReport) reportRes.getResource();
  }
  @Test
  public void testPrd3857Report() throws Exception {
    File file = GoldenSampleGenerator.locateGoldenSampleReport("Prd-3857-001.prpt");
    Assert.assertNotNull(file);

    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    final Resource res = manager.createDirectly(file, MasterReport.class);
    final MasterReport report = (MasterReport) res.getResource();

    List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1);
    assertPageValid(pages, 0);
    assertPageValid(pages, 1);
  }
예제 #11
0
  /**
   * This method does what the report designer does on save.
   *
   * @param report
   * @param file
   * @throws Exception
   */
  private void saveReport(final MasterReport report, final File file) throws Exception {
    BundleWriter.writeReportToZipFile(report, file);
    final ResourceManager resourceManager = report.getResourceManager();
    final Resource bundleResource = resourceManager.createDirectly(file, DocumentBundle.class);
    final DocumentBundle bundle = (DocumentBundle) bundleResource.getResource();
    final ResourceKey bundleKey = bundle.getBundleKey();

    final MemoryDocumentBundle mem = new MemoryDocumentBundle();
    BundleUtilities.copyStickyInto(mem, bundle);
    BundleUtilities.copyMetaData(mem, bundle);
    report.setBundle(mem);
    report.setContentBase(mem.getBundleMainKey());
    report.setDefinitionSource(bundleKey);
  }
  public void testWizardDefinitionIsAvailable() throws Exception {
    final File url = GoldTestBase.locateGoldenSampleReport("prd-2887.prpt");
    assertNotNull(url);
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final Resource directly = resourceManager.createDirectly(url, MasterReport.class);
    final MasterReport org = (MasterReport) directly.getResource();

    assertNotNull(WizardProcessorUtil.loadWizardSpecification(org, resourceManager));
    final MasterReport report = postProcess(org);
    assertNotNull(WizardProcessorUtil.loadWizardSpecification(report, report.getResourceManager()));
    DetailsHeader detailsHeader = report.getDetailsHeader();
    detailsHeader.getElement(0).setName("MagicChange");

    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1);
    ModelPrinter.INSTANCE.print(logicalPageBox);
  }
 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);
   }
 }
  public MasterReport getReportDefinition() {
    try {
      // Get the URL to the reportDefinition file
      final Class classVar = this.getClass();
      final URL reportDefinitionURL =
          classVar.getResource("/reports/LC_Total_Number_Of_Cancelled_Bookings.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;
  }
  /**
   * 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());
    }
  }
  /**
   * Validate that the master-report page-footer content shows up in the layout-editor
   *
   * @throws Exception
   */
  public void testOutsidePageFooter() throws Exception {
    final URL resource = getClass().getResource("Prd-4637.prpt");
    assertNotNull(resource);

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

    final GlobalAuthenticationStore globalAuthenticationStore = new GlobalAuthenticationStore();
    final ReportRenderContext reportContext =
        new ReportRenderContext(report, report, null, globalAuthenticationStore);
    final TestRootBandRenderer r = new TestRootBandRenderer(report.getPageFooter(), reportContext);

    final ValidateTextGraphics graphics2D = new ValidateTextGraphics(468, 108);
    graphics2D.expect("Outside", "Page", "Footer");
    assertTrue(graphics2D.hitClip(10, 10, 1, 1));
    r.draw(graphics2D);
  }
  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);
  }
예제 #18
0
  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());
  }
 public void registerFromXml(final URL expressionMetaSource) throws IOException {
   if (expressionMetaSource == null) {
     throw new NullPointerException(
         "Error: Could not find the expression meta-data description file");
   }
   try {
     final Resource resource =
         resourceManager.createDirectly(expressionMetaSource, ExpressionMetaDataCollection.class);
     final ExpressionMetaDataCollection typeCollection =
         (ExpressionMetaDataCollection) resource.getResource();
     final ExpressionMetaData[] types = typeCollection.getExpressionMetaData();
     for (int i = 0; i < types.length; i++) {
       final ExpressionMetaData metaData = types[i];
       if (metaData != null) {
         registerExpression(metaData);
       }
     }
   } catch (Exception e) {
     throw new IOException("Error: Could not parse the element meta-data description file", e);
   }
 }
예제 #20
0
 private ResourceKey createImageKey() throws IOException, ResourceKeyCreationException {
   final ResourceManager resMgr = new ResourceManager();
   resMgr.registerDefaults();
   return resMgr.createKey(new URL("http://127.0.0.1:65535/image.jpg"));
 }
  public void testSerialize() throws Exception {
    final ResourceLoader resourceLoader = new ClassloaderResourceLoader();
    final ResourceManager manager = new ResourceManager();
    manager.registerDefaults();

    // Test failure - null key
    try {
      resourceLoader.serialize(null, null);
      fail("Serialization of a null key should throw an exception");
    } catch (NullPointerException npe) {
      // success
    }

    // Test failure - not a Classloader resource key
    try {
      final File tempFile = File.createTempFile("junit-test", ".tmp");
      final ResourceKey tempKey = manager.createKey(tempFile);
      resourceLoader.serialize(null, tempKey);
      fail(
          "The Classloader Resource Loader should fail when handling a non-classloader resource key");
    } catch (IllegalArgumentException iae) {
      // success
    }

    // Create key
    final String key1source =
        "res://org/pentaho/reporting/libraries/resourceloader/test1.properties";
    final ResourceKey key1 = manager.createKey(key1source);
    assertNotNull(key1);

    // Serialize the key
    final String serKey1 = resourceLoader.serialize(null, key1);
    assertNotNull("The returned key should not be null", serKey1); // $NON-NLS-1$
    assertTrue(
        "Serialized verison does not start with the correct header",
        serKey1.startsWith(STRING_SERIALIZATION_PREFIX));
    assertTrue(
        "Serialized version does not contain the correct schema information",
        serKey1.startsWith(DESERIALIZE_PREFIX));
    assertTrue(
        "Serialized version should contain the identifier intact",
        serKey1.endsWith(key1.getIdentifier().toString()));

    // Serialize a key created from a derived key
    final String key2source = "test2.properties";
    final ResourceKey key2 = manager.deriveKey(key1, key2source);
    assertNotNull(key2);

    final String serKey2 = resourceLoader.serialize(null, key2);
    assertNotNull("The returned key should not be null", serKey2); // $NON-NLS-1$
    assertTrue(
        "Serialized verison does not start with the correct header",
        serKey2.startsWith(STRING_SERIALIZATION_PREFIX));
    assertTrue(
        "Serialized version does not contain the correct schema information",
        serKey2.startsWith(DESERIALIZE_PREFIX));
    assertTrue(
        "Serialized version should contain the identifier intact",
        serKey2.endsWith(";res://org/pentaho/reporting/libraries/resourceloader/test2.properties"));

    // Serialize a key with factory parameters
    final Map<ParameterKey, Object> factoryParams = new HashMap<ParameterKey, Object>();
    factoryParams.put(new FactoryParameterKey("this"), "that");
    factoryParams.put(new FactoryParameterKey("null"), null);
    final ResourceKey key3 = manager.createKey(key1source, factoryParams);
    assertNotNull(key3);

    final String serKey3 = resourceLoader.serialize(null, key3);
    assertEquals(
        "resourcekey:org.pentaho.reporting.libraries.resourceloader"
            + ".loader.resource.ClassloaderResourceLoader;"
            + "res://org/pentaho/reporting/libraries/resourceloader/"
            + "test1.properties;\"\"\"f:this=that\"\":\"\"f:null=\"\"\"",
        serKey3);
  }
  protected void drawReplacedContent(final RenderableReplacedContentBox content) {
    final Graphics2D g2 = getGraphics();
    final Object o = content.getContent().getRawObject();
    if (o instanceof DrawableWrapper) {
      final DrawableWrapper drawableWrapper = (DrawableWrapper) o;
      if (drawDrawable(content, g2, drawableWrapper)) {
        drawImageMap(content);
      }
      return;
    }
    if (o instanceof Image) {
      if (drawImage(content, (Image) o)) {
        drawImageMap(content);
      }
      return;
    }

    if (o instanceof URLImageContainer) {
      final URLImageContainer imageContainer = (URLImageContainer) o;
      if (imageContainer.isLoadable() == false) {
        PdfLogicalPageDrawable.logger.info(
            "URL-image cannot be rendered, as it was declared to be not loadable: "
                + imageContainer.getSourceURLString());
      } else {
        final ResourceKey resource = imageContainer.getResourceKey();
        if (resource == null) {
          PdfLogicalPageDrawable.logger.info(
              "URL-image cannot be rendered, as it did not return a valid URL.");
        } else {
          try {
            final ResourceManager resourceManager = getResourceManager();
            final com.lowagie.text.Image instance;
            final com.lowagie.text.Image maybeImage = imageCache.get(resource);
            if (maybeImage != null) {
              instance = maybeImage;
            } else {
              final ResourceData data = resourceManager.load(resource);
              instance = com.lowagie.text.Image.getInstance(data.getResource(resourceManager));
              imageCache.put(resource, instance);
            }

            final Resource imageWrapped = resourceManager.create(resource, null, Image.class);
            final Image image = (Image) imageWrapped.getResource();

            if (drawImage(content, image, instance)) {
              drawImageMap(content);
            }
            return;
          } catch (InvalidReportStateException re) {
            throw re;
          } catch (Exception e) {
            PdfLogicalPageDrawable.logger.info(
                "URL-image cannot be rendered, as the image was not loadable.", e);
          }
        }
      }
    }

    if (o instanceof LocalImageContainer) {
      final LocalImageContainer imageContainer = (LocalImageContainer) o;
      final Image image = imageContainer.getImage();
      if (drawImage(content, image)) {
        drawImageMap(content);
      }
    } else {
      PdfLogicalPageDrawable.logger.debug("Unable to handle " + o);
    }
  }
 public static MasterReport parseReport(final Object file) throws ResourceException {
   final ResourceManager manager = new ResourceManager();
   manager.registerDefaults();
   final Resource resource = manager.createDirectly(file, MasterReport.class);
   return (MasterReport) resource.getResource();
 }
예제 #24
0
  /**
   * Helperfunction to extract an image from an imagereference. If the image is contained as
   * java.awt.Image object only, the image is recoded into an PNG-Image.
   *
   * @param reference the image reference.
   * @return an image.
   * @throws com.lowagie.text.DocumentException if no PDFImageElement could be created using the
   *     given ImageReference.
   * @throws java.io.IOException if the image could not be read.
   */
  public Image getImage(final ImageContainer reference) throws DocumentException, IOException {
    if (reference == null) {
      throw new NullPointerException();
    }

    Object identity = null;
    java.awt.Image image = null;
    if (reference instanceof URLImageContainer) {
      final URLImageContainer urlImageContainer = (URLImageContainer) reference;
      final ResourceKey url = urlImageContainer.getResourceKey();
      if (url != null && urlImageContainer.isLoadable()) {
        identity = url;
        final Image cached = (Image) cachedImages.get(identity);
        if (cached != null) {
          return cached;
        }

        try {
          final ResourceData resourceData = resourceManager.load(url);
          final byte[] data = resourceData.getResource(resourceManager);
          final Image itextimage = Image.getInstance(data);
          cachedImages.put(identity, itextimage);
          return itextimage;
        } catch (ResourceException re) {
          RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", re);
        } catch (BadElementException be) {
          RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", be);
        } catch (IOException ioe) {
          RTFImageCache.logger.info(
              "Unable to read the raw-data, will try to recode image-data.", ioe);
        }

        try {
          final Resource resource = resourceManager.create(url, null, Image.class);
          image = (java.awt.Image) resource.getResource();
        } catch (ResourceException re) {
          RTFImageCache.logger.info("Caught illegal Image, will try to find local instance", re);
        }
      }
    }

    if (reference instanceof LocalImageContainer && image == null) {
      final LocalImageContainer localImageContainer = (LocalImageContainer) reference;
      image = localImageContainer.getImage();
      if (image != null) {
        // check, if the content was cached ...
        identity = localImageContainer.getIdentity();
        if (identity != null) {
          final Image cachedImage = (Image) cachedImages.get(identity);
          if (cachedImage != null) {
            return cachedImage;
          }
        }
      }
    }
    if (image == null) {
      return null;
    }

    final WaitingImageObserver obs = new WaitingImageObserver(image);
    obs.waitImageLoaded();

    try {
      final byte[] data = RenderUtility.encodeImage(image);
      final Image itextimage = Image.getInstance(data);
      if (identity != null) {
        cachedImages.put(identity, itextimage);
      }
      return itextimage;
    } catch (UnsupportedEncoderException uee) {
      logger.warn("Assertation-Failure: PNG encoding failed.", uee);
      return null;
    }
  }