Commit f7010088 authored by Guus der Kinderen's avatar Guus der Kinderen

Adding custom JSTL functions.

parent 93f81848
package org.jivesoftware.admin;
import org.jivesoftware.util.ByteFormat;
import org.jivesoftware.util.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* Utility functions that are exposed through a taglib.
*
......@@ -28,4 +35,65 @@ public class JSTLFunctions
{
return string.split(regex);
}
/**
* A formatter for formatting byte sizes. For example, formatting 12345 byes results in
* "12.1 K" and 1234567 results in "1.18 MB".
*
* @see ByteFormat
*/
public static String byteFormat( long bytes )
{
return new ByteFormat().format( bytes );
}
/**
* Translates a string into {@code application/x-www-form-urlencoded} format using a specific encoding scheme. This
* method uses the UTF-8 encoding scheme to obtain the bytes for unsafe characters.
*
* @see URLEncoder
*/
public static String urlEncode( String string )
{
try
{
return URLEncoder.encode( string, "UTF-8" );
}
catch ( UnsupportedEncodingException e )
{
// Should never occur, as UTF-8 encoding is mantdatory to implement for any JRE.
throw new IllegalStateException( "Unable to URL-encode string: " + string, e );
}
}
/**
* Decodes a {@code application/x-www-form-urlencoded} string using the UTF-8 encoding scheme. The encoding is used
* to determine what characters are represented by any consecutive sequences of the form "<i>{@code %xy}</i>".
*
* @see URLDecoder
*/
public static String urlDecode( String string )
{
try
{
return URLDecoder.decode( string, "UTF-8" );
}
catch ( UnsupportedEncodingException e )
{
// Should never occur, as UTF-8 encoding is mantdatory to implement for any JRE.
throw new IllegalStateException( "Unable to URL-decode string: " + string, e );
}
}
/**
* This method takes a string which may contain HTML tags (ie, &lt7;b&gt;,
* &lt;table&gt;, etc) and converts the '&lt;' and '&gt;' characters to
* their HTML escape sequences. It will also replace LF with &lt;br&gt;.
*
* @see StringUtils#escapeHTMLTags(String);
*/
public static String escapeHTMLTags( String string )
{
return StringUtils.escapeHTMLTags( string );
}
}
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.2</tlib-version>
<tlib-version>1.3</tlib-version>
<short-name>Tag Library for Openfire</short-name>
<description>Tab Library for Openfire Admin Console</description>
<short-name>admin</short-name>
......@@ -151,6 +151,26 @@
<function-class>org.jivesoftware.admin.JSTLFunctions</function-class>
<function-signature>java.lang.String[] split(java.lang.String, java.lang.String)</function-signature>
</function>
<function>
<name>byteFormat</name>
<function-class>org.jivesoftware.admin.JSTLFunctions</function-class>
<function-signature>java.lang.String byteFormat(long)</function-signature>
</function>
<function>
<name>urlEncode</name>
<function-class>org.jivesoftware.admin.JSTLFunctions</function-class>
<function-signature>java.lang.String urlEncode(java.lang.String)</function-signature>
</function>
<function>
<name>urlDecode</name>
<function-class>org.jivesoftware.admin.JSTLFunctions</function-class>
<function-signature>java.lang.String urlDecode(java.lang.String)</function-signature>
</function>
<function>
<name>escapeHTMLTags</name>
<function-class>org.jivesoftware.admin.JSTLFunctions</function-class>
<function-signature>java.lang.String escapeHTMLTags(java.lang.String)</function-signature>
</function>
<function>
<name>serverIdentities</name>
<function-class>org.jivesoftware.util.CertificateManager</function-class>
......@@ -186,4 +206,20 @@
<function-class>org.jivesoftware.util.JiveGlobals</function-class>
<function-signature>java.util.List getListProperty(java.lang.String,java.util.List)</function-signature>
</function>
<function>
<name>formatDate</name>
<function-class>org.jivesoftware.util.JiveGlobals</function-class>
<function-signature>java.lang.String formatDate(java.util.Date)</function-signature>
</function>
<function>
<name>formatDateTime</name>
<function-class>org.jivesoftware.util.JiveGlobals</function-class>
<function-signature>java.lang.String formatDateTime(java.util.Date)</function-signature>
</function>
<function>
<name>formatTime</name>
<function-class>org.jivesoftware.util.JiveGlobals</function-class>
<function-signature>java.lang.String formatTime(java.util.Date)</function-signature>
</function>
</taglib>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment