Javier, I agree that it could be easier to do this in a transformer,
but really, in some cases I think the generator is more appropriate,
and in my case I will be more comfortable with a generator.


Transformation happens on streams, and don't know about the source of
the this stream.
In my case, I need to generate events from a file, and validate the
file references. This generator will read from file system, and check
if the links are available and not broken.
I don't think it's convenient to educate the transformer about the
source of the events in order to resolve relative links. I completely
understand you, but it's just more convenient for me and my team to do
it in a generator.

I looked into the examples, and had a look at the source of the file generator:
http://www.docjar.com/html/api/org/apache/cocoon/generation/FileGenerator.java.html

On line 116:
  116               SourceUtil.parse(this.manager, this.inputSource,
super.xmlConsumer);

I am assuming that we are sending the events directly to xmlConsumer.
So to be to do things my way, I need to create a Custom source, and
attach it to a custom XMLConsumer that will pass these events through
an XMLFilterImpl.
Or, I can implement the logic directly in the XMLConsumer, which will
make the logic dependent on Cocoon.

Is this the only way to handle events in a Generator ??



On Thu, Dec 6, 2012 at 4:36 PM, Javier Puerto <jpue...@gmail.com> wrote:
>
> El 06/12/2012 20:40, "gelo1234" <gelo1...@gmail.com> escribió:
>
>
>>
>>
>> But you should really consider using Transformer as Jaxier suggested.
>> Thats what "filters" XML data in Cocoon so acts as a Filter.
>
> Exactly, recently I have to migrate a Cocoon application to pure java and
> transformers are just XMLFilters. That's why I suggest this approach. If you
> can't do it with xslt you can create your own transformer.
>
>> If you need to do this in Java (write your own Transformer [Filter]), you
>> can take a look at one of the simplest Transformers
>> in Cocoon sources: CleaningTransformer
>>
>>
>> cocoon-sax/src/main/java/org/apache/cocoon/sax/component/CleaningTransformer.java
>>
>> You just consume SAX events and generate new ones :)
>>
>> Greetings,
>> Greg
>>
>>
>>
>> 2012/12/6 gelo1234 <gelo1...@gmail.com>
>>>
>>>
>>> If you need to do this in generator why not writing your own Generator ?
>>> that extends AbstractSAXGenerator ?
>>> You can find example in:
>>> cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/
>>>
>>> Greetings,
>>> Greg
>>>
>>>
>>> 2012/12/6 Mansour Al Akeel <mansour.alak...@gmail.com>
>>>>
>>>> Javier, thank you for replying.
>>>> For many additional reasons, I need to do this in a generator. It's
>>>> not my call on this. So I need to connect the XMLFilterImpl to the
>>>> Generator.
>>>> I know it can be done, but looking for the simplest and cleanest way.
>>>>
>>>>
>>>> On Thu, Dec 6, 2012 at 12:25 PM, Javier Puerto <jpue...@gmail.com>
>>>> wrote:
>>>> > Hi Mansour,
>>>> >
>>>> > 2012/12/6 Mansour Al Akeel <mansour.alak...@gmail.com>
>>>> >>
>>>> >> Hello all,
>>>> >> I am using C2.2 for this project, and I need to add some
>>>> >> functionality
>>>> >> to the current file generator (ie, logging and warning for broken
>>>> >> links). I know this can be done in a transformer,
>>>> >> but since it's required in many places, I want it in the Generator.
>>>> >>
>>>> >>
>>>> >> Since the generator, generates SAX events, the simplest way is to
>>>> >> insert an XMLFilterImpl that does the logging, between the generator
>>>> >> and the consumer. For example:
>>>> >
>>>> >
>>>> > I think that use a Transformer is the Cocoon way and simplest (no need
>>>> > of
>>>> > java code).
>>>> >
>>>> > <map:pipeline match="myCustomFileGenerator/**">
>>>> >   <map:generator src="{1}"/>
>>>> >   <map:transform src="yourXSLT"/>
>>>> >   <mao:serialize/>
>>>> > </map:pipeline>
>>>> >
>>>> > Then you can use from other pipelines in the same sitemap like this:
>>>> >
>>>> > <map:pipeline match="my/service">
>>>> >   <map:generate
>>>> > src="cocoon:/myCustomFileGenerator/your/file/to/consume"/>
>>>> >   ....
>>>> >
>>>> > From another block you can consume also with the sevlet: protocol,
>>>> > just add
>>>> > the name of the block with the service you want to consume:
>>>> > <map:pipeline match="my/service">
>>>> >   <map:generate
>>>> > src="servlet:myBlock:/myCustomFileGenerator/your/file/to/consume"/>
>>>> >
>>>> >
>>>> >>
>>>> >> Currently:
>>>> >>
>>>> >> FileGenerator --> events ---> XMLConsumer
>>>> >>
>>>> >> I need it to be:
>>>> >>
>>>> >> FileGenerator --> events --> XMLFilterImpl ---> XMLConsumer
>>>> >> OR
>>>> >> FileGenerator --> events ---> XMLConsumer --> XMLFilterImpl
>>>> >>
>>>> >> The issue is I couldn't find any example on connecting and setting up
>>>> >> a filter between the generator and the consumer.
>>>> >> Additionally, setting the contentHandler doesn't seem to have any
>>>> >> effect. Currently this is what I have and the events are not passing
>>>> >> through LinkValidator Filter.
>>>> >>
>>>> >>
>>>> >> public class MyGenerator extends FileGenerator {
>>>> >>
>>>> >>         @Override
>>>> >>         public void setup(SourceResolver resolver, Map objectModel,
>>>> >> String
>>>> >> src, Parameters parameters) throws ProcessingException, SAXException,
>>>> >> IOException {
>>>> >>
>>>> >>                 super.setup(resolver, objectModel, src, parameters);
>>>> >>
>>>> >>                 LinkValidator validator = new
>>>> >> LinkValidator(this.contentHandler);
>>>> >>
>>>> >>                 this.setContentHandler(validator);
>>>> >>
>>>> >>         }
>>>> >>
>>>> >>         @Override
>>>> >>         public void generate() throws IOException, SAXException,
>>>> >> ProcessingException {
>>>> >>                 super.generate();
>>>> >>         }
>>>> >>
>>>> >> }
>>>> >>
>>>> >>
>>>> >> Thank you
>>>> >
>>>> >
>>>> > If you have implemented the XMLFilter already, you can easily
>>>> > transform into
>>>> > a Cocoon transformer, the interface is very similar.
>>>> >
>>>> > Salu2.
>>>> >
>>>> >>
>>>> >>
>>>> >> ---------------------------------------------------------------------
>>>> >> To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
>>>> >> For additional commands, e-mail: users-h...@cocoon.apache.org
>>>> >>
>>>> >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
>>>> For additional commands, e-mail: users-h...@cocoon.apache.org
>>>>
>>>
>>

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

Reply via email to