Hi Fred,
You should not use a template (.vm) file because your extension of RawScreen
is a "complete" response to a page request in Turbine. To access it, the URL
should look something like:
http://<server>:8080/app/servlet/app?screen=Download&fileID=12345
Note the use of "screen" instead of "template", which tells Turbine to
execute ONLY a screen class.
To force the browser to display a "Save As" dialog box, you can set the
content type to something that will not be recognized by the browser. For
example, if your application is called "fred", you could return a content
type of "application/fred-download" or something like that. If you want the
browser to handle the file in some other way, such as displaying it in the
browser window or launching a helper app, make sure you send the appropriate
content type for the file, such as "text/plain" or "application/ms-word", or
whatever.
doOutput() looks something like this (but with exception handling, of
course):
public void doOutput(RunData data)
throws Exception
{
// get the full path to the input file, based on the fileID, or whatever
you use
// to indicate what file is to be downloaded
String filePath = ...
// open the file for reading
FileInputStream input = new FileInputStream(filePath);
// open the response stream
ServletOutputStream output = data.getResponse().getOutputStream();
// tell the browser what the file name is so that the "save as" dialog
does the
// right thing (use the file name only, not the full path to the file!)
String fileName = ...
data.getResponse().setHeader("Content-Disposition", "inline; filename="
+ fileName);
// copy the file content to the response stream
// copy the file content from the input stream to the output stream
int readCount;
byte fileBuffer[] = new byte[FILE_BUFFER_SIZE];
while((readCount = input.read(fileBuffer)) != -1)
{
output.write(fileBuffer, 0, readCount);
}
// close everything
output.flush();
output.close();
input.close();
}
Hope that helps.
Kevin
-----Original Message-----
From: Fred Gerson [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 10:54 PM
To: [EMAIL PROTECTED]
Subject: RE: How to server files
Hey Kevin,
I was wondering if you could be so kind as to share how you chain your I/O
streams in your implementation of the doOutput() method in your RawScreen
class (particularly where you say "//open the file and write its content to
responseStream" in
http://www.mail-archive.com/[email protected]/msg07479.html).
I've been trying to use RawScreen, but so far have had no luck.
Also, because RawScreen is infact a screen, should I be pointing the user
to a template with the same name as my RawScreen subclass (like
/template/Download.vm for a Download.class screen?) I've tried this but my
browser downloads the file as Download.vm, not as the name of the file on
my server, what am I missing?
Also also, what should I return from getContentType() to indicate
downloading any arbitrary file type?
Thanks so much,
Fred
From: Kevin Rutherford
Subject: RE: How to server files
Date: Mon, 30 Sep 2002 09:29:14 -0700
RawScreen is a Turbine class that can be extended to implement file
downloads. You have to override the getContentType() and doOutput()
methods
to make your new class do what you want.
In my response to your question last Friday, I included a link to the
Turbine mail archives
(http://www.mail-archive.com/turbine-user%40jakarta.apache.org/), and
suggested that you search it for the term "RawScreen". Here is one example
of what you will find:
http://www.mail-archive.com/[email protected]/msg07479.html
Reading these emails may help explain what RawScreen is, and how to extend
it. It is also very helpful to study the Turbine source code itself,
because
not everything can be figured out by looking at the documentation.
Hope this helps.
Kevin
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 30, 2002 10:30 AM
To: Turbine Users List
Subject: RE: How to server files
Hi ,
Thanks for the tip. But Could you please elaborate how to use raw screen ?
I
am really very new to turbine.
Regards,
A.P.Das.
> Use rawscreen. I do that for PDF files.
>
> -----Original Message-----
> From: apdas [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 30, 2002 11:03 AM
> To: Turbine User
> Subject: How to server files
>
>
> Hi friends,
>
> I want to read files on my server byte by byte and send the data to the
> client to replace $screen_placeholder.
>
> Please suggest some tips.
> Regards,
>
> A.P.Das.
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail: <mailto:turbine-user-
[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:turbine-user-
[EMAIL PROTECTED]>
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>