You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Bent André Solheim <be...@gmail.com> on 2004/11/11 15:16:06 UTC

Passing a parameter from custome generator to transformer

Hi Cocoon users.

I'm developing an application where we keep thousands of gzipped xml
documents in some 20 different formats in a legacy relational
database. These documents can be accessed using a document id. I have
written a custom generator that retrieves a gzipped document from the
database based on a request parameter, unzips it, and passes sax
events on to a transformer. Which transformation the transformer
should use was earlier passed as a request parameter along with the
document id, but new requirements dictates that only the document id
can be passed as parameter. Now I have to look the transformation id
up in a database (in the same table as the gzipped xml document).

The application will be under heavy load constantly, so I would like
to minimize the number of database accesses pr. request. Hence, I
would like to look up the gzipped xml data and the transformation id
in one query. My question is; is there a way for my custom generator
to pass the transformation id to the next transformer in the pipeline
(file based)? Or do I need to write my own transformer that looks up
the transformation id based on the document id request parameter and
figures out what transformation to apply by it self?

To summarize; is there a way for my generator to tell the next
transformer which transformation to use?

Any suggestion would be recieved with great appreciation! :)

Best regards
Bent André Solheim

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


Re: Passing a parameter from custome generator to transformer

Posted by Jorg Heymans <jh...@domek.be>.
Are you using a custom transformer ? Post your pipeline snippet + 
relevant code if possible so we have something more to work with.

BTW there is also a setup() method you can override. This is called 
during pipeline setup - before any components are executed.

Regards
Jorg Heymans


Bent André Solheim wrote:
> First of all, thank you for your answer Jorg!
> 
> I'm having a bit trouble with your suggestion. It appears the
> transformer is configured after MyGenerator.compose(ComponentManager),
> but before MyGenerator.generate(). It is in generate() I look up the
> transformation id and put it in the Request, so when the transformer
> is being configured, the parameter is not set, and I get a
> FileNotFoundException (Unable to get transformer handler for file...).
> 
> I cannot do the lookup in compose, because this is only called on
> generator creation. Have I misunderstood something here?
> 
> 
> Best regards,
> Bent.
> 
> On Thu, 11 Nov 2004 15:30:09 +0100, Jorg Heymans <jh...@domek.be> wrote:
> 
>>you can make your generator set a request attribute, and retrieve it in
>>the sitemap via the request-attr module .
>>
>>Note that you cannot make the transformer *type* dynamic.
>>
>>If you want to execute a different pipeline depending on parameters then
>>i think you could selectors for this (i've never used them so i could be
>>wrong)
>>
>>does this make sense?
>>
>>Jorg
>>
>>
>>
>>Bent André Solheim wrote:
>>
>>>Hi Cocoon users.
>>>
>>>I'm developing an application where we keep thousands of gzipped xml
>>>documents in some 20 different formats in a legacy relational
>>>database. These documents can be accessed using a document id. I have
>>>written a custom generator that retrieves a gzipped document from the
>>>database based on a request parameter, unzips it, and passes sax
>>>events on to a transformer. Which transformation the transformer
>>>should use was earlier passed as a request parameter along with the
>>>document id, but new requirements dictates that only the document id
>>>can be passed as parameter. Now I have to look the transformation id
>>>up in a database (in the same table as the gzipped xml document).
>>>
>>>The application will be under heavy load constantly, so I would like
>>>to minimize the number of database accesses pr. request. Hence, I
>>>would like to look up the gzipped xml data and the transformation id
>>>in one query. My question is; is there a way for my custom generator
>>>to pass the transformation id to the next transformer in the pipeline
>>>(file based)? Or do I need to write my own transformer that looks up
>>>the transformation id based on the document id request parameter and
>>>figures out what transformation to apply by it self?
>>>
>>>To summarize; is there a way for my generator to tell the next
>>>transformer which transformation to use?
>>>
>>>Any suggestion would be recieved with great appreciation! :)
>>>
>>>Best regards
>>>Bent André Solheim
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>


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


Re: Passing a parameter from custome generator to transformer

Posted by Bent André Solheim <be...@gmail.com>.
Thank you guys. This really helps! I'll look at how to build an action
that will do the xml lookup and unzip, and put the extracted xml in
the request first thing in the morning.

Really appreciate your help!

Best regards
Bent.


