我的Apache FOP应用程序出现问题。
一切正常,直到我开始将外部工作目录中的外部文件(xsl,ttf,...)打包到应用程序的jar文件中。从那时起,没有图像被加载,我得到以下错误:
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
在xsl文件中,图像嵌入了:
<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>
当我将文件打包到jar中时,为什么图像不再起作用?图像作为base64字符串嵌入到xsl文件中,因此图像数据必须可用...
谢谢:)
修改1 我正在设置FopFactory基本网址:
String path = MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = URLDecoder.decode(path, "UTF-8");
File jar = new File(decodedPath);
fopFactory.setBaseURL(jar.getParent());
这是我的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;
}
我从ClasspathUriResolver检查了日志,包含的文件(字体,样式表)得到了正确解析。
答案 0 :(得分:0)
&#39; ave将jdk版本更新为1.7.71,现在一切正常。谢谢:))