nl.gx.webmanager.taglib
Class FunctionLibrary

java.lang.Object
  extended by nl.gx.webmanager.taglib.FunctionLibrary

public class FunctionLibrary
extends java.lang.Object

Implements the wmfn taglibrary functions. The functions may be used in the expressionlanguage used in jsp pages.
Usage: ${wmfn:function(arg0, ...)}

Example of usage:

 < script type="text/javascript" >
 alert('page title is ${wmfn:escapeToJavascript(pageVersion.title)}');
 < /script >
 


Field Summary
static java.lang.String literalEndTag
           
static java.lang.String literalStartTag
           
 
Method Summary
static java.lang.String addLineFeed()
          Get a line feed (usually line feeds in JSP pages are ignored).
static boolean contains(java.lang.Object instance, java.lang.Object[] array)
          Return true if the array contains the instance.
static java.lang.String convertToJavaScript(java.lang.String value)
          Convert html code to javascript document.write statements.
static java.lang.String convertToNmtoken(java.lang.String source)
          Converts a given source String to a valid nmtoken.
static java.lang.String escapeToJavaScript(java.lang.String value)
          Replace \\ by \\\\ and ' by \\' in a string so that it can be used in a javascript.
static java.lang.String escapeToText(java.lang.String value)
          Surround the text part by a <pre> tag so that we know while processing that this part should be taken literally and so that line feeds should be preserved.
static java.lang.String formatExternalUrl(java.lang.String value)
          Returns the value prepended with "http://", unless it starts with "mailto:", "javascript:", "/", "#" or if it matches against the "[A-Za-z]*://.*" pattern using a regular expression.
static java.lang.String formSignatureParameterName(javax.servlet.ServletContext context)
          Get the name of the secure form request parameter If secure forms are turned on, then this function will return the name of the form parameter which should be used for sending the form signature.
static int indexOf(java.lang.Object instance, java.lang.Object[] array)
          Returns the index of the object in the array or -1 if the array doesn't contain the object.
static boolean instanceOf(java.lang.Object instance, java.lang.String className)
          More flexible instanceOf implementation than te built-in Java instanceof operator.
static java.util.Map<java.lang.Object,java.lang.Object> putAll(java.util.Map<java.lang.Object,java.lang.Object> initialMap, java.util.Map<java.lang.Object,java.lang.Object> additionalMap)
          Copies all of the mappings from the additional map to the initial map.
static java.util.Map<java.lang.String,java.lang.Object> putAllIgnoreCase(java.util.Map<java.lang.String,java.lang.Object> initialMap, java.util.Map<java.lang.String,java.lang.Object> additionalMap)
          Copies all of the mappings from the additional map to the initial map.
static java.lang.String replaceNewLines(java.lang.String value)
          Replace new lines by <br />.
static java.lang.String signForm(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, java.lang.String html)
          Add a secure form signature to a fragment of HTML
static java.lang.String signFormParameters(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, java.lang.String[] names)
          Computes a signature for a set of names for the use of secureforms in SiteWorks.
static java.lang.String signFragment(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, java.lang.String source)
          Generate a secure forms signature for the given HTML fragment
static java.util.SortedMap[] sortMaps(java.util.SortedMap[] rows, java.lang.String key, boolean ascending)
          Sorts an array of SortedMaps by the elements at a specified key.
static java.lang.Object[][] sortRows(java.lang.Object[][] rows, int column, boolean ascending)
          Sorts a two dimensional array (an array of arrays) by the objects in a column.
static java.lang.Object[] subArray(java.lang.Object[] rows, int from, int to)
          Returns a sub array of the original array.
static java.lang.String urlEncode(java.lang.String s)
          Url encode an utf-8 string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

literalStartTag

public static final java.lang.String literalStartTag
See Also:
Constant Field Values

literalEndTag

public static final java.lang.String literalEndTag
See Also:
Constant Field Values
Method Detail

subArray

public static java.lang.Object[] subArray(java.lang.Object[] rows,
                                          int from,
                                          int to)
Returns a sub array of the original array.

Parameters:
rows - The original array.
from - The index of the first element in the resulting array.
to - The index of the last element in the resulting array.
Returns:
The subarray containing the elements from the original array from index from to index to.

sortRows

public static java.lang.Object[][] sortRows(java.lang.Object[][] rows,
                                            int column,
                                            boolean ascending)
Sorts a two dimensional array (an array of arrays) by the objects in a column.

Parameters:
rows - The array that should be sorted.
column - The column index for comparing rows.
ascending - Indicates whether the sort order is ascending or descending.
Returns:
The sorted array.

urlEncode

public static java.lang.String urlEncode(java.lang.String s)
Url encode an utf-8 string.

Parameters:
s - the original string.
Returns:
the urlencoded string.

sortMaps

public static java.util.SortedMap[] sortMaps(java.util.SortedMap[] rows,
                                             java.lang.String key,
                                             boolean ascending)
Sorts an array of SortedMaps by the elements at a specified key.

Parameters:
rows - The array that should be sorted.
key - The key for the elements that should be used for comparing rows.
ascending - Indicates whether the sort order is ascending or descending.
Returns:
The array containing the elements of the original array in which the elements have been sorted by the values for the specified key.

contains

public static boolean contains(java.lang.Object instance,
                               java.lang.Object[] array)
Return true if the array contains the instance.

Parameters:
instance - an object
array - an array of objects
Returns:
true if the instance is in the array.