On Thu, 11 Nov 2004 17:40:33 +0100, Jorg Heymans <jh...@domek.be> wrote:
> Thanks for setting things crispy clear Joerg :=)
> 
> Jorg (going back to read the cocoon internals manual)
> 
> 
> 
> Joerg Heinicke wrote:
> > On 11.11.2004 16:41, Bent André Solheim wrote:
> >
> >> First of all, thank you for your answer Jorg!
> >>
> >> I'm having a bit trouble with your suggestion. It appears the
> >> transformer is configured after MyGenerator.compose(ComponentManager),
> >> but before MyGenerator.generate(). It is in generate() I look up the
> >> transformation id and put it in the Request, so when the transformer
> >> is being configured, the parameter is not set, and I get a
> >> FileNotFoundException (Unable to get transformer handler for file...).
> >>
> >> I cannot do the lookup in compose, because this is only called on
> >> generator creation. Have I misunderstood something here?
> >
> >
> > Unfortunately Jorg's suggestion can not work. You have a component
> > configuration phase (compose() in your case), a pipeline build phase, a
> > pipeline components setup phase (setup()) and a execution phase
> > (generate()). When the first SAX event has left the generator (out of
> > generate()), the transformation starts immediately. So, no chance to do
> > it appropriately here.
> >
> >> On Thu, 11 Nov 2004 15:30:09 +0100, Jorg Heymans <jh...@domek.be> wrote:
> >>
> >>> you can make your generator set a request attribute, and retrieve it in
> >>> the sitemap via the request-attr module .
> >
> >
> > The pipeline is already been setup when the generator is to be setup.
> > This means for changing the pipeline it is to late. And changing the
> > transformation in which way ever dynamically sounds like a hack.
> >
> >>> Note that you cannot make the transformer *type* dynamic.
> >
> >
> > Exactly.
> >
> >>> If you want to execute a different pipeline depending on parameters then
> >>> i think you could selectors for this (i've never used them so i could be
> >>> wrong)
> >
> >
> > This is part of pipeline build phase, i.e. where the pipeline components
> > for this pipeline are chosen. A parameter set by the generator can not
> > be used.
> >
> >>>> I'm developing an application where we keep thousands of gzipped xml
> >>>> documents in some 20 different formats in a legacy relational
> >>>> database. These documents can be accessed using a document id. I have
> >>>> written a custom generator that retrieves a gzipped document from the
> >>>> database based on a request parameter, unzips it, and passes sax
> >>>> events on to a transformer. Which transformation the transformer
> >>>> should use was earlier passed as a request parameter along with the
> >>>> document id, but new requirements dictates that only the document id
> >>>> can be passed as parameter. Now I have to look the transformation id
> >>>> up in a database (in the same table as the gzipped xml document).
> >>>>
> >>>> The application will be under heavy load constantly, so I would like
> >>>> to minimize the number of database accesses pr. request. Hence, I
> >>>> would like to look up the gzipped xml data and the transformation id
> >>>> in one query. My question is; is there a way for my custom generator
> >>>> to pass the transformation id to the next transformer in the pipeline
> >>>> (file based)? Or do I need to write my own transformer that looks up
> >>>> the transformation id based on the document id request parameter and
> >>>> figures out what transformation to apply by it self?
> >>>>
> >>>> To summarize; is there a way for my generator to tell the next
> >>>> transformer which transformation to use?
> >
> >
> > No. But there is a component that can do this for you. The actions are
> > executed before and used for building the pipeline. Let an action
> > execute your query and pass the id to the generator and the transformer.
> > The action can also retrieve the document and store it in the request
> > from where the generator can get it.
> >
> > Joerg
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

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


Re: Passing a parameter from custome generator to transformer

Posted by Jorg Heymans <jh...@domek.be>.
Thanks for setting things crispy clear Joerg :=)


Jorg (going back to read the cocoon internals manual)

