You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2001/12/03 12:37:08 UTC

Writing a Transformer, getting a Serializer

At 10:49 am +0000 2/12/01, Jeremy Quinn wrote:

>Maybe I'll have a go at writing a test "FileResourceWriterTransformer", to
>investigate the process of taking input from the user, having it modify a
>Resource using XSLT then writing it out again.

Would someone mind helping me with some Cocoon internals?

I am pretty sure I know how to write a Transformer (at least I have some
great examples!), but I do not know how to get a Serialiser inside a
Transformer.

What I am thinking of is this:

I would like to pass as a parameter to the Transformer, the name of the
Serialiser (as set up in the SiteMap), that you want the Transformer to use
when it writes out your XML Fragment to file.

Something like this:


  <map:transformers default="xslt">
   	<map:transformer
			name="write-file"
			src="org.apache.cocoon.transformation.FileResourceWriterTransformer"
      pool-max="16" pool-min="8" pool-grow="2">
    	<serializer>xml</serializer> <!-- say which Serialiser to use -->
   	</map:transformer>
  </map:transformers>


  <map:serializers default="html">
   	<map:serializer name="xml"
			mime-type="text/xml"
			src="org.apache.cocoon.serialization.XMLSerializer"
      pool-max="32" pool-min="16" pool-grow="4">
			<omit-xml-declaration>no</omit-xml-declaration>
		</map:serialzer>
  </map:serializers>


	<map:pipeline>
		<map:match pattern=" ... ">
				<map:generate ...../>

				<map:transform type="write-file" src="cocoon:/thefile.xml">
					<!-- the Node in the current document, that is
						to become the root Node of the saved file-->
					<map:parameter name="file-root" value="doc"/>
				</map:transform>

				<map:serialize>
		</map:match>
	</map:pipeline>


Then in the "compose()" method, I want to take the (SiteMap) name of the
Serialser, and retrieve the Component, releasing it in the "dispose()"
method.


Is this possible?
Am I looking at this the right way?


Thanks for any help


regards Jeremy






-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
   <phone:+44.[0].20.7737.6831>             <pa...@vizzavi.net>

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


Re: Writing a Transformer, getting a Serializer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 10:25 am +0100 4/12/01, Stefano Mazzocchi wrote:
>Jeremy Quinn wrote:
>>
>> At 4:30 pm +0100 3/12/01, Stefano Mazzocchi wrote:
>> >Jeremy Quinn wrote:
>> >
>> >> Is this possible?
>> >
>> >Is shouldn't.
>> >
>> >> Am I looking at this the right way?
>> >
>> >I think so, what are you trying to achieve?
>>
>> XML File editing from HTML forms.
>>
>> Request Generator
>>
>> Followed by XSLT StyleSheet to set up XInclude tags
>>
>> Xinclude the editable content
>>
>> XSLT StyleSheet modifies the XIncluded content, using the output of the
>> request generator.
>>
>> This content is then passed on to a "FileResourceWriterTransformer", which
>> (either reacting to a namespace in the content or has been told which tag)
>> outputs that content as a file on disk.
>>
>> Response prepared for user
>>
>> I need my Transformer to Serialise the Sax Events "between" it's trigger
>> tags, to a File, provided a (pseudo protocol) URL.
>
>Yes, this is more of an architectural question. For now, you can't call
>a serializer like that. And I have the perception it would be wrong to
>allow you to do it.
>
>I would simply call the the serializing code that the XML serializer
>uses, it's a couple of lines of code anyway.
>
>> Serialisers can be set up in different ways, so I thought it would be good
>> to allow the SItemap author to be able to tell the Transformer to use a
>> Serialiser already setup in the SiteMap.
>
>I'm not that sure since your outside behavior is still that of a
>transformer if you are taking input and placing output.
>
>The use of Serializers would be justified if you considered the need for
>plugging in different serialization behavior, but I only see the need
>for the XML serialialize, so my suggestion is to call the serialization
>routines directly.
>
>> Hence my need to get a Serialser by it's sitemap name, whilst inside my
>> Transformer.
>>
>> Does that make any more sense ;)    ?
>
>Yes, but I'd call it FS: if you need to serialize it doesn't necessarely
>mean that you need a the whole abstraction of the serializer concept :)
>Don't you agree?

