From: <fg...@us...> - 2011-04-27 12:57:27
|
Revision: 3436 http://openutils.svn.sourceforge.net/openutils/?rev=3436&view=rev Author: fgiust Date: 2011-04-27 12:57:20 +0000 (Wed, 27 Apr 2011) Log Message: ----------- ELFUNCTIONS-9 new function for javascript escaping Modified Paths: -------------- trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld Modified: trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java =================================================================== --- trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java 2011-04-27 12:50:45 UTC (rev 3435) +++ trunk/openutils-elfunctions/src/main/java/net/sourceforge/openutils/elfunctions/ElStringUtils.java 2011-04-27 12:57:20 UTC (rev 3436) @@ -67,11 +67,23 @@ /** * Escapes a javascript string. If "true" is passed as parameter, the string is between ", if false is between ' * @param text the string to be escaped - * @param dbl deprecated - no effect + * @param dbl If "true" the escaped string is returned between ", if false is returned between ' * @return the escaped string between either ' or " */ public static String escapeJsText(String text, boolean dbl) { + String repl = dbl ? "\"" : "'"; + String with = "\\" + repl; + return repl + (text != null ? StringUtils.replace(text, repl, with) : "") + repl; + } + + /** + * Escapes a javascript string. + * @param text the string to be escaped + * @return the escaped string + */ + public static String escapeJavascript(String text) + { return StringEscapeUtils.escapeJavaScript(text); } Modified: trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld =================================================================== --- trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld 2011-04-27 12:50:45 UTC (rev 3435) +++ trunk/openutils-elfunctions/src/main/resources/META-INF/stringutils.tld 2011-04-27 12:57:20 UTC (rev 3436) @@ -89,6 +89,17 @@ ]]> </example> </function> + <function> + <description>Escapes a javascript string.</description> + <name>escapeJavascript</name> + <function-class>net.sourceforge.openutils.elfunctions.ElStringUtils</function-class> + <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature> + <example> + <![CDATA[ + escapeJavascript("xyz\\2'3",true) : xyz\\2\'3 + ]]> + </example> + </function> <function> <description>Crops a String to a given length, adding a suffix (for example "...") if needed. The function takes 3 parameters: <![CDATA[<br/><strong>java.lang.String:</strong> the string to be adapted<br/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |