LSP Servlet extension library

LSP comes with an extension library with functions for use in a Servlet environment, the namespace URI for this extension library is http://staldal.nu/LSP/ExtLib/Servlet. In this document, it's assumed that this namespace is mapped to the prefix s, however any prefix may be used.

Elements

s:include

<s:include
  name = serviceName
  optionally more attributes />

The s:include element is used to include the output of another service in the current page. Can only be used with the LSP framework.

Any attributes other than name will be make available to the included service as a request attribute with the prefix INCLUDE_ATTR_PREFIX.

s:lang

<s:lang
  key = key />

The s:lang element is used for internationalization of LSP pages. The element is replaced with a localized string for the given key in the user's locale. If no suitable localized string is found, the element is replaced with [key].

Functions

string s:lang(string)

Works like the s:lang element, but can be used in attribute values.

string s:encodeURL(string)

Encodes an URL for session tracking, using the javax.servlet.http.HttpServletResponse.encodeURL(String) method.

boolean s:isUserInRole(string)

Check if the user is in a given role, using the javax.servlet.http.HttpServletRequest.isUserInRole(String) method.

string s:formatDate(date)

Format a date as a string using the user's locale. Return the empty string if the date is null.

string s:formatTime(date)

Format a time as a string using the user's locale. Return the empty string if the date is null.

string s:formatDateTime(date)

Format a date/time as a string using the user's locale. Return the empty string if the date is null.

string s:formatXMLDateTime(date)

Format a date/time as XML Schema dateTime datatype in UTC. Return the empty string if the date is null.

string s:formatCustomDateTime(string, date)

Format a date/time as a string using the user's locale with a custom formatting pattern. The pattern is specified as in java.text.SimpleDateFormat. Return the empty string if the date is null.

date arguments may be java.util.Date, number which is used as argument to java.util.Date constructor or string which is parsed as a long and used as argument to java.util.Date constructor.

XSLT

The extension functions can also be used from XSLT stylesheets.

The LSP runtime passes two parameters to XSLT stylesheets:
context The LSP context
pageName The name of the current LSP page

Use the static methods in the class nu.staldal.lsp.servlet.XSLTExt with context as the first parameter. Like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:s="java://nu.staldal.lsp.servlet.XSLTExt"                
                exclude-result-prefixes="s">
<xsl:param name="context"/>
<xsl:param name="pageName"/>
<xsl:template match="/">
<html>
  <head>
    <title>Extension library test</title>
  </head>

  <body>
    <h1>Using extensions from XSLT</h1>
    <p><a href="{s:encodeURL($context,'FUNC1')}">Link to FUNC1 with URLencoding</a></p>
   
    <p>foo: <xsl:value-of select="s:lang($context, 'foo')"/></p>
    <p>bar: <xsl:value-of select="s:lang($context, 'bar')"/></p>
    <p>foobar: <img alt="{s:lang($context,$pageName,'foobar')}" src="theimage.png"/></p>
   
  </body>
</html>
</xsl:template>

</xsl:stylesheet>