Here is my proposed implementation for automatic character escaping in reference values.
 
Only the XML format is taken into account for now, but the object model can easily be extended to handle other formats.
I recall that the only predicate is that reference values should not contain syntax boundaries (althougth they can in some cases), along with the fact that the document should of course be well-formed.
 
I guess the lack of feedback for the specs I posted a week ago was a kind of tepid approval, so I went ahead...
Now that the thing is coded, I'd appreciate some comments, despite the fact I know you've all plenty of late work to do, as I do... (at least, tell me you'll look at it one of those days ;-) or where this package has a chance to go : in the repository, in the whiteboard, or in the trashcan...).
 
### Description of this implementation :
 
A new boolean property, "runtime.format.character.escaping", controls the use of this character escaping mechanism.
 
A new string member of Template : "contentType", describing the MIME type of this template; has its getter and setter. For now, will remain null until explicitely set.
 
All new objects related to this character escaping are stored in the package org.apache.velocity.runtime.format
 
If template content type is known and there exists a corresponding specialized character escaper, a new "org.apache.velocity.runtime.format.CharEscaper" object member [with getter and setter] in InternalContextAdapter[Impl] is built by Template.merge( ).
 
If not null, this char escaper is called by ASTText.render( ) (to keep track of the current syntax) and by ASTReference.render( ) (to perform the actual character escaping).
 
### Three zip files attached :
 
 - all modified files
 - the patch
 - an example
 
### Output of the example :
 
<?xml version="1.0" encoding="UTF-8"?>
<document singlequote='-->&apos;<--' doublequote="-->&quot;<--">
        &lt;&amp;&gt;
        <![CDATA['<&>']]>
        &lt;&amp;&gt;
        <!--'<&>'-->
        &lt;&amp;&gt;
</document>
 
Fell free to make any comment or critic.
 
CloD
 

Attachment: modfiles.zip
Description: Macintosh archive

Attachment: charescape_patch.zip
Description: Macintosh archive

Attachment: charescape_example.zip
Description: Macintosh archive

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


Reply via email to