On Tue, Mar 16, 2010 at 18:32, Vincent Massol <[email protected]> wrote:
>
> On Mar 16, 2010, at 6:28 PM, mflorea (SVN) wrote:
>
>> Author: mflorea
>> Date: 2010-03-16 18:28:54 +0100 (Tue, 16 Mar 2010)
>> New Revision: 27661
>>
>> Modified:
>>   
>> platform/web/trunk/xwiki-gwt-wysiwyg-server/src/main/java/com/xpn/xwiki/wysiwyg/server/plugin/WysiwygPluginApi.java
>> Log:
>> XWIKI-5013: HTML code visible when inserting velocity macro displaying a 
>> property
>>
>> Modified: 
>> platform/web/trunk/xwiki-gwt-wysiwyg-server/src/main/java/com/xpn/xwiki/wysiwyg/server/plugin/WysiwygPluginApi.java
>> ===================================================================
>> --- 
>> platform/web/trunk/xwiki-gwt-wysiwyg-server/src/main/java/com/xpn/xwiki/wysiwyg/server/plugin/WysiwygPluginApi.java
>>        2010-03-16 15:51:03 UTC (rev 27660)
>> +++ 
>> platform/web/trunk/xwiki-gwt-wysiwyg-server/src/main/java/com/xpn/xwiki/wysiwyg/server/plugin/WysiwygPluginApi.java
>>        2010-03-16 17:28:54 UTC (rev 27661)
>> @@ -35,6 +35,14 @@
>> public class WysiwygPluginApi extends Api
>> {
>>     /**
>> +     * The context property which indicates if the current code was called 
>> from a template (only Velocity execution) or
>> +     * from a wiki page (wiki syntax rendering).
>> +     *
>> +     * @see #parseAndRender(String, String)
>> +     */
>> +    private static final String IS_IN_RENDERING_ENGINE = 
>> "isInRenderingEngine";
>> +
>> +    /**
>>      * The plugin instance.
>>      */
>>     private WysiwygPlugin plugin;
>> @@ -98,11 +106,26 @@
>>      */
>>     public String parseAndRender(String html, String syntax)
>>     {
>> +        // Save the value of the "is in rendering engine" context property.
>> +        Object isInRenderingEngine = context.get(IS_IN_RENDERING_ENGINE);
>> +
>>         try {
>> +            // This tells display() methods that we are inside the 
>> rendering engine and thus that they can return wiki
>> +            // syntax and not HTML syntax (which is needed when outside the 
>> rendering engine, i.e. when we're inside
>> +            // templates using only Velocity for example).
>> +            context.put(IS_IN_RENDERING_ENGINE, true);
>> +
>>             return 
>> Utils.getComponent(HTMLConverter.class).parseAndRender(html, syntax);
>>         } catch (Exception e) {
>>             // Leave the previous HTML in case of an exception.
>>             return html;
>> +        } finally {
>> +            // Restore the value of the value of the "is in rendering 
>> engine" context property.
>> +            if (isInRenderingEngine != null) {
>> +                context.put(IS_IN_RENDERING_ENGINE, isInRenderingEngine);
>> +            } else {
>> +                context.remove(IS_IN_RENDERING_ENGINE);
>> +            }
>
> Shouldn't you always put back the value that you saved (even if it's null) ?

It's basically what he does with context.remove, XWikiContext does not
support null value because it's a Hashtable.

>
> Thanks
> -Vincent
>
> _______________________________________________
> devs mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs
>



-- 
Thomas Mortagne
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to