You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Terry Brick <te...@yahoo.com> on 2004/06/09 01:09:38 UTC

REQ: An "escapeXml" attribute in JXT macro/script output

Hello,
This request is carried over from the users list regarding introducing XML from a
variable/component into the JXT output stream.
For example, let's say I have Java bean with a String property that holds XML text.  If, in my
template, I do something like...
${MyBean.XML}
... Then all of the XML characters are escaped.
For example,
<para>
..becomes..
&lt;para&gt;

I would think that for most Cocoon users, this is undesirable behavior most of the time.
The current workaround is to have the bean property return a DOM Document instead of a String. 
However, in many cases, other than to accomodate this workaround, I have no other need to create a
DOM document within my Java component.... so it seems like there could be some unecessary overhead
associated with doing that.  I guess that depends on how Cocoon handles the doc... maybe it's a
wash.
Anyway, an escapeXml="true/false" attribute on the JX output tags (similar to JSTL) would
certainly be handy IMO.

Thanks!


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Terry Brick <te...@yahoo.com>.
> I think this is not the good way to do that. What if the input string 
> was a wiki entry. It is also some kind of input data formatting.

The idea is to give the user control of the output.  So if, in the case you mention, you wanted
the XML escaped (as it is currently doing), then the attribute would read escapeXml="true" (as is
the current default and the *only* option in the tag).  In most of my instances, I would be doing
escapeXml="false".
In my mind, the current functionality would be considered more "data formatting"... but the
problem is it's doing it whether we want it or not.

> 
> We need taglibs for jx. Could the functionality of TagTransformer be 
> merged with JXTemplateGenerator?

I agree... taglibs would be very nice.  Seems like JSTL could be incorporated.



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Joerg Heinicke wrote:

> On 09.06.2004 01:09, Terry Brick wrote:
> 
>> This request is carried over from the users list regarding introducing 
>> XML from a
>> variable/component into the JXT output stream.
>> For example, let's say I have Java bean with a String property that 
>> holds XML text.  If, in my
>> template, I do something like...
>> ${MyBean.XML}
>> ... Then all of the XML characters are escaped.
>> For example,
>> <para>
>> ..becomes..
>> &lt;para&gt;
>>
>> I would think that for most Cocoon users, this is undesirable behavior 
>> most of the time.
>> The current workaround is to have the bean property return a DOM 
>> Document instead of a String. However, in many cases, other than to 
>> accomodate this workaround, I have no other need to create a
>> DOM document within my Java component.... so it seems like there could 
>> be some unecessary overhead
>> associated with doing that.  I guess that depends on how Cocoon 
>> handles the doc... maybe it's a
>> wash.
>> Anyway, an escapeXml="true/false" attribute on the JX output tags 
>> (similar to JSTL) would
>> certainly be handy IMO.
> 
> 
> Can you file a feature request to buzilla?
I think this is not the good way to do that. What if the input string 
was a wiki entry. It is also some kind of input data formatting.

We need taglibs for jx. Could the functionality of TagTransformer be 
merged with JXTemplateGenerator?
	
-- 
Leszek Gawron                                      lgawron@mobilebox.pl


Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Joerg Heinicke <jo...@gmx.de>.
On 09.06.2004 01:09, Terry Brick wrote:

> This request is carried over from the users list regarding introducing XML from a
> variable/component into the JXT output stream.
> For example, let's say I have Java bean with a String property that holds XML text.  If, in my
> template, I do something like...
> ${MyBean.XML}
> ... Then all of the XML characters are escaped.
> For example,
> <para>
> ..becomes..
> &lt;para&gt;
> 
> I would think that for most Cocoon users, this is undesirable behavior most of the time.
> The current workaround is to have the bean property return a DOM Document instead of a String. 
> However, in many cases, other than to accomodate this workaround, I have no other need to create a
> DOM document within my Java component.... so it seems like there could be some unecessary overhead
> associated with doing that.  I guess that depends on how Cocoon handles the doc... maybe it's a
> wash.
> Anyway, an escapeXml="true/false" attribute on the JX output tags (similar to JSTL) would
> certainly be handy IMO.

Can you file a feature request to buzilla?

Thanks,

Joerg


Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Terry Brick wrote:

> Thanks for the reply.  I have a similar workaround, but I do consider it a 'workaround'.  If we
> find that a significant number of users are doing things like this, then that tells me simpler,
> 'built-in' approach would be more appropriate.  Maybe this is not the case though... if I'm the
> only one doing this, then there's certainly no need to build it into the framework ;)
I have also found it a workaround and surely cocoon needs a templating 
language with taglibs support. That has already been mentioned on the list but 
no steps were taken. That is why I proposed you that solution.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl


Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Terry Brick <te...@yahoo.com>.
Thanks for the reply.  I have a similar workaround, but I do consider it a 'workaround'.  If we
find that a significant number of users are doing things like this, then that tells me simpler,
'built-in' approach would be more appropriate.  Maybe this is not the case though... if I'm the
only one doing this, then there's certainly no need to build it into the framework ;)


