Search code examples
javajavascriptjbossseampreview

How to preview a file on the server in JBoss


I need some ideas on how I can best solve this problem.

I have a JBoss Seam application running on JBoss 4.3.3 What a small portion of this application does is generate an html and a pdf document based on an Open Office template.

The files that are generated I put inside /tmp/ on the filesystem. I have tried with System.getProperties("tmp.dir") and some other options, and they always return $JBOSS_HOME/bin I would like to choose the path $JBOSS_HOME/$DEPLOY/myEAR.ear/myWAR.war/WhateverLocationHere/

However, I don't know how I can programatically choose path without giving an absolute path, or setting $JBOSS_HOME and $DEPLOY.

Anybody know how I can do this?

The second question; I want to easily preview these generated files. Either through JavaScript, or whatever is the easiest way. However, JavaScript cannot access the filesystem on the server, so I cannot open the file through JavaScript.

Any easy solutions out there?

Solution

  • Not sure how you are generating your PDFs, but if possible, skip the disk IO all together, stash the PDF content in a byte[] and flush it out to the user in a servlet setting the mime type to application/pdf* that responds to a URL which is specified by a link in your client or dynamically set in a <div> by javascript. You're probably taking the memory hit anyways, and in addition to skipping the IO, you don't have to worry about deleting the tmp files when you're done with the preview.

    *****I think this is right. Need to look it up.