[
https://issues.apache.org/jira/browse/FOP-2480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14572358#comment-14572358
]
simon steiner commented on FOP-2480:
------------------------------------
Ive used custom resource resolver to rewrite file paths.
{code}
ResourceResolver rr = ResourceResolverFactory
.createTempAwareResourceResolver(new
InMemoryTempResourceResolver(), new MyResourceResolver());
FopFactoryBuilder confBuilder = new FopConfParser(new
File("fop.xconf"), rr).getFopFactoryBuilder();
FopFactory fopFactory = confBuilder.build();
private static class MyResourceResolver implements ResourceResolver {
public Resource getResource(URI uri) throws IOException {
return new Resource(uri.toURL().openStream());
}
public OutputStream getOutputStream(URI uri) throws IOException {
return new FileOutputStream(new File(uri));
}
}
private static class InMemoryTempResourceResolver implements
TempResourceResolver {
private final Map<String, ByteArrayOutputStream> tempBaos = Collections
.synchronizedMap(new HashMap<String, ByteArrayOutputStream>());
public OutputStream getOutputStream(String id) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tempBaos.put(id, baos);
return baos;
}
public Resource getResource(final String id) throws IOException {
if (!tempBaos.containsKey(id)) {
throw new IllegalArgumentException("Temp resource with id = " +
id
+ " does not exist");
}
return new Resource(new
ByteArrayInputStream(tempBaos.remove(id).toByteArray()));
}
}
{code}
> Since FOP 2.0 it is not possible to load embedded fonts from a JAR
> ------------------------------------------------------------------
>
> Key: FOP-2480
> URL: https://issues.apache.org/jira/browse/FOP-2480
> Project: FOP
> Issue Type: Bug
> Affects Versions: 2.0
> Reporter: Martin Wegner
>
> In FOP 1.1 it was possible to load embedded fonts (relative path in the
> fop.xconf) from a JAR by using a custom URIResolver and setting it
> (fopFactory.setURIResolver(fileResolver)) before loading the fop.xconf. The
> custom URIResolver was used while parsing the fop.xconf and resolving
> relative paths.
> FOP 2.0 does not use the given resolver. It uses resolveFromBase() from the
> InternalResourceResolver. The method resolveFromBase() calls resolve() from
> the base URI. Because it is impossible to overwrite URI or
> InternalResourceResolver there is no chance to load embedded fonts (relative
> path in the fop.xconf) from a JAR by using a custom URIResolver.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)