Ok, sorry, I didn't understand you but now it makes perfect sense. Thanks for your advise!
Well, I had a chance to express myself more clearly, and think it through a bit more.
Basically, what you're doing is implementing another way to connect the controller to the view, when the view is pretty simple.
I would tend to implement this as a custom reader, actually, with code like:
<map:components> <map:readers> <map:reader name="stream" class="....."> <stream-name>/stream</stream-name> <mime-type-name>/mimeType</mime-type-name> </map:reader> </map:readers> </map:components>
<map:match pattern="my-stream-uri"> <map:read type="stream"/> </map:match>
That way, you're configuring the reader to know where in the flow business objects to get the stream and the mime type. As the context object from flow comes back as just an Object (presumably could be some kind of javascript object as well), you would do well to use JXPath to get at the values, hence specifying the names of these values as XPath expressions.
You end up with something more generic component that way that isn't specifically targetted at your problem.
Make sense?
Regards, Upayavira
-----Original Message----- From: Upayavira [mailto:[EMAIL PROTECTED] Sent: Friday, February 18, 2005 10:37 AM To: dev@cocoon.apache.org Subject: Re: Write binary data to output stream from flow
Bart Molenkamp wrote:
-----Original Message----- From: Upayavira [mailto:[EMAIL PROTECTED] Sent: Thursday, February 17, 2005 5:19 PM To: dev@cocoon.apache.org Subject: Re: Write binary data to output stream from flow
Bart Molenkamp wrote:
Hi,
Is it possible to write binary data to the HTTP response directly
from
the flow? I have an InputStream available in my flow, and I want to serve data from that stream directly to the HTTP response. E.g.
cocoon.sendBinaryData(inputStream, "application/octet-stream");
Or something similar.
I solved it now by creating a SourceFactory and Source
implementation,
so that I can use a plain reader, but this feels a bit like
overkill.
The SourceFactory has to lookup the data from the database (that is where the data is for the input stream), and the URL contains the primary key to get the data from the database.
To my knowledge there isn't a way to do this directly. But you could place the inputstream into a request attribute or some such, and
pick
that up from your source, rather than reading the database again.
Am I understanding your question right?
Regards, Upayavira
Hi Upayavira,
I don't know if I understood your answer. Maybe I'm not clear enough about my question, so I'll try again.
In my flowscript, I get a java.io.InputStream instance, and the
content
that I read from it can be sent to the user directly. The user
thinks
that it is downloading a file (which he is) but the source comes
from a
database (but the database is transparent due to OJB). In my case, I have a review object which can hold 0 or more downloaded files
(files
are evidence that support the result of the review):
... review = ...; // get review from database trough OJB cocoon.sendPageAndWait("list-evidence.xml", {evidence: review.getEvidence()});
... evidenceId = cocoon.request.get("evidenceId"); evidence = review.getEvidenceById(evidenceId); evidenceDataStream = evidence.getInputStream(); mimeType = evidence.getMimeType();
// now I want to serve the input stream to the user // e.g. something like cocoon.sendBinaryData(evidenceDataStream, mimeType);
How can I now read this input stream, and pass it's data to the
output
stream of a pipeline, in a simple way. Currently, I have an evidence source that I can lookup. The URL contains the ID of the review, and
the
ID of the evidence. Something like
evidence://reviewid/evidenceid.txt
That is exactly what I took from what you were saying. And, as it currently stands, there is no way to send data other than via a pipeline. So, what I would say is:
cocoon.sendPage("my-binary-url", {"stream": evidenceDataStream, "mimeType": mimeType});
<map:match pattern="my-binary-url"> <map:read src="evidence:"/> </map:match>
Then, in your source, you can use o.a.c.components.flow.FlowHelper to get the stream and mimetype business objects, and have your source use them. I'm not up on this enough to give you exact details, but if I
were
to try to achieve this, this is probably how I would go about it.
Am I making sense now?
Regards, Upayavira