Please see below for a proposal, following the use-case:
On Sat, 18 Sep 2004, Jorg Heymans wrote:
Luigi Bai wrote:Hi,
I've got a XML database with images of various sorts of mime-types (jpeg, gif, png, etc) stored in text() nodes as Base64. I have a trivial Base64Serializer that reconstitutes them on the way out. However, I think I'm stuck with a mime-type problem. It seems I have to have a separately instantiated Serializer for each possible mime-type:
correct
<map:select type="mimeSelector"> <map:when test="image/png"> <map:serialize type="base64" mime-type="image/png" /> </map:when> ...etc...
I find this verbose, and annoying to maintain if someone saves an image with a new mime-type.
i agree, others might not.
correct. getMimeType() is called during setup() which is called during pipeline setup before any data is processed.
The Serializer interface has a getMimeType() method which allows a Serializer to declare its mime-type, but only at setup() time (correct me if I'm wrong?). I need to declare the mime-type later; the first
IIRC it works this ways so that cocoon can start streaming SAX events to the client as they roll in, and doesn't have to wait until the serializer is fully finished processing.
I would like to propose a change to how mime-types in a pipeline work, so a Serializer can set the mime-type after setup() (i.e., if the mime-type depends on some SAX events).
I would like Serializer to have a method boolean willSetMimeType()
to let the pipeline builder know that despite returning null in getMimeType(), the Serializer *will* want to set the mime type later in the stream. This will tell AbstractProcessingPipeline.setupPipeline() not to bail if it can't determine a mimeType.
The problem is that I can't get a handle on *how* the Serializer would later set the mime-type; it doesn't seem to have access to the Environment in which that information is stored.
The Pipeline would also probably need to be told not to start streaming to the client right away, but to probably do that when the Serializer's finished. Maybe it can just deduce that from the Serializer returning "true" from willSetMimeType().
This would throw a wrench in the caching policy of creating the Serializer to see what the mime-type of the cached object is; you'd have to run the Serializer each time to determine the mime-type. UNLESS, of course, the mime-type is cached with the object. Which seems like a reasonable thing to do.
Any comments?
