"Ilan Azbel" <[EMAIL PROTECTED]> writes:

>I sent a similar message to the velocity mailing list but was informed that
>this would probably be a better list to email with my question:

>Hello,

>I would like a servlet to return a binary file and thereby instruct the
>browser
>not to display it, but rather to download it. That is, ask the user if they
>would like to "Open" or "Save" the file.

--- cut --- 
package org.apache.turbine.apachefaces.modules.screens;
                                                                                
                                                                                
                                                 
import java.io.OutputStream;
                                                                                
                                                                                
                                                 
import javax.servlet.http.HttpServletResponse;
                                                                                
                                                                                
                                                 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
                                                                                
                                                                                
                                                 
import org.apache.turbine.apachefaces.model.ImageModel;
import org.apache.turbine.apachefaces.security.ApacheUser;
import org.apache.turbine.modules.screens.RawScreen;
import org.apache.turbine.util.RunData;
                                                                                
                                                                                
                                                 
public class ImageScreen
        extends RawScreen
{
    protected Log log = LogFactory.getLog(this.getClass());
                                                                                
                                                                                
                                                 
    public String getContentType(RunData data)
    {
        return "image/gif";
    }
                                                                                
                                                                                
                                                 
    protected void doOutput(RunData data)
            throws Exception
    {
        HttpServletResponse response = data.getResponse();
        ImageModel imageModel = ImageModel.getModel(data);
        ApacheUser user = (ApacheUser) imageModel.getUser();
                                                                                
                                                                                
                                                 
        byte [] img = user.getImage();
        OutputStream os = response.getOutputStream();
                                                                                
                                                                                
                                                 
        if (img != null && img.length > 0)
        {
            os.write(img);
        }
 
        os.flush();
    }
}
--- cut --- 

This outputs a GIF (which is available as a byte array from
user.getImage()) through a RawScreen. This is actual code from the
ApacheFaces application which made 2nd prize at the Derby Contest @
ApacheCon.

I will polish this application some more and then it will go into the
Turbine repository as an example application for Turbine 2.3.x
programming.

        Regards
                Henning


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
[EMAIL PROTECTED]        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

What is more important to you...
   [ ] Product Security
or [ ] Quality of Sales and Marketing Support
              -- actual question from a Microsoft customer survey

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to