• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Embedding FOP: resolving 'href' and 'url' references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Embedding FOP: resolving 'href' and 'url' references


  • Subject: Re: Embedding FOP: resolving 'href' and 'url' references
  • From: Patrick Robinson <email@hidden>
  • Date: Fri, 1 Oct 2010 22:55:34 -0400

Hi Paul,

I just saw this (late to the party).  I solved this for one of our apps in a way very similar to what you have there:

public class XSLURIResolver implements URIResolver {

        public Source resolve(String href, String base) throws TransformerException {
                StringBuffer path = new StringBuffer(WOApplication.application().path());
                path.append("/Contents/Resources/");
                path.append(href);
                File file = new File(path.toString());
                if(file.exists()) return new StreamSource(file);
                return null;
        }

}

This works whether it's running on development or deployment machine, and whether from Eclipse or from command line.

- Patrick


On Sep 14, 2010, at 9:25 PM, Paul Hoadley wrote:

On 14/09/2010, at 10:01 PM, Q wrote:

Unless FOP supports some kind of resource resolution delegate

Thanks for the idea.  It turns out that FOP does indeed support custom URI resolvers.  I created a subclass of FOURIResolver which just overrides resolve(String, String), and returns a StreamSource by calling WOResourceManager.inputStreamForResourceNamed():

public class WOURIResolver extends FOURIResolver {
@Override
public Source resolve(java.lang.String href, java.lang.String base) throws javax.xml.transform.TransformerException {
return new StreamSource(WOApplication.application().resourceManager().inputStreamForResourceNamed(href, null, null));
}
}

(Obviously this is an incomplete proof of concept.  That method would certainly need to call super.resolve() at some point if the WOResourceManager can't find the resource, as it's effectively swallowing up all _other_ URI references.  I just happen to have none in this particular situation.)

Passing one of these to TransformerFactory.setURIResolver() sorts out the xsl:import issue, and to FopFactory.setURIResolver() sorts out the fo:external-graphic problem.

Have a look at the source for ERPDFGeneration in wonder for how this problem is currently handled. If you aren't tied to using FOP you may wish to try using it instead.

As an aside, I'm only tied to FOP to the extent that I have an existing XSLFO solution for simple invoice generation that I currently use with RenderX's XEP.  The cost of embedding XEP for this particular application is prohibitive.  FOP seemed like an interesting alternative if I could get it to work.  I haven't looked at it since about version 0.2, and it seems to be doing well enough to render the very simple documents I'm throwing at it here.  And the price is right.


-- 
Paul.

http://logicsquad.net/

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Embedding FOP: resolving 'href' and 'url' references
      • From: Paul Hoadley <email@hidden>
  • Prev by Date: Re: Patched MySQL plugin
  • Next by Date: Re: BugTracker on Derby
  • Previous by thread: Re: BugTracker on Derby
  • Next by thread: Re: Embedding FOP: resolving 'href' and 'url' references
  • Index(es):
    • Date
    • Thread