[doxia-dev] [PATCH] Sink validation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[doxia-dev] [PATCH] Sink validation

Juan F. Codagnone

Hi,
 in the past day i've been writting a twiki parser for doxia. It isn't done
yet, but i started to convert some text using existing Sinks, and while doing
that i've found some problems:
  None of the sinks tries to validates a correct usage. For example in most of
sinks,
      sink.list();
      sint.listItem_();
would generate an invalid output, and you don't find that until you process
the output. I found this a bit fragile.

To solve it, i've created an AdvicedSink class that is a proxy implementation
of a Sink, where you can inject some Advisors to do some crosscutting
validations. The advisors are like AOP and you only must implement one method
instead of the 89 of the Sink.

I've implemented two advisors: one that prints the the sink calls with
indentation:
        head
        head_
        body
           section1
              sectionTitle
                 text
        ...
usefull for debuging, and one that throws a runtime exception if the closing
element doesn't match with the starting, in cases like:
      sink.list();
      sint.listItem_();

In the future i would like to see an advisor that check in a fine grain the
sink events. For example in the XdocSink if i do
      sink.listItem();
      sink.text("foo");
      sink.listItem_();
wrong code is generated, and i must do:
      sink.listItem();
      sink.paragraph();
      sink.text("foo");
      sink._paragraph();
      sink.listItem_();
to get the correct content. And state machine advisor would only allow to call
paragraph item a listitem and that would be reusable for all the sinks.

Example of use:
     final Sink sink = new AdvicedSink(new MethodBeforeAdvice[] {
                new PrintAdvisor(System.out),
                new HangingElementAdvice(),
     }, new XdocSink(writer));

I hope you found it usefull as i do.

Regards,
    Juan.

--
Buenos Aires, Argentina                           17°C with winds at 22 km/h E

doxia-sink-common.tar.gz (9K) Download Attachment
attachment1 (161 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [doxia-dev] [PATCH] Sink validation

Juan F. Codagnone
On Sunday 06 November 2005 19:44, Juan F. Codagnone wrote:
> Hi,
...
> I hope you found it usefull as i do.
>
> Regards,
>     Juan.

i forgot of some things in the previus tarball...

--
Buenos Aires, Argentina                           15°C with winds at 24 km/h E

doxia-sink-common.tar.gz (10K) Download Attachment
attachment1 (161 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [doxia-dev] [PATCH] Sink validation

Emmanuel Venisse-2
Please, filed a jira issue.

Thanks
Emmanuel

Juan F. Codagnone a ?crit :

> On Sunday 06 November 2005 19:44, Juan F. Codagnone wrote:
>
>>Hi,
>
> ...
>
>>I hope you found it usefull as i do.
>>
>>Regards,
>>    Juan.
>
>
> i forgot of some things in the previus tarball...
>