You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jeff Jones <jj...@trap9.com> on 2002/08/06 22:52:17 UTC
Re: problem redirecting to a RawScreen - solved
Excellent! Thanks you guys!
The two keys for me were:
1) Use an action (without a screen) to delegate a request to the proper template
and/or screen.
2) using the following to 'hardcode' your attachment filename and type in
RawScreen:
res.setHeader("Content-disposition-type", "attachment");
res.setHeader("Content-disposition", "filename=" + filename);
res.setIntHeader("Content-length", new
Long(c.getFileSize()).intValue());
Thanks again.
Jeff
----- Original Message -----
From: "Steve Yokanovich" <sy...@smythco.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Tuesday, August 06, 2002 1:29 PM
Subject: Re: problem redirecting to a RawScreen
> I do this in my RawContent screen, which follows. This works for me but
> does prompt the user to save the file or open in in Excel. I think if
> you take out the following line it may open it in Excel:
>
> res.setHeader("Content-disposition-type", "attachment");
>
> Regards,
>
> Steve Yokanovich
> Smyth Companies, Inc.
>
>
>
> public class RawContent extends RawScreen {
>
> /**
> * Check the users session to see if the content type is known
> * from the database. If not, set it to the default.
> * @param data RunData Turbine information
> * @param contentType String containing the content type
> */
> public String getContentType(RunData data) {
>
> String defaultType = "application/download";
> Content c = null;
> c = (Content) data.getSession().getAttribute("CONTENT");
>
> if (c == null || c.getType().length() == 0) {
>
> return defaultType;
>
> } else {
> System.out.println(c.getType());
> return c.getType();
> }
>
> }
>
> /**
> * Retrieves clob content from the content manager and sends the
> * output stream to the response writer
> * @param data RunData Turbine object
> */
> public void doOutput(RunData data) {
> StringBuffer sb = null;
> DBConnection db = null;
> ParameterParser pp = data.getParameters();
> int contentID = pp.getInt("p");
> int versionID = pp.getInt("v");
> if ( contentID <= 0 ) {
> contentID = pp.getInt("id");
> versionID = pp.getInt("version");
> }
>
> if (versionID <= 0) {
> versionID = 1;
> }
> if (contentID >= 0) {
> try {
> db = TurbineDB.getConnection();
> Connection conn = db.getConnection();
> ContentManager cm = new ContentManager();
> cm.setConnection(conn);
> sb = cm.getContent(contentID, versionID);
> } catch (IOException ioe) {
> System.err.println("IOException " + ioe.getMessage());
> } catch (Exception e) {
> System.err.println("Exception" + e.getMessage());
> } finally {
> try {
> TurbineDB.releaseConnection(db);
> } catch (Exception e) {
> }
> }
>
>
> // Content metadata is in the session, I put it
> there in the action
> Content c = (Content)
> data.getSession().getAttribute("CONTENT");
> // Before sending the content, set the file name and size
> HttpServletResponse res = data.getResponse();
> res.setHeader("Content-disposition-type", "attachment");
> res.setHeader("Content-disposition", "filename=" +
> c.getSourceFile());
> res.setIntHeader("Content-length", new
> Long(c.getFileSize()).intValue());
>
> try {
> PrintWriter out = res.getWriter();
> out.print(sb.toString());
> } catch (IOException e) {
> }
>
>
> }
>
>
> }
>
> }
>
>
>
>
> EPugh@upstate.com wrote:
> > Does this allow the user to open a document in their browser? I have an
> > excel document, that I would like to have them be able to click on, and have
> > the excel doc open in the browser. Currently, if they do that, they get the
> > raw text of the .xls file. I have to have them rightclick and save the file
> > to the desktop to be able to see it.
> >
> > Eric
> >
> > -----Original Message-----
> > From: Steve Yokanovich [mailto:syokanovich@smythco.com]
> > Sent: Tuesday, August 06, 2002 4:05 PM
> > To: Turbine Users List
> > Subject: Re: problem redirecting to a RawScreen
> >
> >
> > I am not sure if this will help you, but I had a similar situation and
> > solved it this way:
> >
> > I have a screen that lists content stored in an Oracle database as
> > clobs. This screen template has a reference to a Turbine Action (no screen).
> >
> > <a
> > href="$link.setAction("GetContent").addPathInfo("id",$id).addPathInfo("versi
> > on",$version)">$id
> > </a></td>
> >
> >
> > In the Turbine Action class (in this example called GetContent) I set
> > the appropriate screen template and layout based on the type of content
> > the user selected. Eg:
> >
> > (c is the content object retrieved from the database)
> > String type = c.getType();
> > if ( type.equalsIgnoreCase("application/pdf")) {
> > // The content is raw and we need a Rawscreen to display it
> > data.setLayout(null);
> > data.getSession().setAttribute("CONTENT", c);
> > data.setScreenTemplate("RawContent.vm");
> > }
> > if ( type.equalsIgnoreCase("text/html")) {
> > // The content is text -- need a VelocityScreen to display it
> > data.setScreenTemplate("Content.vm");
> > }
> > if (type.equalsIgnoreCase("text/xml")) {
> > // The content is raw -- need a Rawscreen to display it
> > data.setLayout(null);
> > data.getSession().setAttribute("CONTENT", c);
> > data.setScreenTemplate("PdfContent.vm");
> > }
> > if (type.equalsIgnoreCase("application/msword")) {
> > // The content is raw and we need a Rawscreen to display it
> > data.setLayout(null);
> > data.getSession().setAttribute("CONTENT", c);
> > data.setScreenTemplate("RawContent.vm");
> > }
> >
> > The result is the user may see the content displayed on the screen with
> > a layout and (Content.vm) or download the content to a file (RawContent.vm).
> >
> > I hope this helps. If not, feel free to email me and I can provide some
> > other samples.
> >
> >
>
>
> --
> Steve Yokanovich
> Smyth Companies, Inc.
> Information Systems
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>