Joerg Heinicke wrote:
> On 11.11.2004 16:41, Bent André Solheim wrote:
> 
>> First of all, thank you for your answer Jorg!
>>
>> I'm having a bit trouble with your suggestion. It appears the
>> transformer is configured after MyGenerator.compose(ComponentManager),
>> but before MyGenerator.generate(). It is in generate() I look up the
>> transformation id and put it in the Request, so when the transformer
>> is being configured, the parameter is not set, and I get a
>> FileNotFoundException (Unable to get transformer handler for file...).
>>
>> I cannot do the lookup in compose, because this is only called on
>> generator creation. Have I misunderstood something here?
> 
> 
> Unfortunately Jorg's suggestion can not work. You have a component 
> configuration phase (compose() in your case), a pipeline build phase, a 
> pipeline components setup phase (setup()) and a execution phase 
> (generate()). When the first SAX event has left the generator (out of 
> generate()), the transformation starts immediately. So, no chance to do 
> it appropriately here.
> 
>> On Thu, 11 Nov 2004 15:30:09 +0100, Jorg Heymans <jh...@domek.be> wrote:
>>
>>> you can make your generator set a request attribute, and retrieve it in
>>> the sitemap via the request-attr module .
> 
> 
> The pipeline is already been setup when the generator is to be setup. 
> This means for changing the pipeline it is to late. And changing the 
> transformation in which way ever dynamically sounds like a hack.
> 
>>> Note that you cannot make the transformer *type* dynamic.
> 
> 
> Exactly.
> 
>>> If you want to execute a different pipeline depending on parameters then
>>> i think you could selectors for this (i've never used them so i could be
>>> wrong)
> 
> 
> This is part of pipeline build phase, i.e. where the pipeline components 
> for this pipeline are chosen. A parameter set by the generator can not 
> be used.
> 
>>>> I'm developing an application where we keep thousands of gzipped xml
>>>> documents in some 20 different formats in a legacy relational
>>>> database. These documents can be accessed using a document id. I have
>>>> written a custom generator that retrieves a gzipped document from the
>>>> database based on a request parameter, unzips it, and passes sax
>>>> events on to a transformer. Which transformation the transformer
>>>> should use was earlier passed as a request parameter along with the
>>>> document id, but new requirements dictates that only the document id
>>>> can be passed as parameter. Now I have to look the transformation id
>>>> up in a database (in the same table as the gzipped xml document).
>>>>
>>>> The application will be under heavy load constantly, so I would like
>>>> to minimize the number of database accesses pr. request. Hence, I
>>>> would like to look up the gzipped xml data and the transformation id
>>>> in one query. My question is; is there a way for my custom generator
>>>> to pass the transformation id to the next transformer in the pipeline
>>>> (file based)? Or do I need to write my own transformer that looks up
>>>> the transformation id based on the document id request parameter and
>>>> figures out what transformation to apply by it self?
>>>>
>>>> To summarize; is there a way for my generator to tell the next
>>>> transformer which transformation to use?
> 
> 
> No. But there is a component that can do this for you. The actions are 
> executed before and used for building the pipeline. Let an action 
> execute your query and pass the id to the generator and the transformer. 
> The action can also retrieve the document and store it in the request 
> from where the generator can get it.
> 
> Joerg


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


Re: Passing a parameter from custome generator to transformer

Posted by Joerg Heinicke <jo...@gmx.de>.
On 11.11.2004 16:41, Bent André Solheim wrote:
> First of all, thank you for your answer Jorg!
> 
> I'm having a bit trouble with your suggestion. It appears the
> transformer is configured after MyGenerator.compose(ComponentManager),
> but before MyGenerator.generate(). It is in generate() I look up the
> transformation id and put it in the Request, so when the transformer
> is being configured, the parameter is not set, and I get a
> FileNotFoundException (Unable to get transformer handler for file...).
> 
> I cannot do the lookup in compose, because this is only called on
> generator creation. Have I misunderstood something here?

Unfortunately Jorg's suggestion can not work. You have a component 
configuration phase (compose() in your case), a pipeline build phase, a 
pipeline components setup phase (setup()) and a execution phase 
(generate()). When the first SAX event has left the generator (out of 
generate()), the transformation starts immediately. So, no chance to do 
it appropriately here.

> On Thu, 11 Nov 2004 15:30:09 +0100, Jorg Heymans <jh...@domek.be> wrote:
> 
>>you can make your generator set a request attribute, and retrieve it in
>>the sitemap via the request-attr module .

The pipeline is already been setup when the generator is to be setup. 
This means for changing the pipeline it is to late. And changing the 
transformation in which way ever dynamically sounds like a hack.

>>Note that you cannot make the transformer *type* dynamic.

Exactly.

>>If you want to execute a different pipeline depending on parameters then
>>i think you could selectors for this (i've never used them so i could be
>>wrong)

This is part of pipeline build phase, i.e. where the pipeline components 
for this pipeline are chosen. A parameter set by the generator can not 
be used.

>>>I'm developing an application where we keep thousands of gzipped xml
>>>documents in some 20 different formats in a legacy relational
>>>database. These documents can be accessed using a document id. I have
>>>written a custom generator that retrieves a gzipped document from the
>>>database based on a request parameter, unzips it, and passes sax
>>>events on to a transformer. Which transformation the transformer
>>>should use was earlier passed as a request parameter along with the
>>>document id, but new requirements dictates that only the document id
>>>can be passed as parameter. Now I have to look the transformation id
>>>up in a database (in the same table as the gzipped xml document).
>>>
>>>The application will be under heavy load constantly, so I would like
>>>to minimize the number of database accesses pr. request. Hence, I
>>>would like to look up the gzipped xml data and the transformation id
>>>in one query. My question is; is there a way for my custom generator
>>>to pass the transformation id to the next transformer in the pipeline
>>>(file based)? Or do I need to write my own transformer that looks up
>>>the transformation id based on the document id request parameter and
>>>figures out what transformation to apply by it self?
>>>
>>>To summarize; is there a way for my generator to tell the next
>>>transformer which transformation to use?

