My first guess would be in (cocoon-sax) org.apache.cocoon.sax.util but let's wait for a few more replies.
Robby
-----Original Message-----
From:
simone.tripodi@... [mailto:
simone.tripodi@...] On Behalf Of Simone Tripodi
Sent: Monday, April 23, 2012 4:42 PM
To:
dev@...
Subject: Re: potential SAX builder helper class
thanks a lot for the quick reply Robby!
do you already have an idea where that class should be placed?
TIA!
-Simo
http://people.apache.org/~simonetripodi/http://simonetripodi.livejournal.com/http://twitter.com/simonetripodihttp://www.99soft.org/On Mon, Apr 23, 2012 at 4:40 PM, Robby Pelssers <
Robby.Pelssers@...> wrote:
> Looks definitely like an improvement in usability. +1
>
> Robby
>
> -----Original Message-----
> From:
simone.tripodi@... [mailto:
simone.tripodi@...] On Behalf Of Simone Tripodi
> Sent: Monday, April 23, 2012 4:36 PM
> To:
dev@...
> Subject: potential SAX builder helper class
>
> Hi all guys,
>
> One thing I've always found a little "annoying" - "boring" is maybe
> the more appropriate therm - of SAX APIs is that, when crating even
> simple XML snippets via ContentHandler APIs, the following boilerplate
> code has to be written:
>
> +--------+
> ContentHandler handler = ... ;
> contentHandler.startDocument();
> contentHandler.startElement( "", "project", "project", new AttributesImpl() );
> contentHandler.startElement( "", "modelVersion", "modelVersion", new
> AttributesImpl() );
>
> String modelVersion = "4.0.0";
> contentHandler.characters( modelVersion.toCharArray(), 0,
> modelVersion.length() );
>
> contentHandler.endElement( "", "modelVersion", "modelVersion" );
> contentHandler.endElement( "", "project", "project", new AttributesImpl() );
> contentHandler.endDocument();
> +--------+
>
> I think you would agree with me that to obtain the following snippet
>
> +--------+
> <?xml version="1.0" encoding="UTF-8"?>
> <project>
> <modelVersion>4.0.0</modelVersion>
> </project>
> +--------+
>
> that code is maybe an overkill :P
>
> So, at company I developed a small SAX wrapper that would help on
> transforming the previous code in the following:
>
> +--------+
> ContentHandler handler = ... ;
> SAXEventsBuilder.newDocument( transformerHandler )
> .start( "project" )
> .start( "modelVersion" ).body( "4.0.0" ).end()
> .end()
> .endDocument();
> +--------+
>
> isn't more "sexy"? It still supports elements that require
> namespaces/attributes but reduces the lines of code for hardcoded XML
> documents - especially when closing elements.
>
> It also allows users to add manually-generated elements in an existing
> ContentHandler:
> +--------+
> ContentHandler handler = ... ;
> SAXEventsBuilder.wrap( transformerHandler )
> .start( "modelVersion" ).body( "4.0.0" ).end()
> .start( "groupId" ).body( "org.apache.cocoon.sax" ).end()
> .start( "artifactId" ).body( "cocoon-sax" ).end()
> .start( "version" ).body( "3.0.0-beta-1" ).end()
> +--------+
>
> without starting/closing the document.
>
> If you like it, I would be pleased to commit it in the Cocoon repo -
> as a side question: which component that would fill?
>
> Many thanks in advance, all the best!
> -Simo
>
>
http://people.apache.org/~simonetripodi/>
http://simonetripodi.livejournal.com/>
http://twitter.com/simonetripodi>
http://www.99soft.org/