--- Leszek Gawron <lg...@mobilebox.pl> wrote:
> Terry Brick wrote:
> > Hello,
> > This request is carried over from the users list regarding introducing XML from a
> > variable/component into the JXT output stream.
> > For example, let's say I have Java bean with a String property that holds XML text.  If, in my
> > template, I do something like...
> > ${MyBean.XML}
> > ... Then all of the XML characters are escaped.
> > For example,
> > <para>
> > ..becomes..
> > &lt;para&gt;
> > 
> > I would think that for most Cocoon users, this is undesirable behavior most of the time.
> > The current workaround is to have the bean property return a DOM Document instead of a String.
> 
> > However, in many cases, other than to accomodate this workaround, I have no other need to
> create a
> > DOM document within my Java component.... so it seems like there could be some unecessary
> overhead
> > associated with doing that.  I guess that depends on how Cocoon handles the doc... maybe it's
> a
> > wash.
> > Anyway, an escapeXml="true/false" attribute on the JX output tags (similar to JSTL) would
> > certainly be handy IMO.
> > 
> > Thanks!
> Solution:
> 
> >> function stringToSAX( str, consumer, ignoreRootElement ) {
> >> 	var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( str ) );
> >> 	var ignore = ( ignoreRootElement == "true" );
> >> 	var parser = null;
> >> 	var includeConsumer = new org.apache.cocoon.xml.IncludeXMLConsumer( consumer, consumer );
> >> 	includeConsumer.setIgnoreRootElement( true );
> >> 	try {	
> >> 		parser = cocoon.getComponent( Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE );
> >> 		parser.parse( is, includeConsumer );	
> >> 	} finally {
> >> 		if ( parser != null ) cocoon.releaseComponent( parser );
> >> 	}
> >> }
> put it into session by
> cocoon.session.setAttribute( "saxer", stringToSAX  );
> 
> implement a jx:macro:
> >> 	<jx:macro name="xmlize">
> >> 		<jx:parameter name="value"/>
> >> 		<jx:parameter name="ignoreRoot" default="false"/>
> >> 		<jx:set var="ignored" value="${cocoon.session.stringToSAX( value, cocoon.consumer,
> ignoreRoot )}"/>
> >> 	</jx:macro>
> > 
> 
> use it like this:
> 
> <xmlize value="${xmlVal}" ignoreRoot="true"/>
> 
> and you're done.
> 	LG



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

Re: REQ: An "escapeXml" attribute in JXT macro/script output

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Terry Brick wrote:
> Hello,
> This request is carried over from the users list regarding introducing XML from a
> variable/component into the JXT output stream.
> For example, let's say I have Java bean with a String property that holds XML text.  If, in my
> template, I do something like...
> ${MyBean.XML}
> ... Then all of the XML characters are escaped.
> For example,
> <para>
> ..becomes..
> &lt;para&gt;
> 
> I would think that for most Cocoon users, this is undesirable behavior most of the time.
> The current workaround is to have the bean property return a DOM Document instead of a String. 
> However, in many cases, other than to accomodate this workaround, I have no other need to create a
> DOM document within my Java component.... so it seems like there could be some unecessary overhead
> associated with doing that.  I guess that depends on how Cocoon handles the doc... maybe it's a
> wash.
> Anyway, an escapeXml="true/false" attribute on the JX output tags (similar to JSTL) would
> certainly be handy IMO.
> 
> Thanks!
Solution:

>> function stringToSAX( str, consumer, ignoreRootElement ) {
>> 	var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( str ) );
>> 	var ignore = ( ignoreRootElement == "true" );
>> 	var parser = null;
>> 	var includeConsumer = new org.apache.cocoon.xml.IncludeXMLConsumer( consumer, consumer );
>> 	includeConsumer.setIgnoreRootElement( true );
>> 	try {	
>> 		parser = cocoon.getComponent( Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE );
>> 		parser.parse( is, includeConsumer );	
>> 	} finally {
>> 		if ( parser != null ) cocoon.releaseComponent( parser );
>> 	}
>> }
put it into session by
cocoon.session.setAttribute( "saxer", stringToSAX  );

implement a jx:macro:
>> 	<jx:macro name="xmlize">
>> 		<jx:parameter name="value"/>
>> 		<jx:parameter name="ignoreRoot" default="false"/>
>> 		<jx:set var="ignored" value="${cocoon.session.stringToSAX( value, cocoon.consumer, ignoreRoot )}"/>
>> 	</jx:macro>
> 

use it like this:

<xmlize value="${xmlVal}" ignoreRoot="true"/>

and you're done.
	LG