You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Marco Rothe (JIRA)" <de...@velocity.apache.org> on 2009/12/17 12:12:18 UTC

[jira] Created: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

ReferenceInsertionEventHandler called "to often"/need more configuration settings
---------------------------------------------------------------------------------

                 Key: VELOCITY-749
                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
             Project: Velocity
          Issue Type: Bug
    Affects Versions: 1.6.2
            Reporter: Marco Rothe
            Priority: Minor
             Fix For: 1.6.x, 1.7


I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
But I works not as expected in some situations:

Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 

Me &amp; Co. Ltd 

correctly after the EscapeXmlReference.

But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 

* Me &amp;amp; Co. Ltd *  

and not  * Me &amp; Co. Ltd * as output!

This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
"inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.

So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

Posted by "Marco Rothe (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791929#action_12791929 ] 

Marco Rothe commented on VELOCITY-749:
--------------------------------------

Sorry, my browser did'nt show me your example when I leave my comment :-/

> ReferenceInsertionEventHandler called "to often"/need more configuration settings
> ---------------------------------------------------------------------------------
>
>                 Key: VELOCITY-749
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6.2
>            Reporter: Marco Rothe
>            Priority: Minor
>             Fix For: 1.6.x, 1.7
>
>
> I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
> But I works not as expected in some situations:
> Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 
> Me &amp; Co. Ltd 
> correctly after the EscapeXmlReference.
> But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 
> * Me &amp;amp; Co. Ltd *  
> and not  * Me &amp; Co. Ltd * as output!
> This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
> The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
> "inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.
> So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

Posted by "Marco Rothe (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791912#action_12791912 ] 

Marco Rothe commented on VELOCITY-749:
--------------------------------------

Hmm, I can't find anything about escaping references on the wiki! The current behaviour of the EscapeXmlReference handler is nearly useless if there is no way to distinct between internal and real output insertations. Did you know a way to do that with 'sophisticated filtering' ? I would like to see an example or get an hint.

> ReferenceInsertionEventHandler called "to often"/need more configuration settings
> ---------------------------------------------------------------------------------
>
>                 Key: VELOCITY-749
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6.2
>            Reporter: Marco Rothe
>            Priority: Minor
>             Fix For: 1.6.x, 1.7
>
>
> I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
> But I works not as expected in some situations:
> Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 
> Me &amp; Co. Ltd 
> correctly after the EscapeXmlReference.
> But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 
> * Me &amp;amp; Co. Ltd *  
> and not  * Me &amp; Co. Ltd * as output!
> This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
> The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
> "inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.
> So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Issue Comment Edited: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

Posted by "Claude Brisson (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791897#action_12791897 ] 

Claude Brisson edited comment on VELOCITY-749 at 12/17/09 12:22 PM:
--------------------------------------------------------------------

It's too complex to try to configure it, because the frontier between an internal and a real output insertion is very difficult to define.

If you want to control precisely when escaping occurs and when it doesn't, you better inherit EscapeXmlReference in a class of yours.

A quite handy way of handling this, that I often use, is giving prefixes to reference names. For instance, you can have a filter that only escapes references whose name begins by 'xml'.

public class MyXmlEscape extends EscapeXmlReference
{
    public Object referenceInsert( String reference, Object value  ) {
        if (value == null)
        {
            return null;
        }
        if (!value instanceof String || !reference.startsWith("xml"))
        {
            // do not escape
            return value;
        }
        else
        {
            // escape
            return super.referenceInsert(reference, value);
        }
    }
}

That way, you can write :

#set( $test = 'Me & Co. Ltd' )
#set( $xmltest = " * $test * ")
$xmltest

and this will exhibit the expected behaviour.


      was (Author: claude):
    It's too complex to try to configure it, because the frontier between an internal and a real output insertion is very difficult.

If you want to control precisely when escaping occurs and when it doesn't, you better inherit EscapeXmlReference in a class of yours.

A quite handy way of handling this, that I often use, is giving prefixes to reference names. For instance, you can have a filter that only escapes references whose name begins by 'xml'.

public class MyXmlEscape extends EscapeXmlReference
{
    public Object referenceInsert( String reference, Object value  ) {
        if (value == null)
        {
            return null;
        }
        if (!value instanceof String || !reference.startsWith("xml"))
        {
            // do not escape
            return value;
        }
        else
        {
            // escape
            return super.referenceInsert(reference, value);
        }
    }
}

