1
votes

I have upgraded FOP version from fop 1.1 to fop 2.3 version but getting

org.apache.fop.events.LoggingEventListener processEvent Image not found.

Below are the code snippets modified for upgrading. Master View code using fop 2.3

Code:

  TransformerFactory factory = TransformerFactory.newInstance();
  Transformer transformer = factory.newTransformer();

  FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

  //foUserAgent.setURIResolver( this.getURIResolver() );
  transformer.setURIResolver(this.getURIResolver());

  Fop fop = null;
  Source src = new StreamSource(new ByteArrayInputStream(foDoc));

  if (this.getContentType().equals("application/pdf"))
  {
    fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, os);
  }
  else if (this.getContentType().equals("application/postscript"))
  {
    fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, os);
  }

View code for fop 2.3

protected static final FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI(), resolver);

XSLT code

<fo:external-graphic src = "stylesheets/Anthem_Join_In.bmp"/>
1

1 Answers

2
votes

The API for the Resolver have changed and it is poorly documented. This code works for me (fop 2.3) in a JSF webApp.

final ServletContext sc = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();

// Create ServletContext resource Resolver
ResourceResolver resolver = new ResourceResolver() {
    @Override
    public Resource getResource(URI uri) throws IOException {
        return new Resource(sc.getResourceAsStream(uri.toASCIIString()));
    }

    @Override
    public OutputStream getOutputStream(URI uri) throws IOException {
        URL url = sc.getResource(uri.toASCIIString());
        return url.openConnection().getOutputStream();
    }
};

// Buid the factory
FopFactoryBuilder builder = new FopFactoryBuilder(new URI(sc.getContextPath()), resolver);
FopFactory FOP_FACTORY = builder.build();

The rest of the previous code in my project remains unchanged. I am not using transformer.setURIResolver(...)

The xml fop code looks like this:

<fo:external-graphic width="auto" content-width="164pt" height="auto" src="url(/resources/img/main-logo.png)"/>