On Fri, Apr 16, 2004 at 11:49:28AM -0700, Christopher Oliver wrote:
> Another approach is to stream it into a SaxBuffer (which implements 
> XMLizable and therefore will be automatically streamed by 
> JXTemplateGenerator). Something like this:
> 
> // parse "string" sending SAX events to "consumer"
> function toSAX(string, consumer) {
>  var is = new org.xml.sax.InputSource(new java.io.StringReader(string));
>  var parser = null;
>  try {
>    parser = 
> cocoon.getComponent(org.apache.excalibur.xml.sax.SAXParser.ROLE);
>    // Create a filter to remove the start document and end document events
>    var contentHandlerWrapper =
>      new org.apache.cocoon.xml.ContentHandlerWrapper() {
>        startDocument: function() {
>          // inhibit this event
>        }
>        endDocument: function() {
>          // inhibit this event
>        }
>    };
>    contentHandlerWrapper.contentHandler = consumer;
>    contentHandlerWrapper.lexicalHandler = consumer;
>    parser.parse(is, contentHandlerWrapper);
>  } finally {
>    if (parser != null) {
>      cocoon.releaseComponent(parser);
>    }
>  }
> }
Thanks a lot. After fixing some typos this code works perfectly fine. I tried
to omit the ContentHandlerWrapper and it also works (commented out in the
code).

Would it be accepted if I provided a patch to JXTemplateGenerator so it parses
a new tag jx:outputxml to implement this functionality?


var str = "<p>here is some <b>bolded</b> text</p>";
var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( str ) );
var parser = null;
var consumer = new Packages.org.apache.cocoon.xml.SaxBuffer();

try {   
        parser = cocoon.getComponent( 
Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE );
/*      
        var contentHandlerWrapper = 
                new JavaAdapter( Packages.org.apache.cocoon.xml.ContentHandlerWrapper, 
                                                {
                                                        startDocument: function() {},
                                                        endDocument: function() {}
                                                } );
        
        contentHandlerWrapper.setContentHandler( consumer );
        contentHandlerWrapper.setLexicalHandler( consumer );
*/
        parser.parse( is, consumer );   
} finally {
        if ( parser != null ) cocoon.releaseComponent( parser );
}
cocoon.sendPage( "view/test.jx", { buffer: consumer } );

> 
> 
> I guess you could even avoid the sax buffer and stream it directly in 
> the template:
> 
> // flowscript fragment
> var message = ...;
> sendPage("page.html", {message: message, streamer: {toSAX: toSAX}});
> 
> 
> // jx template fragment
> <jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
> ...
> <jx:set var="ignored" value="${streamer.toSAX(message.content, 
> cocoon.consumer}}"/>
> ...
> </jx/template>
Works also.

Is there some kind of "object AOP"? I mean is there a way to provide every
bizData with this streamer without explicitly declaring? I have a lot of
application context variables apart from this new streamer I would like to
expose to every view.
        lg
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/       [EMAIL PROTECTED]           _\\()//_
         .'/()\'.     Phone: +48(501)720812     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to