indexOf

public static int indexOf(java.lang.Object instance,
                          java.lang.Object[] array)
Returns the index of the object in the array or -1 if the array doesn't contain the object.

Parameters:
instance - an object
array - an array of objects
Returns:
the index of the object in the array or -1 if the array doesn't contain the object.

instanceOf

public static boolean instanceOf(java.lang.Object instance,
                                 java.lang.String className)
More flexible instanceOf implementation than te built-in Java instanceof operator.

Parameters:
instance -
className -
Returns:
true if instance is of type className,

escapeToJavaScript

public static java.lang.String escapeToJavaScript(java.lang.String value)
Replace \\ by \\\\ and ' by \\' in a string so that it can be used in a javascript.

Parameters:
value -
Returns:
escaped text.

replaceNewLines

public static java.lang.String replaceNewLines(java.lang.String value)
Replace new lines by <br />.

Parameters:
value -
Returns:
value with all newlines replaced by br tags

escapeToText

public static java.lang.String escapeToText(java.lang.String value)
Surround the text part by a <pre> tag so that we know while processing that this part should be taken literally and so that line feeds should be preserved.

Parameters:
value - The string to be escaped
Returns:
Escaped text string

addLineFeed

public static java.lang.String addLineFeed()
Get a line feed (usually line feeds in JSP pages are ignored).

Returns:
<pre>\r\n</pre>

convertToJavaScript

public static java.lang.String convertToJavaScript(java.lang.String value)
Convert html code to javascript document.write statements.

Parameters:
value - Usually some HTML fragment that needs to be written in the document
Returns:
javascript string that will write the provided string

convertToNmtoken

public static final java.lang.String convertToNmtoken(java.lang.String source)
Converts a given source String to a valid nmtoken. Every invalid character is replaced by an underscore (_).

Parameters:
source - the source String
Returns:
a valid nmtoken

formatExternalUrl

public static java.lang.String formatExternalUrl(java.lang.String value)
Returns the value prepended with "http://", unless it starts with "mailto:", "javascript:", "/", "#" or if it matches against the "[A-Za-z]*://.*" pattern using a regular expression.

Parameters:
value - The external url which may or may not start with a protocol.
Returns:
The value prepended with "http://", unless it starts with "mailto:", "javascript:", "/", "#" or if it matches against the "[A-Za-z]*://.*" pattern using a regular expression.

signFragment

public static java.lang.String signFragment(javax.servlet.ServletContext context,
                                            javax.servlet.http.HttpServletRequest request,
                                            java.lang.String source)
Generate a secure forms signature for the given HTML fragment

Parameters:
context - Current ServletContext object.
request - Current HttpServletRequest object.
source - HTML fragment containing HTML INPUT tags.
Returns:
the HTML with the signature hidden field attached

signFormParameters

public static java.lang.String signFormParameters(javax.servlet.ServletContext context,
                                                  javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String[] names)
Computes a signature for a set of names for the use of secureforms in SiteWorks. If secureforms is switched on, then the form will be signed automatically by siteworks. If the form is written by for example JavaScript then this function can be used for signing the form.

Parameters:
context - Current ServletContext object.
request - Current HttpServletRequest object.
names - The names of the inputs
Returns:
The signature for the input names, or "" if an exception occurred.

formSignatureParameterName

public static java.lang.String formSignatureParameterName(javax.servlet.ServletContext context)
Get the name of the secure form request parameter If secure forms are turned on, then this function will return the name of the form parameter which should be used for sending the form signature. This is normally not needed most of the time. The main use case is when performing Ajax style requests to WM.

Parameters:
context - Current ServletContext object.
Returns:
parameter name

signForm

public static java.lang.String signForm(javax.servlet.ServletContext context,
                                        javax.servlet.http.HttpServletRequest request,
                                        java.lang.String html)
                                 throws SignException
Add a secure form signature to a fragment of HTML

Parameters:
context - The current ServletContext object. From JSP this will typicall be "pageContext.servletContext".
request - The current HttpServletRequest object .From JSP this will typically be "pageContext.request".
html - The fragment of HTML to sign. This code should contain
Returns:
The HTML fragment with the signature INPUT tag added.
Throws:
SignException

putAll

public static java.util.Map<java.lang.Object,java.lang.Object> putAll(java.util.Map<java.lang.Object,java.lang.Object> initialMap,
                                                                      java.util.Map<java.lang.Object,java.lang.Object> additionalMap)
Copies all of the mappings from the additional map to the initial map. If a key exists in both maps the value of that key in the initial map is overwritten.

Parameters:
initialMap - Initial map.
additionalMap - Mappings to be stored in the initial map.
Returns:
Reference to the initial map.
See Also:
Map#putAll(Map)}.

putAllIgnoreCase

public static java.util.Map<java.lang.String,java.lang.Object> putAllIgnoreCase(java.util.Map<java.lang.String,java.lang.Object> initialMap,
                                                                                java.util.Map<java.lang.String,java.lang.Object> additionalMap)
Copies all of the mappings from the additional map to the initial map. The key of both maps is a string. If a key exists in both maps the value of that key in the initial map is overwritten. A key exists in both maps if keyOne.equalsIgnoreCase(keyTwo) is true.

Parameters:
initialMap - Initial map.
additionalMap - Mappings to be stored in the initial map.
Returns:
Reference to the initial map.


Copyright © 2007-2011 GX Software BV. All Rights Reserved.