nu.staldal.lsp
Class SimpleExtLib

java.lang.Object
  extended by nu.staldal.lsp.SimpleExtLib
All Implemented Interfaces:
LSPExtLib, org.xml.sax.ContentHandler
Direct Known Subclasses:
ServletExtLib

public abstract class SimpleExtLib
extends java.lang.Object
implements LSPExtLib, org.xml.sax.ContentHandler

Convenience class for implementing LSP extension libraries with only empty elements.

You only need to implement the handleElement method and methods for any extension functions.

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 handleElement method. It may not do both.


Field Summary
protected  java.lang.Object extContext
          External context, or null if not currently executing a page.
protected  java.lang.String myNamespaceURI
          Namespace URI for this extension library.
protected  java.lang.String pageName
          Current page name, or null if not currently executing a page.
 
Constructor Summary
SimpleExtLib()
           
 
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 characters(char[] chars, int start, int length)
           
 void endDocument()
           
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qname)
           
 void endPage()
          Indicate the end of an LSP page.
 void endPrefixMapping(java.lang.String prefix)
           
abstract  java.lang.String handleElement(java.lang.String localName, org.xml.sax.Attributes atts, org.xml.sax.ContentHandler out)
          Handle an extension element.
 void ignorableWhitespace(char[] chars, int start, int length)
           
 void init(java.lang.String namespaceURI)
          Initialize this Extension Library.
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void skippedEntity(java.lang.String name)
           
 void startDocument()
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts)
           
 void startPage(java.lang.Object extContext, java.lang.String pageName)
          Indicate the start of an LSP page.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myNamespaceURI

protected java.lang.String myNamespaceURI
Namespace URI for this extension library.


extContext

protected java.lang.Object extContext
External context, or null if not currently executing a page.


pageName

protected java.lang.String pageName
Current page name, or null if not currently executing a page.

Constructor Detail

SimpleExtLib

public SimpleExtLib()
Method Detail

init

public void init(java.lang.String namespaceURI)
          throws LSPException
Description copied from interface: LSPExtLib
Initialize this Extension Library.

Specified by:
init in interface LSPExtLib
Parameters:
namespaceURI - the namespace URI to serve
Throws:
LSPException

startPage

public void startPage(java.lang.Object extContext,
                      java.lang.String pageName)
               throws LSPException
Description copied from interface: LSPExtLib
Indicate the start of an LSP page.

Specified by:
startPage in interface LSPExtLib
Parameters:
extContext - external context passed to LSP execution engine
pageName - name of the LSP page
Throws:
LSPException

beforeElement

public org.xml.sax.ContentHandler beforeElement(org.xml.sax.ContentHandler out)
                                         throws org.xml.sax.SAXException
Description copied from interface: LSPExtLib
Invoked before the element is sent.

Specified by:
beforeElement in interface LSPExtLib
Parameters:
out - where to write XML output.
Returns:
a ContentHandler to send input to.
Throws:
org.xml.sax.SAXException - may throw SAXException

afterElement

public java.lang.String afterElement()
                              throws org.xml.sax.SAXException
Description copied from interface: LSPExtLib
Invoked after the element is sent.

Specified by:
afterElement in interface LSPExtLib
Returns:
a string output.
Throws:
org.xml.sax.SAXException - may throw SAXException

endPage

public void endPage()
Description copied from interface: LSPExtLib
Indicate the end of an LSP page.

Specified by:
endPage in interface LSPExtLib

handleElement

public abstract java.lang.String handleElement(java.lang.String localName,
                                               org.xml.sax.Attributes atts,
                                               org.xml.sax.ContentHandler out)
                                        throws org.xml.sax.SAXException
Handle an extension element.

Parameters:
localName - the local name of the element
atts - the attributes of the element
out - where to write XML output
Returns:
the String to replace the extension element with, or null if out was used
Throws:
org.xml.sax.SAXException - may throw SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qname,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qname)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] chars,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] chars,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException