uk.me.nxg.enormity
Class SigningXMLReader

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by uk.me.nxg.enormity.SigningXMLReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, XMLFilter, XMLReader

public class SigningXMLReader
extends org.xml.sax.helpers.XMLFilterImpl

An XML reader which can sign and verify XML in passing. This is an implementation of the SAX XMLReader interface, and may be used as such.

Normally, you obtain a SAX reader using a SAXParserFactory; if you instead obtain a reader using the getXMLReader(File,String,String) method, then it can be used in the same way as any other parser, except that:

In each case, further information can be retrieved about the parse using the information object returned by getGPGInformation(org.xml.sax.XMLReader).


Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(String uri, String localName, String qName)
           
 void endPrefixMapping(String prefix)
           
static GPGInformation getGPGInformation(XMLReader r)
          Retrieves extra information about the work done by the SigningXMLReader which is passed as argument.
static XMLReader getXMLReader(File gpgHome)
          Obtains a new XMLreader which can verify input XML.
static XMLReader getXMLReader(File gpgHome, String identity, String passphrase)
          Obtains a new XMLReader which can either sign or verify input XML.
static XMLFilter getXMLReader(File gpgHome, String identity, String passphrase, XMLReader xmlReader)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void parse(InputSource is)
           
 void processingInstruction(String target, String data)
           
 void setDocumentLocator(Locator locator)
           
 void skippedEntity(String name)
           
 void startDocument()
           
 void startElement(String uri, String localName, String qName, Attributes atts)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getGPGInformation

public static GPGInformation getGPGInformation(XMLReader r)
Retrieves extra information about the work done by the SigningXMLReader which is passed as argument. If no GPG work has been done so far by the reader, or if the reader is not a SigningXMLReader, then returns null.

Parameters:
r - an XMLReader, typically a SigningXMLReader
Returns:
status information about the GPG work

getXMLReader

public static XMLReader getXMLReader(File gpgHome)
                              throws SAXException
Obtains a new XMLreader which can verify input XML. Equivalent to getXMLReader(gpgHome, null, null)

Throws:
SAXException

getXMLReader

public static XMLReader getXMLReader(File gpgHome,
                                     String identity,
                                     String passphrase)
                              throws SAXException
Obtains a new XMLReader which can either sign or verify input XML. If either the identity or the passphrase is null, then the reader can only verify signatures, and if no signature is present then it will not attempt to add one

Parameters:
gpgHome - the location of the GPG keys to be used
identity - the GPG identity to use to sign keys, or null
passphrase - the passphrase for the key associated with the identity, or null
Throws:
SAXException

getXMLReader

public static XMLFilter getXMLReader(File gpgHome,
                                     String identity,
                                     String passphrase,
                                     XMLReader xmlReader)
                              throws SAXException
Throws:
SAXException

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.XMLFilterImpl
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.XMLFilterImpl
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.XMLFilterImpl
Throws:
SAXException

setDocumentLocator

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

skippedEntity

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

startDocument

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

endDocument

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

startElement

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

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.XMLFilterImpl
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.XMLFilterImpl
Throws:
SAXException

endPrefixMapping

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

parse

public void parse(InputSource is)
           throws SAXException,
                  IOException
Specified by:
parse in interface XMLReader
Overrides:
parse in class org.xml.sax.helpers.XMLFilterImpl
Throws:
SAXException
IOException


Copyright © 2012. All Rights Reserved.