That way, you can write :

#set( $test = 'Me & Co. Ltd' )
#set( $xmltest = " * $test * ")
$xmltest

and this will exhibit the expected behaviour.

  
> ReferenceInsertionEventHandler called "to often"/need more configuration settings
> ---------------------------------------------------------------------------------
>
>                 Key: VELOCITY-749
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6.2
>            Reporter: Marco Rothe
>            Priority: Minor
>             Fix For: 1.6.x, 1.7
>
>
> I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
> But I works not as expected in some situations:
> Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 
> Me &amp; Co. Ltd 
> correctly after the EscapeXmlReference.
> But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 
> * Me &amp;amp; Co. Ltd *  
> and not  * Me &amp; Co. Ltd * as output!
> This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
> The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
> "inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.
> So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

Posted by "Claude Brisson (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-749?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claude Brisson resolved VELOCITY-749.
-------------------------------------

    Resolution: Won't Fix

Sophisticated filtering behaviours can be proposed on the wiki, but shouldn't be included in the engine, as use cases are too complex and too different one from another

> ReferenceInsertionEventHandler called "to often"/need more configuration settings
> ---------------------------------------------------------------------------------
>
>                 Key: VELOCITY-749
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6.2
>            Reporter: Marco Rothe
>            Priority: Minor
>             Fix For: 1.6.x, 1.7
>
>
> I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
> But I works not as expected in some situations:
> Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 
> Me &amp; Co. Ltd 
> correctly after the EscapeXmlReference.
> But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 
> * Me &amp;amp; Co. Ltd *  
> and not  * Me &amp; Co. Ltd * as output!
> This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
> The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
> "inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.
> So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-749) ReferenceInsertionEventHandler called "to often"/need more configuration settings

Posted by "Claude Brisson (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791897#action_12791897 ] 

Claude Brisson commented on VELOCITY-749:
-----------------------------------------

It's too complex to try to configure it, because the frontier between an internal and a real output insertion is very difficult.

If you want to control precisely when escaping occurs and when it doesn't, you better inherit EscapeXmlReference in a class of yours.

A quite handy way of handling this, that I often use, is giving prefixes to reference names. For instance, you can have a filter that only escapes references whose name begins by 'xml'.

public class MyXmlEscape extends EscapeXmlReference
{
    public Object referenceInsert( String reference, Object value  ) {
        if (value == null)
        {
            return null;
        }
        if (!value instanceof String || !reference.startsWith("xml"))
        {
            // do not escape
            return value;
        }
        else
        {
            // escape
            return super.referenceInsert(reference, value);
        }
    }
}

That way, you can write :

#set( $test = 'Me & Co. Ltd' )
#set( $xmltest = " * $test * ")
$xmltest

and this will exhibit the expected behaviour.


> ReferenceInsertionEventHandler called "to often"/need more configuration settings
> ---------------------------------------------------------------------------------
>
>                 Key: VELOCITY-749
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-749
>             Project: Velocity
>          Issue Type: Bug
>    Affects Versions: 1.6.2
>            Reporter: Marco Rothe
>            Priority: Minor
>             Fix For: 1.6.x, 1.7
>
>
> I use the EscapeXmlReference (ReferenceInsertionEventHandler implementation) in our projects to produce valid XHTML.
> But I works not as expected in some situations:
> Given the reference $test as 'Me & Co. Ltd' (for example from context) will output as 
> Me &amp; Co. Ltd 
> correctly after the EscapeXmlReference.
> But if we enrich the $test reference with some other string before output (#set($test = "* $test *")) we got 
> * Me &amp;amp; Co. Ltd *  
> and not  * Me &amp; Co. Ltd * as output!
> This is because the EscapeReference handler was called two times. First on the (internal) set directive (Me & Co. Ltd -> Me &amp; Co. Ltd), second on the real output of $test to the stream (* Me &amp; Co. Ltd *->  * Me &amp;amp; Co. Ltd *). 
> The javadoc of ReferenceInsertionEventHandler says "Reference 'Stream insertion' event handler.  Called with object  that will be inserted into stream via value.toString()." 
> "inserted  into stream" means to me  into the real output stream of the template merge, not into internal substreams. So I believe it's a bug or a least an unexpected behaviour because it produce unpredictable results on string operations.
> So the ReferenceInsertionEventHandler needs the possibility to know if the current insertation is an internal or an real output insertation to be able to react on situations as descripted above.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org