Skip to Content
avatar image
Former Member

XML File download through an iview

Hi All,

I've written an iview that builds up the data for an xml file and tableview report. The should be able to click a link on the iview and a window pops up and they can save the XML data to a local file.

I have two problems, the first is I am unsure how to pass the large amount of data from the first iview to the second "Download" iview. It is too big to fit as a form parameter. I'm hoping to add it to the component session. Do you think this will work?

The second problem is the download itself. I've created a basic component with a doContent method. I've tried setting the content type to "Application/octet-stream" by using the following code :

public class ecDownloadComponent extends AbstractPortalComponent

{

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

PortalComponentContentType pct = new PortalComponentContentType("APPLICATION/OCTET-STREAM");

response.setContentType(pct);

response.write("<xml>hello</xml>");

}

}

All I get is an HTML page with the data in.

Any ideas how I force the download?

Cheers

Richard

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 06, 2004 at 09:19 AM

    Hi Richard,

    1.) If the complete data which should be downloadable is built in the first iView, it is no problem to add it to the component session. "Size doesn't matter" 😊

    What happens "physically" if you add something to a session? In fact, a <i>reference</i> to your (small or incredible fat) object is added into a hashtable or something similar.

    (Excurs: That's why objects in sessions are called "live", because if you get a reference to an object of a session and manipulate this object with it's methods, the object in the session is manipulated, because it's the same object; that's the reason why you don't have to "update" such an object into the session).

    So you don't have to worry about using the double amount of memory, because you are not.

    2.) For iViews to be something different than HTML, put all the stuff into the overridden method <i>protected void doOnNodeReady(IPortalComponentRequest request, IEvent event)</i>, retrieve the original HttpServletResponse via <i>HttpServletResponse response= request.getServletResponse(true);</i> and set the ContentType on this.

    The trick is to be "early enough" in the sense that the content type must not have been set before.

    With this, just implement an empty <i>doContent</i> method and put the rest of your download logic in the method stated above.

    Just one more info, not needed here, but maybe interesting in this context: If you want do produce PDF's in this way, you have to be sure to put the PDF data "fast enough" into the output stream, otherwise the PDF-Reader could get stuck. This means <i>first</i> setting all data into a memory buffer and then sending this into the outputstream (and not calculating the data "while sending").

    Hope it helps

    Detlev

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Richard,

      "it's not a bug, it's a feature!" (This at least is what Bill Gates would answer...)

      IE has different ways to check which program is responsible for wich resources. First, it checks the content type. IE "knows" that it can handle "text/xml" by itself.

      But this is not your problem, for you have set the content type to "application/octet-stream".

      In this case, IE checks the OS-table to be found in the file explorer --> tools --> folder options --> file types. There it sees that it can handle ".xml" sources by itself, again. (You can control this by deleting this entry, but you can simply trust me, too; with the latter choice, you don't have troubles to reinstall the entry...).

      So the solution or better the best workaround could be:

      a) Before the link, explain that the user should right-click and choose "save target as..." instead of left-clicking. GMX uses this for attachements, so it's not <i>that</i> unusual.

      b) ZIP the XML and send the ZIP instead of the pure XML. Now the user is asked to download (or open the file with the standard ZIP tool) the file.

      c) If you left-click on the link and the XML is parsed and shown up by IE, the user also can save the XML directly from within IE...

      Hope it helps,

      and don't forget to reward me with 1000 points 😊

      Detlev

  • avatar image
    Former Member
    Aug 06, 2004 at 02:18 PM

    Hi,

    I'm using something like

    response.setHeader("Content-disposition", "attachment;filename=\"" + defaultName + "\"");

    and this gives me the desired download-dialog. Maybe this work for you, too.

    Best regards

    AE

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 06, 2004 at 02:56 PM

    Hi Detlev,

    regarding software patents thats a different story... A cool beer would be enough for me now.

    See ya.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 09, 2004 at 07:29 AM

    Hi Guys,

    Great work between you, adding the "attachment" word into the content disposition line has fixed IE. It now prompts to download the raw XML.

    I'll have to split the points I'm afraid as Albert was helpful too. I'll try to give Albert 1/3 of the points as he gave the final answer but not all answers to all of the questions.

    Hope its ok. Thanks again.

    Richard

    Add comment
    10|10000 characters needed characters exceeded