Skip,

I developed two classes (extensions of RawScreen) to serve direct .html,
.xml files/data, completely bypassing the default turbine template
mechanism.

The DirectResponseScreen class is used when you have either the html (e.g.,
generated by transforming XML into XSL) or the xml (with link to a style
sheet) programmatically generated in a string buffer.

The RedirectResponseScreen class is used when you want to serve a physical
html/xml file on your server.

Example use of a direct response screen:

1. In your action class (doPerform method) force the screen to be the
DirectResponseScreen class.

For example,
   runData.setScreen("DirectResponseScreen");

2. After retrieving the results (xml+xsl or html) in a stringBuffer, save
them in the runData message buffer.

runData.setMessage(strOutput);


Example use of redirect response screen

1. In your action class (doPerform method) force the screen to be the
ReDirectResponseScreen class.

For example,
   runData.setScreen("ReDirectResponseScreen");

2. Set the redirect URI in runData.

runData.setRedirectURI(strUrl);


The source code of the RawScreen extension classes is given below:

DIRECT_RESPONSE_SCREEN class
----------------------------------------------------------------------------
-------------------

package org.apache.turbine.modules.screens;

import org.apache.turbine.util.StringUtils;
import java.io.*;
/**
 * Insert the type's description here.
 * Creation date: (1/22/02 9:54:52 AM)
 * @author: Administrator
 */
public class DirectResponseScreen extends RawScreen {
 /**
  * Actually output the dynamic content.  The OutputStream can be
  * accessed like this: <pre>OutputStream out =
  * data.getResponse().getOutputStream();</pre>.
  *
  * @param data Turbine information.
  * @exception Exception, a generic exception.
  */
protected void doOutput(org.apache.turbine.util.RunData data) throws
Exception
{
 // We are using the message field of RunData to store the response
 String strXmlOut = data.getMessage();
 if (StringUtils.isValid(strXmlOut))
 {
  PrintWriter out = data.getOut();
  //
  // return XML stream to the browser
  out.println(strXmlOut);
  out.flush();
 }
}
/**
  * Set the content type.  This method should be overidden to
  * actually set the real content-type header of the output.
  *
  * @param data Turbine information.
  * @return A String with the content type.
  */
protected String getContentType(org.apache.turbine.util.RunData data)
{
 return data.getContentType();
}
}
----------------------------------------------------------------------------
-------------------


REDIRECT_RESPONSE_SCREEN class
----------------------------------------------------------------------------
-------------------
package org.apache.turbine.modules.screens;

import org.apache.turbine.util.StringUtils;
/**
 * Insert the type's description here.
 * Creation date: (1/22/02 9:54:52 AM)
 * @author: Administrator
 */
public class ReDirectResponseScreen extends RawScreen {
 /**
  * Actually output the dynamic content.  The OutputStream can be
  * accessed like this: <pre>OutputStream out =
  * data.getResponse().getOutputStream();</pre>.
  *
  * @param data Turbine information.
  * @exception Exception, a generic exception.
  */
protected void doOutput(org.apache.turbine.util.RunData data) throws
Exception
{
 String strRedirectUrl = data.getRedirectURI();
 if (StringUtils.isValid(strRedirectUrl))
 {
  data.getResponse().sendRedirect(strRedirectUrl);
 }
}
 /**
  * Set the content type.  This method should be overidden to
  * actually set the real content-type header of the output.
  *
  * @param data Turbine information.
  * @return A String with the content type.
  */
protected String getContentType(org.apache.turbine.util.RunData data)
{
 return data.getContentType();
}
}
----------------------------------------------------------------------------
-------------------


----- Original Message -----
From: "Skip Walker" <[EMAIL PROTECTED]>
To: "'Turbine Users List'" <[EMAIL PROTECTED]>
Sent: Wednesday, January 23, 2002 2:12 PM
Subject: RE: Turbine (with auth/session) as transparent proxy (no template
s)?


> Would you mind providing a bit more explanation  as to how you use
RawScreen
> to apply Turbine security to downloadable files?
>
> How are your screens setup to do this?
>
> How do you create a link in a template to a downloadable file which goes
> through the RawScreen?
>
> Thanks,
> Skip
>
>
>
> > -----Original Message-----
> > From: Eric Dobbs [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, January 23, 2002 2:14 PM
> > To: Turbine Users List
> > Subject: Re: Turbine (with auth/session) as transparent proxy (no
> > template s)?
> >
> >
> > On Wednesday, January 23, 2002, at 06:56  AM, Weaver, Scott wrote:
> >
> > >> I need to be able to act like a web server to my
> > >> client and send back binary data like image/jpeg; so must I use
> > >> getOutputStream()?
> > >
> > > You may want to check out
> > org.apache.turbine.modules.screens.RawScreen.
> > > I've never used it but from what it says in the javadocs,
> > this might do
> > > the
> > > trick for you.
> >
> > We use RawScreen to allow uses to download binary files.  It
> > has worked great for us.  Added bonus, we can apply Turbine's
> > security mechanisms to ensure that users can only download
> > their own files.
> >
> > -Eric
> >
> > --
> > 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]>


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

Reply via email to