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);
}
}
}



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>



Chris


Ugo Cei wrote:

Leszek Gawron wrote:

Imagine I have a bean fetched from database. Call it a Message. A Message has
a String getContent() method. Now this string contains not a plain text but an
X(HT)ML piece. What is the most elegant, fastest and most convenient way to
make JXTemplate treat it as a node instead of displaying the tags as text ?
lg



Parse the string, get the DOM and pass it to the template.


Ugo



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




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



Reply via email to