It looks like JEXL syntax $tools.esc.url() is not working for version 1.4 of org.apache.velocity.tools.generic.EscapeTool.
I was thinking of using String.replaceAll() to escape offending strings one by one, but it may miss something that has not been identified.
Does anyone have any other ideas to escape URL in the JEXL bindings?
A lot of on-line references point to java.net.URLEncoder class, and it does have a nice “encode” method, but how to use this kind of class inside of Rhythmyx bindings to work with JEXL expression?
Which version of CM System are you using? This function and the updated velocity tools is available in the current 6.7. I think it was the base 6.7 did not have the updated tools in the Workbench deployment without a patch which caused the syntax checker to fail even though this would work when previewing or publishing. If using an older version of percussion I have dealt with this by using a replaceAll as you suggest, or create your own jexl function to do this for you.
I tried the code excitedly since it was something I was looking for, but I got the following error:
Unexpected exception while assembling one or more items: Problem when evaluating expression “$sys.getClass().forName(‘java.net.URLEncoder’).getDeclaredMethod(‘encode’).invoke($null,$row.title,‘UTF8’);” for variable “$row.contenturl”: Could not find method getDeclaredMethod for object [class java.net.URLEncoder] and arguments [encode]
So you know why this didn’t work?
Any documentation for $sys.getClass().forName(‘java.net.URLEncoder’).getDeclaredMethod(‘encode’).invoke($null,$youVariable,‘UTF8’)? I couldn’t find any document for $sys.getClass().forName().
Not only had I left out the classes for the arguments to “encode”, I was having you use reflection when you didn’t need to. Java apparently supports calling static methods directly on the Class object… who knew, right?
Same error as before:
Unexpected exception while assembling one or more items: Problem when evaluating expression “$sys.getClass().forName(‘java.net.URLEncoder’).getDeclaredMethod(‘encode’, $sys.getClass().forName(‘java.lang.String’), $sys.getClass().forName(‘java.lang.String’)).invoke($null,$row.title.String,‘UTF8’);” for variable “$row.contenturl”: Could not find method getDeclaredMethod for object [class java.net.URLEncoder] and arguments [encode,class java.lang.String,class java.lang.String]
It seems the parameters in getDeclaredMethod are having some problems. The 3rd parameter is supposed to be some kind of parameter array, based on the java doc.
Any idea? Thanks.
This works, but it doesn’t do the url encoding as expected, somehow it encodes space to +, but and encodes “®” as %C2%AE with an extra %C2 in the front.
For example:
“Another Press Release for /Testing Simulink®” is the original string.
The binding will encode it into:
“Another+Press+Release+for+%2FTesting+Simulink%C2%AE”.