Thanks for the reply.

Makes sense, I'll try it like you suggest.

People may still want to set character-set and indentation of the serialsed
XML, or is the character-set treated transparently?

In fact I don't really understand the issues of Character Sets here, can
anybody help?

Assuming that you do not want to change the character-set of a document
that you are inserting Nodes into, and it might be anything, and you don't
know what character-set the Request is going to be, what do you do?

This is something I never worked out properly in the FP TagLib, and it
caused problems for people not using utf-8, I'd rather get it right this
time ;)


Thanks for your help

regards Jeremy


-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
   <phone:+44.[0].20.7737.6831>             <pa...@vizzavi.net>

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


Re: Writing a Transformer, getting a Serializer

Posted by Stefano Mazzocchi <st...@apache.org>.
Jeremy Quinn wrote:
> 
> At 4:30 pm +0100 3/12/01, Stefano Mazzocchi wrote:
> >Jeremy Quinn wrote:
> >
> >> Is this possible?
> >
> >Is shouldn't.
> >
> >> Am I looking at this the right way?
> >
> >I think so, what are you trying to achieve?
> 
> XML File editing from HTML forms.
> 
> Request Generator
> 
> Followed by XSLT StyleSheet to set up XInclude tags
> 
> Xinclude the editable content
> 
> XSLT StyleSheet modifies the XIncluded content, using the output of the
> request generator.
> 
> This content is then passed on to a "FileResourceWriterTransformer", which
> (either reacting to a namespace in the content or has been told which tag)
> outputs that content as a file on disk.
> 
> Response prepared for user
> 
> I need my Transformer to Serialise the Sax Events "between" it's trigger
> tags, to a File, provided a (pseudo protocol) URL.

Yes, this is more of an architectural question. For now, you can't call
a serializer like that. And I have the perception it would be wrong to
allow you to do it.

I would simply call the the serializing code that the XML serializer
uses, it's a couple of lines of code anyway.
 
> Serialisers can be set up in different ways, so I thought it would be good
> to allow the SItemap author to be able to tell the Transformer to use a
> Serialiser already setup in the SiteMap.

I'm not that sure since your outside behavior is still that of a
transformer if you are taking input and placing output.

The use of Serializers would be justified if you considered the need for
plugging in different serialization behavior, but I only see the need
for the XML serialialize, so my suggestion is to call the serialization
routines directly.
 
> Hence my need to get a Serialser by it's sitemap name, whilst inside my
> Transformer.
> 
> Does that make any more sense ;)    ?

Yes, but I'd call it FS: if you need to serialize it doesn't necessarely
mean that you need a the whole abstraction of the serializer concept :)
Don't you agree?

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------



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


Re: Writing a Transformer, getting a Serializer

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 4:30 pm +0100 3/12/01, Stefano Mazzocchi wrote:
>Jeremy Quinn wrote:
>
>> Is this possible?
>
>Is shouldn't.
>
>> Am I looking at this the right way?
>
>I think so, what are you trying to achieve?

XML File editing from HTML forms.

Request Generator

Followed by XSLT StyleSheet to set up XInclude tags

Xinclude the editable content

XSLT StyleSheet modifies the XIncluded content, using the output of the
request generator.

This content is then passed on to a "FileResourceWriterTransformer", which
(either reacting to a namespace in the content or has been told which tag)
outputs that content as a file on disk.

Response prepared for user


I need my Transformer to Serialise the Sax Events "between" it's trigger
tags, to a File, provided a (pseudo protocol) URL.

Serialisers can be set up in different ways, so I thought it would be good
to allow the SItemap author to be able to tell the Transformer to use a
Serialiser already setup in the SiteMap.

Hence my need to get a Serialser by it's sitemap name, whilst inside my
Transformer.


Does that make any more sense ;)    ?


regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
   <phone:+44.[0].20.7737.6831>             <pa...@vizzavi.net>

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


Re: Writing a Transformer, getting a Serializer

Posted by Stefano Mazzocchi <st...@apache.org>.
Jeremy Quinn wrote:

> Is this possible?

Is shouldn't.

> Am I looking at this the right way?

I think so, what are you trying to achieve?

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------


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