uk.me.nxg.xoxa
Class SigningXMLReader

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by uk.me.nxg.xoxa.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 of the first two cases, further information can be retrieved about the parse using the information object returned by getGPGInformation(org.xml.sax.XMLReader).


Field Summary
static String OPENPGP
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(String uri, String localName, String qName)
           
 void endPrefixMapping(String prefix)
           
 GPGInformation getGPGInformation()
          Retrieves extra information about the work done by the XMLReader.
static GPGInformation getGPGInformation(XMLReader r)
          Retrieves extra information about the work done by the SigningXMLReader which is passed as argument.
static XMLReader getXMLReader()
          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)
          Wraps an existing reader in a SigningXMLReader.
 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
 

Field Detail

OPENPGP

public static final String OPENPGP
See Also:
Constant Field Values
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, or null if the argument is not a SigningXMLReader

getGPGInformation

public GPGInformation getGPGInformation()
Retrieves extra information about the work done by the XMLReader. If no GPG work has been done so far by the reader, then returns null.

Returns:
status information about the GPG work

getXMLReader

public static XMLReader getXMLReader()
                              throws SAXException
Obtains a new XMLreader which can verify input XML. This uses GPG information in the default location, or that pointed to by GNUPGHOME. Equivalent to getXMLReader(null, null, null)

Returns:
a new XMLReader instance
Throws:
SAXException - on XML errors

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

The gpgHome parameter indicates the location of the GPG keys to be used -- it is equivalent to, and overrides, the environment variable GNUPGHOME. It may be null to use the default location.

Parameters:
gpgHome - the location of the GPG keys to be used, or null
identity - the GPG identity to use to sign keys, or null
passphrase - the passphrase for the key associated with the identity, or null
Returns:
a new XMLReader instance
Throws:
SAXException - if SAX does

getXMLReader

public static XMLFilter getXMLReader(File gpgHome,
                                     String identity,
                                     String passphrase,
                                     XMLReader xmlReader)
                              throws SAXException
Wraps an existing reader in a SigningXMLReader.

Parameters:
gpgHome - the location of the GPG keys to be used, or null
identity - the GPG identity to use to sign keys, or null
passphrase - the passphrase for the key associated with the identity, or null
xmlReader - a XMLReader instance
Returns:
a new XMLFilter
Throws:
SAXException - if SAX does

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 © 2015. All rights reserved.