You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by ne...@swisslab.de on 2005/09/26 16:14:01 UTC

Flow Script Output

Hello List,

I ve a FlowScript which creates a XML tree.

var doc = Packages.org.jdom.Document();
var root = Packages.org.jdom.Element("SWLREPORT");
var outputter =
Packages.org.jdom.output.XMLOutputter(Packages.org.jdom.output.Format.getPre
ttyFormat())
var xmlfile = Packages.java.lang.String(cocoon.session.getId() + ".xml");
var msgname = Packages.java.lang.String(xmlfile.substring(0,
xmlfile.indexOf(".")) + ".msg");
...
doc.setRootElement(root);

...
  var status = Packages.org.jdom.Element("STATUS");
  if (success == true){
    status.setText("OK");
  }
  else{
    status.setText("ERROR");
  }
  root.addContent(status);
  ...

outstreamPDF = new Packages.java.io.FileOutputStream( "c:/temp/" + xmlfile
);

outputter.output(doc, outstreamXML);
outstreamXML.close();
cocoon.sendPage(msgname);
..


In this example I create a XML file in the servers local harddrice
(c:/temp/) and afterwards send a request to another sitemap matching *.msg.
This pipeline just shows the xml file on c:/temp. The XMLs name is the
session ID. 

    <map:match pattern="*.msg">
	<!-- {global:working-path} = c:/temp -->
      <map:generate type="file" src="{global:working-path}/{1}.xml"/>
      <map:serialize type="xml"/>
    </map:match>  


This method has some seriouse drawbacks. 
First and most important for me is, that it look quite silly. I think it is
not supposed to be done this way. Would'nt it be much smarter to just drop
the XML into the result stream that is send to the client anyway than to
save it on disk? 
But I *could* live with this if there was'nt

A:
The to the client returning XML file has to be stored on the server, and
also into the clients "temporary internet files" folder.
B:
Do I request the same document twice in a short period, the session ID
has'nt changed and the result of the second job is dumped into the first
jobs result XML (because the XML file name is "cocoon.session.getId() +
'.xml'"). As result I get a accumulated result XML.
C:
I cant delete the created XML file in the servers Harddrive because of some
unkown reasons.

All together I have the feeling that I m doing something fundamentally
wrong.

I ve the feeling I should write the result XML to the stream that is send to
the client. But I dont know how. If I search in JavaScript FAQs arround the
net I often finde something like: 
document.write("<B>foo</B>");

what would be just like what I basicly need. But how?
some help?

Thanks & Regards,
Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Flow Script Output

Posted by Johannes Textor <jc...@gmx.de>.
Hi Jan,

news@swisslab.de schrieb:

>This method has some seriouse drawbacks. 
>First and most important for me is, that it look quite silly. I think it is
>not supposed to be done this way. Would'nt it be much smarter to just drop
>the XML into the result stream that is send to the client anyway than to
>save it on disk? 
>  
>
I can't quite understand why one should create a whole XML tree in flow
script. isn't it much easier to use JXT for this purpuose ?
You have two choices to save the XML that is sent tho the client on the
server's hard drive:

- use the sourcewriting transformer
- use cocoon.processPipelineTo()

Regards,
Johannes

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Flow Script Output

Posted by Jason Johnston <co...@lojjic.net>.
> Hello List,
>
> I ve a FlowScript which creates a XML tree.
>
> [snip]
>
> In this example I create a XML file in the servers local harddrice
> (c:/temp/) and afterwards send a request to another sitemap matching
> *.msg.
> This pipeline just shows the xml file on c:/temp. The XMLs name is the
> session ID.
>
>     <map:match pattern="*.msg">
> 	<!-- {global:working-path} = c:/temp -->
>       <map:generate type="file" src="{global:working-path}/{1}.xml"/>
>       <map:serialize type="xml"/>
>     </map:match>
>
>
> This method has some seriouse drawbacks.
> First and most important for me is, that it look quite silly. I think it
> is
> not supposed to be done this way. Would'nt it be much smarter to just drop
> the XML into the result stream that is send to the client anyway than to
> save it on disk?


Yes, definitely.  Temporary server-side files suck. ;-)

It looks like what you're trying to do is to simply take a flowscript
object and have that object used as the source when generating the
pipeline.  This can be done using the ModuleSource[1] in your
map:generate, for example:

### In the flow: ###
var myXml = getXMLAsStringOrInputStream(); //logic done elsewhere
cocoon.sendPage("send-my-xml", {xml : myXml});

### In the sitemap: ###
<map:match pattern="send-my-xml">
  <map:generate src="module:flow-attr:xml" />
  <map:transform ... />
  <map:serialize ... />
</map:match>

This should work as long as the flow object you pass it is an InputStream,
a String, or a byte array.

Hope that helps.
--Jason

[1]
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/components/source/impl/ModuleSource.html




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org