I have a plain ole’ HTML document. It gets read into some Java code I wrote and translated into a PDF via some XSL-T and Apache FOP.
My issue is, this HTML document is a legal form that should be pre-populated with values contained in a Java object before being sent off to various computers/users. How can I read in dynamic (run-time) data and then continue to transform it as usual?
I would like to know of a strategy/technology to do this that can be completed server-side. Any ideas would be appreciated!
(I could take a very ugly solution where I piece together Strings in my Java code and insert in the data one piece at a time in the middle, but I have many pieces and that code would be difficult for my company to maintain.)
EDIT: To clarify — I found this answer already on SO that addresses something similar. In that question, it addresses reading data in from a user’s browser via text entry into a form, I believe. That is a client-side issue. I need to read data from Java code, which is on the server side.
My question was not worded very well, allow me to clarify what I was trying to accomplish and how I accomplished it (for Google-viewers.)
I had a document encoded in XHTML (well formed HTML). I needed an end result of a PDF version of this document with some data gathered at run-time. I do not think my solution is novel or even close to the best way someone might do it, but for the sake of closure, I am going to list it:
Insert tags into HTML/XML document that indicate a value needs to be filled in later. For example
<day/>for the day from a timestamp.Retain my existing XSL-T document to convert the text from XML to a PDF format. It ignores all tags like
<day/>which is nice because I didn’t immediately have all of the fields ready to be replaced.Create code using simple regular expressions to
replaceFirst("<day/>", getTimestamp())the tags with the appropriate content at runtime. This method needed to be called via a “struts” event that was triggered when the user entered in the data.When run, the program accepts user data, calls a method to read in the XHTML file, replace the fields with the data gathered, pass on the modified file to my XSLT transformation using Apache FOP.
This isn’t elegant, but it does the trick.