[
https://issues.apache.org/jira/browse/FOP-3084?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17569870#comment-17569870
]
Markus Karg commented on FOP-3084:
----------------------------------
BTW, I actually tried your proposed solution and it does not work. I provided a
custom schema as the `baseURI` to FopFactoryBuilder (so the resource builder
understands the prefix to replace by the "dynamic" base URI), while keeping
schema-free relative URIs in the FO file (so the GUI tool is happy), so I could
replace the custom schema by a base URI found in a Thread Var. This might work
for external graphics like PNG, but it does not work for _embedded_ SVG. No
resource resolver is invoked for _embedded_ SVG but instead the custom schema
is forwarded to the SVG handling code by FOP internally, which apparently is
unable to deal with custom schema:
{{java.net.MalformedURLException: unknown protocol: foo}}
{{ at java.base/java.net.URL.<init>(Unknown Source)}}
{{ at java.base/java.net.URL.fromURI(Unknown Source)}}
{{ at java.base/java.net.URI.toURL(Unknown Source)}}
{{ at
org.apache.fop.fo.extensions.svg.SVGElement.getDimension(SVGElement.java:77)}}
Hence the _sole_ +completely+ working solution is to allow either the method
`newFop()` or the user user agent to set a base URI specific for the current
rendering job.
Now as that is proven, can we please go on discussing _how_ we change FOP? :)
> Override baseURI per FOP instance
> ---------------------------------
>
> Key: FOP-3084
> URL: https://issues.apache.org/jira/browse/FOP-3084
> Project: FOP
> Issue Type: Improvement
> Affects Versions: 2.7
> Reporter: Markus Karg
> Priority: Major
>
> There is a best practice to reuse FOP Factory instances for optimal
> performance. But doing so effectively applies the same baseURI (the one used
> at factory creation) to all FOP instances, hence to all rendered XSL
> templates.
>
> Given the case one needs to render XSL template `/a/A.xfo` referring to a
> picture file `./A.png` (hence effectively located at `/a/A.png`), and then
> needs to render XSL template `/b/B.xfo`, referring to a picture file
> `./B.png` (hence effectively found at `/b/B.png`), then there is no other
> solution but to create a new FOP Instance per template: On instance for
> `baseURI=.../a/` and a second instance for `baseURI=.../b/`. This effectively
> results in rather bad performance!
>
> To support this use case while keeping optimal performance (hence: use a
> single FOP factory), there should be a way to pass the baseURI of the
> rendered XSL template to the FOP Factory, so creating a new FOP instances
> effectively use different baseURIs to resolve images. In the past, there had
> been a `FOP.setBaseURI(baseURI)` method for this. Clearly that method was a
> very bad idea, as concurrent callers ended up in a race condition. So
> reintroducing `FOP.setBaseURI(baseURI)` is *definitively not* a viable
> solution!
>
> Proposed solutions could be to either add an optional parameter baseURI to
> `FOPFactory.newFOP(..., baseURI)`, _or_ to add a new method
> `FOP.setBaseURI(baseURI)` to FOP, _or_ to add a new method
> `FOUserAgent.setBaseURI(baseURI)`.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)