views:

24

answers:

2

Hi,

My application generates PDFs using images stored in the EAR. The images are changed about on a monthly basis, and I would like to move them into the database to avoid deployment by every image file change.

Unforunately there is a problem:

<fo:block>
           <fo:external-graphic src=”testImage.gif”/>
</fo:block>

The FOP can just accept URL as parameter. I could create a servlet that reads the database and can give an image and then I could refer to the servlet url from the FOP context, but I think it is not the best solution. An other solution would be storing the images in the file system and recording the filenames in the database, but I do like none of these options. What do you think about these solutions? Is there any third one? Thanks Zoltan

+2  A: 

I think your servlet option is probably the best.

Here's another option, not sure if it is a good one. Store the images in the database with the filename as the primary key. During application startup, pull all the images out of the database and write them to the given filenames in the appropriate location so that the FOP logic can locate them.

Either the application would need to be restarted whenever an image is changed in the database, or you would need to add a method of forcing it to refresh the image files on disk.

Dave Costa
+2  A: 

Assuming you are embedding FOP in your application and programmatically running the transformation, you should be able to use a custom URI Resolver in order to accomplish this.

Then your example would become something like this (you can use any scheme instead of "db"):

<fo:block>
           <fo:external-graphic src=”db:testImage.gif”/>
</fo:block>

You would need to register "db:" URI scheme handler with FOP User Agent (or FOP factory) before processing. Check the FOP embedding guide for details (search for "URIResolver").

Also, FOP comes with ServletContextURIResolver that you can use as an example, see How to use Apache FOP in a Servlet for details.

Neeme Praks