com.sap.portal.httpconnectivity.transformationservice

Class EPSAXDefaultHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.sap.portal.httpconnectivity.transformationservice.EPSAXDefaultHandler
All Implemented Interfaces:
IPageContextHolder, ITransformerProperties, Cloneable, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler

public abstract class EPSAXDefaultHandler
extends org.xml.sax.helpers.DefaultHandler
implements LexicalHandler, ITransformerProperties, IPageContextHolder

An abstract base class for the SAX transformers used in the transformation service.
SAX handlers have access to the result handlers (ContentHandler and LexicalHandler) and to the page context. If the result is an instance of SAXResult, then the resultHandler is available. If the result is an instance of StreamResult, then the writer is available. The writer is a buffer that holds the result.
When implementing the doClone() method make sure that the handler remains thread safe.
The default implementation of DefaultHandler is a simple copy of the source to the result.
The following example shows a simple SAX handler that adds ID to XML nodes. Error handling is removed.


 
public class MyUIDAdderHandler extends EPSAXDefaultHandler
{
                // Map holding the input parameters that this handler exposes.    
    final private static Map mm_inputParameters = new HashMap(10);
    
    // The list of parameters of this transformer
    static
    {
                        // Parameter holding the number of the first ID.
        mm_inputParameters.put("StartUID","Integer");  
    }
 
        private int    m_iUIDCounter;
 
   public MyUIDAdderHandler()
   {
      super();
      m_iUIDCounter = 0;
    }
 
                // Clones the handler.      
    public EPSAXDefaultHandler doClone()
    {           
        return new MyUIDAdderHandler();
    }

    public void startElement(String namespaceURI, String localName, String qName, Attributes attrs)
        throws SAXException
    {
        AttributesImpl newAttrs = new AttributesImpl(attrs);        
        newAttrs.addAttribute("","","UID","integer",Integer.toString(m_iUIDCounter++));
        super.startElement(namespaceURI, localName, qName, newAttrs);
    }

    public void startDocument() throws SAXException
    {
        Integer i = (Integer) m_paremetersMap.get("StartUID");
        if(i!=null)
        {
            m_iUIDCounter = i.intValue(); 
        }
        super.startDocument();
    }

    public Map getInputProperties()
    {       
        return mm_inputParameters;
    }
}
 


Field Summary
protected  com.sapportals.htmlb.rendering.IPageContext m_pageContext
          The current HTMLB page context.
protected  Map m_paremetersMap
          The transformer input parameters.
 ContentHandler resultHandler
          The result content handler.
 LexicalHandler resultLexicalHanlder
          The result lexical handler.
 Writer writer
          The writer associated with the result.
 
Constructor Summary
EPSAXDefaultHandler()
          The class constructor.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void clearParameters()
          Clears the runtime parameters for the handler.
 void comment(char[] ch, int start, int length)
           
abstract  EPSAXDefaultHandler doClone()
          Clones the handler.
 void endCDATA()
           
 void endDocument()
           
 void endDTD()
           
 void endElement(String namespaceURI, String localName, String qName)
           
 void endEntity(String name)
           
 void endPrefixMapping(String prefix)
           
 void error(SAXParseException spe)
           
 void fatalError(SAXParseException spe)
           
protected  String getNormalizedString(char[] ch, int start, int length)
          Gets a string from the specified buffer.
 com.sapportals.htmlb.rendering.IPageContext getPageContext()
          Gets the HTMLB page context.
 Object getParemeter(String name)
          Gets the parameter value from the runtime parameters.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(String target, String data)
           
 InputSource resolveEntity(String arg0, String arg1)
           
 void setPageContext(com.sapportals.htmlb.rendering.IPageContext context)
          Places the HTMLB page context in the holder.
 void setParemeter(String name, Object value)
          Sets a runtime parameter.
 void setResult(Result result)
          Sets the result of the transformation.
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String systemId)
           
 void startElement(String namespaceURI, String localName, String qName, Attributes attrs)
           
 void startEntity(String name)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
notationDecl, setDocumentLocator, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sap.portal.httpconnectivity.transformationservice.ITransformerProperties
getInputProperties
 

Field Detail

resultHandler

public ContentHandler resultHandler
The result content handler. The result of the transformer should be written to this handler. This handler is null if it is the last transformer in a pipe.


resultLexicalHanlder

public LexicalHandler resultLexicalHanlder
The result lexical handler. See the JDK documentation for more details.


m_pageContext

protected com.sapportals.htmlb.rendering.IPageContext m_pageContext
The current HTMLB page context. The transformer sets the page context before activating transformation.


m_paremetersMap

protected Map m_paremetersMap
The transformer input parameters.


writer

public Writer writer
The writer associated with the result.

Constructor Detail

EPSAXDefaultHandler

public EPSAXDefaultHandler()
The class constructor.

Method Detail

getPageContext

public com.sapportals.htmlb.rendering.IPageContext getPageContext()
Description copied from interface: IPageContextHolder
Gets the HTMLB page context.

Specified by:
getPageContext in interface IPageContextHolder
Returns:
the page context

setPageContext

public void setPageContext(com.sapportals.htmlb.rendering.IPageContext context)
Description copied from interface: IPageContextHolder
Places the HTMLB page context in the holder.

Specified by:
setPageContext in interface IPageContextHolder
Parameters:
context - the current page context to hold

getParemeter

public Object getParemeter(String name)
Gets the parameter value from the runtime parameters.

Parameters:
name - the name of the parameter
Returns:
the value of the parameter

setParemeter

public void setParemeter(String name,
                         Object value)
Sets a runtime parameter. If the parameter already exists, it is overwritten.

Parameters:
name - the name of the parameter to set
value - the value of the parameter

setResult

public void setResult(Result result)
Sets the result of the transformation. Called by the transformation service before transformation is activated.

Parameters:
result - the result of the transformation

clearParameters

public void clearParameters()
Clears the runtime parameters for the handler. Called each time a transformer is taken from the list of registered transformers.


characters

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

endDocument

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

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

ignorableWhitespace

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

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

startDocument

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

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes attrs)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Specified by:
comment in interface LexicalHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

error

public void error(SAXParseException spe)
           throws SAXException
Specified by:
error in interface ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

fatalError

public void fatalError(SAXParseException spe)
                throws SAXException
Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

getNormalizedString

protected String getNormalizedString(char[] ch,
                                     int start,
                                     int length)
Gets a string from the specified buffer. If there is no alpha-numeric value in the buffer, returns an empty string.

Parameters:
ch - the buffer for the characters
start - the starting point in the buffer
length - the number of characters to take from the buffer
Returns:
a normalized string

doClone

public abstract EPSAXDefaultHandler doClone()
Clones the handler.

Returns:
a new instance of the handler

resolveEntity

public InputSource resolveEntity(String arg0,
                                 String arg1)
                          throws SAXException
Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] EP-ADMIN [sap.com] tc/ep/admin/api/extd api EP-PIN


Copyright 2011 SAP AG Complete Copyright Notice