2

I have problems with my Apache FOP application.

Everything worked fine, until I started to pack external files (xsl, ttf, ...) from an external working directory into the jar file of the application. Since then, no images are loaded anymore and I get the following error:

FOUserAgent - Image not available. URI: data:image/jpeg;base64,.... 
Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is 
not supported. No ImagePreloader found for data:image/jpeg;base64,...(No context info available)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for data:image/jpeg;base64

In the xsl file, the images are embedded with:

<fo:external-graphic xsl:use-attribute-sets="helpicon" 
  fox:alt-text="helpicon" 
  src="url('data:image/jpg;base64,...I'm the base64 encoded image data...')">   
</fo:external-graphic>

Why are images not working anymore, when I pack the files into the jar? The images are embedded as a base64 string into the xsl file, so the image data must be available...

Thanks :)


Edit 1 I'm setting the FopFactory base url with:

    String path = MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String decodedPath = URLDecoder.decode(path, "UTF-8");
    File jar = new File(decodedPath);

    fopFactory.setBaseURL(jar.getParent());

and this is my ClasspathUriResolver:

public class ClasspathUriResolver implements URIResolver {

@Override
public Source resolve(String fileName, String base) throws TransformerException {

    System.out.print(" RESOLVING: " + fileName);

    URL url = getClass().getClassLoader().getResource(fileName);
    StreamSource jarFileSS = new StreamSource();

    System.out.println(" TO: " + url.toString());

    try {
        InputStream jarfileIS = url.openStream();
        jarFileSS.setInputStream(jarfileIS);
    } catch (IOException ioExp) {
        throw new TransformerException(ioExp);
    }
    return jarFileSS;
}

I checked the log from the ClasspathUriResolver, included files (fonts, stylesheets) get resolved correctly.

sbo
  • 951
  • 2
  • 12
  • 25
  • Check the file name spelling; in a jar the file paths are case sensitive (and using slashes `/`). – Joop Eggen Sep 29 '14 at 15:36
  • I don't think, that the file names are wrong because the image data is base64 coded in the src attribute of the external-graphic element. – sbo Sep 30 '14 at 16:39
  • I was rather thinking of non-image files. But it indeed looks like a document-base / URL related problem (`userAgent.setBaseURL("file:///C:/Temp/"); `) - you might show the loading code; what you did modify in the code. – Joop Eggen Sep 30 '14 at 17:10
  • @Joop Eggen: I added the call for setBaseURL and my ClasspathUriResolver to the question. Thanks for your help. – sbo Oct 03 '14 at 07:38
  • This can be a bunch of things. JDK version, FOP version, or a problem in your code elsewhere. Can you create a reproducible app on Github, and specify exactly which JDK/OS/etc you used. E.g. see http://stackoverflow.com/a/11091642/51280 for platform-specific image issues. – opyate Oct 06 '14 at 12:38

1 Answers1

0

I've updated jdk version to 1.7.71 and now everything worked. Thanks :)

sbo
  • 951
  • 2
  • 12
  • 25