I solved my own problem that I raised below.
 
First, the issue occurs in the DownloadManager class.
The two methods inDevelopmentEnvironment() and inServletContainerEnvironment() always evaluates to true regardless of whether I'm in standalone or servlet environment.  The way I fixed this (may not be the most elegant) is to check for the class name when I invoke DevelopmentRunner.getApplicationClass().  This way I can tell what environment I'm in.
 
After fixing the above issue, I'm now encountering another issue.  My application allows for varying file types to be sent to the browser.  However, the way the template code was written, the browser (IE for me) will always see the file named as "download" regardless of what you set the filename to be in your FileResourceProvider.  The way to fix this is by modifying the ResourceDownloadServlet class with
 

protected void prepareResponse(HttpServletRequest request, HttpServletResponse response, IResourceProvider resourceProvider) throws IOException

{

    response.setContentType(resourceProvider.getMimeType());

    response.setHeader("Content-Disposition", "attachment; filename="+resourceProvider.getFile().getName());

    response.setContentLength(resourceProvider.getLength());

}

 
by setting this head your browsers will be faithful on how to handle the file type with the mime-type and file extension that you set.
 
--Alex
----- Original Message ----
From: Alex Chang <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, August 29, 2006 2:48:49 PM
Subject: FileResourceProvider problems

I need my ULC app to be able to export to excel.
 
This is what I have in my code ...
 

public class ResultsFileProvider extends FileResourceProvider {

...

    public File createFile() throws IOException {

        // Default file name

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");

        Calendar cal = new GregorianCalendar();

        String datetime = formatter.format(cal.getTime());

        File file = File.createTempFile(datetime, ".csv");

        file.deleteOnExit();

        out.write(...);

        out.close();

       return file;

    }

...

}

 

The parent class FileResourceProvider came directly from the application template.

 

The method to initiates the download is ...

/**

* Export to Excel

*/

public void exportToExcel(int mode) {

    ResultsFileProvider provider = new ResultsFileProvider(mts);

    String id = DownloadManager.INSTANCE.put(provider);

    try

    {

        DownloadManager.INSTANCE.showDocument(id, "template");

    }

    catch(IOException ioe)

    {

        System.err.println("Cannot show document: " + ioe);

    }

}

 

 

I deployed my application on a Tomcat web server and run it via JNLP.  The problem I encounter when I try to export to Excel, is that my IE browser shows the following URL

 

    file:///D:/Apps/Tomcat%205.5/temp/2006-08-29.csv

 

which causes it to croak because the above file path is the path on my application server, not my local desktop.

 

Thanks,

Alex


Reply via email to