nu.staldal.lsp
Interface LSPExtLib

All Known Implementing Classes:
ServletExtLib, SimpleExtLib

public interface LSPExtLib

LSP Extension Library.

After instance creation, the init method will be invoked with the namespace URI. This allows the same class to be used for several namespaces.

An LSPExtLib may be reused, but will not be executed concurrently by several threads.

For each LSP page to process, the startPage method will be invoked first. Then for each extension element on the LSP page:

  1. beforeElement() is invoked, which returns a ContentHandler "in"
  2. the extension element is sent to the ContentHandler "in" (startDocument() and endDocument() will not be invoked).
  3. afterElement() is invoked, which may return a String.
LSP will not use the "in" ContentHandler after invoking the afterElement() method.

The extlib can return data in one of two ways, write to the supplied ContentHandler "out" (it must not invoke startDocument() or endDocument()), or return a string from the afterElement() method. It may not do both.

For each call to an extension function, a method with the function name prefixed with '_' is invoked. All arguments to this method must be of type Object, and the return type must be Object, it may throw SAXException. Functions may be overloaded based on number of arguments.

After the LSP page is finished, the endPage method is invoked.

An easier, but not as flexible, way to implement an extension library is to extend the SimpleExtLib class.


Method Summary
 java.lang.String afterElement()
          Invoked after the element is sent.
 org.xml.sax.ContentHandler beforeElement(org.xml.sax.ContentHandler out)
          Invoked before the element is sent.
 void endPage()
          Indicate the end of an LSP page.
 void init(java.lang.String namespaceURI)
          Initialize this Extension Library.
 void startPage(java.lang.Object extContext, java.lang.String pageName)
          Indicate the start of an LSP page.
 

Method Detail

init

void init(java.lang.String namespaceURI)
          throws org.xml.sax.SAXException
Initialize this Extension Library.

Parameters:
namespaceURI - the namespace URI to serve
Throws:
org.xml.sax.SAXException - may throw SAXException

startPage

void startPage(java.lang.Object extContext,
               java.lang.String pageName)
               throws org.xml.sax.SAXException
Indicate the start of an LSP page.

Parameters:
extContext - external context passed to LSP execution engine
pageName - name of the LSP page
Throws:
org.xml.sax.SAXException - may throw SAXException

beforeElement

org.xml.sax.ContentHandler beforeElement(org.xml.sax.ContentHandler out)
                                         throws org.xml.sax.SAXException
Invoked before the element is sent.

Parameters:
out - where to write XML output.
Returns:
a ContentHandler to send input to.
Throws:
org.xml.sax.SAXException - may throw SAXException

afterElement

java.lang.String afterElement()
                              throws org.xml.sax.SAXException
Invoked after the element is sent.

Returns:
a string output.
Throws:
org.xml.sax.SAXException - may throw SAXException

endPage

void endPage()
             throws org.xml.sax.SAXException
Indicate the end of an LSP page.

Throws:
org.xml.sax.SAXException - may throw SAXException