Hi Pascal,
The problem is that you are searching for unescaped content inside escaped
content. In other words, $escapetool.xml called at the beginning escapes
your "{" characters to "{". Then you basically call
$stringtool.contains("{", "{") which will clearly be false.
It`s not a problem of $stringtool.contains, but on your code. Of course
that (in your second mail) $stringtool.contains("{",
$escapetool.xml("{")) returns true because it is the same thing as calling
$stringtool.contains($escapetool.xml("{"), $escapetool.xml("{"))
If you plan to do string matching on content, try to leave the escaping of
the content towards the end, when you actually have to display it and
really need to escape it. Until then, work with it unprocessed, as in
#set($MyContent=$recentDoc.content)
You would have easily noticed the problem yourself if you would have tried
printing the value of $MyContent for debugging purposes and to see what it
is actually that you are trying to match. It is a good practice in general
to double check your coding by printing intermediary values of your code.
Happy coding!
-Eduard
On Wed, Oct 8, 2014 at 5:46 PM, Pascal BASTIEN <[email protected]>
wrote:
> ... escapetool.xml is my new friend :-/
> $stringtool.contains($MyContent,$escapetool.xml('{{box
> cssClass="floatinginfobox" title="**Sommaire**"}}'))
>
>
>
> ________________________________
> De : Pascal BASTIEN <[email protected]>
> À : XWiki Users <[email protected]>
> Envoyé le : Mercredi 8 octobre 2014 16h01
> Objet : [xwiki-users] Escape character with $stringtool.contains
>
>
> Hello,
>
> On Xwiki 6.2.1, I'm fighting with $stringtool.contains
>
>
> http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringUtils.html#contains%28java.lang.CharSequence,%20java.lang.CharSequence%29
>
> In my velocity code, I have
>
> #set($MyContent=$escapetool.xml($recentDoc.content))
>
> $MyContent return
>
> {{box cssClass="floatinginfobox" title="**Sommaire**"}} {{toc
> numbered="true" depth="3"/}} {{/box}} {{numberedheadings/}} Bla bla
>
> I want to check if $MyContent contain this litteral string:
>
> {{box cssClass="floatinginfobox" title="**Sommaire**"}}
>
> I noticed than I can't escaping some characters ({ and ") with
> $stringtool.contains
>
> By example $stringtool.contains($MyContent,'box cssClass') working well
> but not $stringtool.contains($MyContent,'{box cssClass')
>
> I tried to escape characters with \ and/or ~ without success :-(
>
> Have you got an idea?
>
>
>
> thanks
>
> Pascal B
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users