No. But there is a component that can do this for you. The actions are 
executed before and used for building the pipeline. Let an action 
execute your query and pass the id to the generator and the transformer. 
The action can also retrieve the document and store it in the request 
from where the generator can get it.

Joerg

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


Re: Passing a parameter from custome generator to transformer

Posted by Bent André Solheim <be...@gmail.com>.
First of all, thank you for your answer Jorg!

I'm having a bit trouble with your suggestion. It appears the
transformer is configured after MyGenerator.compose(ComponentManager),
but before MyGenerator.generate(). It is in generate() I look up the
transformation id and put it in the Request, so when the transformer
is being configured, the parameter is not set, and I get a
FileNotFoundException (Unable to get transformer handler for file...).

I cannot do the lookup in compose, because this is only called on
generator creation. Have I misunderstood something here?


Best regards,
Bent.

On Thu, 11 Nov 2004 15:30:09 +0100, Jorg Heymans <jh...@domek.be> wrote:
> you can make your generator set a request attribute, and retrieve it in
> the sitemap via the request-attr module .
> 
> Note that you cannot make the transformer *type* dynamic.
> 
> If you want to execute a different pipeline depending on parameters then
> i think you could selectors for this (i've never used them so i could be
> wrong)
> 
> does this make sense?
> 
> Jorg
> 
> 
> 
> Bent André Solheim wrote:
> > Hi Cocoon users.
> >
> > I'm developing an application where we keep thousands of gzipped xml
> > documents in some 20 different formats in a legacy relational
> > database. These documents can be accessed using a document id. I have
> > written a custom generator that retrieves a gzipped document from the
> > database based on a request parameter, unzips it, and passes sax
> > events on to a transformer. Which transformation the transformer
> > should use was earlier passed as a request parameter along with the
> > document id, but new requirements dictates that only the document id
> > can be passed as parameter. Now I have to look the transformation id
> > up in a database (in the same table as the gzipped xml document).
> >
> > The application will be under heavy load constantly, so I would like
> > to minimize the number of database accesses pr. request. Hence, I
> > would like to look up the gzipped xml data and the transformation id
> > in one query. My question is; is there a way for my custom generator
> > to pass the transformation id to the next transformer in the pipeline
> > (file based)? Or do I need to write my own transformer that looks up
> > the transformation id based on the document id request parameter and
> > figures out what transformation to apply by it self?
> >
> > To summarize; is there a way for my generator to tell the next
> > transformer which transformation to use?
> >
> > Any suggestion would be recieved with great appreciation! :)
> >
> > Best regards
> > Bent André Solheim
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

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


Re: Passing a parameter from custome generator to transformer

Posted by Jorg Heymans <jh...@domek.be>.
you can make your generator set a request attribute, and retrieve it in 
the sitemap via the request-attr module .

Note that you cannot make the transformer *type* dynamic.

If you want to execute a different pipeline depending on parameters then 
i think you could selectors for this (i've never used them so i could be 
wrong)

does this make sense?

Jorg

Bent André Solheim wrote:
> Hi Cocoon users.
> 
> I'm developing an application where we keep thousands of gzipped xml
> documents in some 20 different formats in a legacy relational
> database. These documents can be accessed using a document id. I have
> written a custom generator that retrieves a gzipped document from the
> database based on a request parameter, unzips it, and passes sax
> events on to a transformer. Which transformation the transformer
> should use was earlier passed as a request parameter along with the
> document id, but new requirements dictates that only the document id
> can be passed as parameter. Now I have to look the transformation id
> up in a database (in the same table as the gzipped xml document).
> 
> The application will be under heavy load constantly, so I would like
> to minimize the number of database accesses pr. request. Hence, I
> would like to look up the gzipped xml data and the transformation id
> in one query. My question is; is there a way for my custom generator
> to pass the transformation id to the next transformer in the pipeline
> (file based)? Or do I need to write my own transformer that looks up
> the transformation id based on the document id request parameter and
> figures out what transformation to apply by it self?
> 
> To summarize; is there a way for my generator to tell the next
> transformer which transformation to use?
> 
> Any suggestion would be recieved with great appreciation! :)
> 
> Best regards
> Bent André Solheim


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