public class BlastLikeSAXParser
extends java.lang.Object
The SAX2 events produced are as if the input to the parser was an XML file validating against the biojava BlastLikeDataSetCollection DTD. There is no requirement for an intermediate conversion of native output to XML format. An application of the parsing framework, however, is to create XML format files from native output files.
The biojava Blast-like parsing framework is designed to uses minimal memory,so that in principle, extremely large native outputs can be parsed and XML ContentHandlers can listen only for small amounts of information.
The framework currently supports parsing of native output from the following bioinformatics programs. Please note that if you are using different versions of NCBI or WU Blast to those listed below, it is worth considering trying setting the parsing mode to Lazy, which means parsing will be attempted if the program is recognised, regardless of version.
Notes to SAX driver writers
The framework that this parser is built on is designed to be extensible with support for both different pieces of software (i.e. not just software that produces Blast-like output), and multiple versions of programs.
This class inherits from the org.biojava.bio.program.sax.AbstractNativeAppSAXParser abstract base class. The abstract base class is a good place to start looking if you want to write new native application SAX2 parsers. This and releated classes have only package-level visibility. Typically, application writers are expected to provide a facade class in this package (similar to the current class) to allow users access to functionality.
NB Support for InputSource is not complete due to the fact that URLs are not resolved and cannot, therefore, be used as an InputSource. System pathnames, ByteStreams and CharacterStreams, however, are all supported.
Copyright © 2000 Cambridge Antibody Technology.
Primary author -
BlastLikeToXMLConverter
Modifier and Type | Field and Description |
---|---|
protected int |
iState |
protected java.lang.String |
oFullNamespacePrefix |
protected org.xml.sax.ContentHandler |
oHandler |
protected java.lang.String |
oNamespacePrefix |
protected boolean |
tNamespacePrefixes |
protected boolean |
tNamespaces |
Constructor and Description |
---|
BlastLikeSAXParser()
Initialises SAXParser, and sets default namespace prefix
to "biojava".
|
Modifier and Type | Method and Description |
---|---|
void |
addPrefixMapping(java.lang.String poPrefix,
java.lang.String poURI)
Adds a namespace prefix to URI mapping as (key,value) pairs.
|
protected void |
changeState(int piState)
Centralise chaining of iState field to help
with debugging.
|
protected void |
characters(char[] ch,
int start,
int length)
Utility method to centralize the sending of a SAX characters
message a document handler.
|
protected void |
endElement(org.biojava.bio.program.sax.QName poQName)
Utility method to centralize the sending of a SAX endElement
message a document handler.
|
org.xml.sax.ContentHandler |
getContentHandler()
Return the content handler.
|
protected java.io.BufferedReader |
getContentStream(org.xml.sax.InputSource poSource)
Create a stream from an an InputSource, picking the
correct stream according to order of precedance.
|
org.xml.sax.DTDHandler |
getDTDHandler()
Do-nothing implementation of interface method
|
org.xml.sax.EntityResolver |
getEntityResolver()
Do-nothing implementation of interface method
|
org.xml.sax.ErrorHandler |
getErrorHandler()
Do-nothing implementation of interface method
|
boolean |
getFeature(java.lang.String poName)
Do-nothing implementation of interface method
|
java.lang.String |
getNamespacePrefix()
Describe
getNamespacePrefix method here. |
boolean |
getNamespacePrefixes()
Support SAX2 configuration of namespace support of parser.
|
boolean |
getNamespaces()
Support SAX2 configuration of namespace support of parser.
|
java.lang.Object |
getProperty(java.lang.String name)
Do-nothing implementation of interface method
|
java.lang.String |
getURIFromPrefix(java.lang.String poPrefix)
Gets the URI for a namespace prefix, given that prefix,
or null if the prefix is not recognised.
|
void |
parse(org.xml.sax.InputSource poSource)
parse initiates the parsing operation. |
void |
parse(java.lang.String poSystemId)
Full implementation of interface method.
|
java.lang.String |
prefix(java.lang.String poElementName)
Given an unprefixed element name, returns
a new element name with a namespace prefix
|
void |
setContentHandler(org.xml.sax.ContentHandler poHandler)
Allow an application to register a content event handler.
|
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
Do-nothing implementation of interface method
|
void |
setEntityResolver(org.xml.sax.EntityResolver resolver)
Do-nothing implementation of interface method
|
void |
setErrorHandler(org.xml.sax.ErrorHandler handler)
Do-nothing implementation of interface method
|
void |
setFeature(java.lang.String poName,
boolean value)
Handles support for ReasoningDomain and Namespace-prefixes
|
void |
setModeLazy()
Setting the mode to lazy means that, if the program is recognised,
e.g.
|
void |
setModeStrict()
This is the default, parsing will be attempted only if both
the program e.g.
|
void |
setNamespacePrefix(java.lang.String poPrefix) |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Do-nothing implementation of interface method
|
protected void |
startElement(org.biojava.bio.program.sax.QName poQName,
org.xml.sax.Attributes atts)
Utility method to centralize sending of a SAX
startElement message to document handler
|
protected org.xml.sax.ContentHandler oHandler
protected boolean tNamespaces
protected boolean tNamespacePrefixes
protected java.lang.String oNamespacePrefix
protected java.lang.String oFullNamespacePrefix
protected int iState
public BlastLikeSAXParser()
public void parse(org.xml.sax.InputSource poSource) throws java.io.IOException, org.xml.sax.SAXException
parse
initiates the parsing operation.parse
in interface org.xml.sax.XMLReader
poSource
- an InputSource
.java.io.IOException
- if an error occurs.org.xml.sax.SAXException
- if an error occurs.public void setModeStrict()
public void setModeLazy()
public void setContentHandler(org.xml.sax.ContentHandler poHandler)
Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
setContentHandler
in interface org.xml.sax.XMLReader
poHandler
- a ContentHandler
The XML content handlerjava.lang.NullPointerException
- If the handler argument is nullpublic org.xml.sax.ContentHandler getContentHandler()
getContentHandler
in interface org.xml.sax.XMLReader
ContentHandler
The current content handler,
or null if none has been registered.public void parse(java.lang.String poSystemId) throws java.io.IOException, org.xml.sax.SAXException
parse
in interface org.xml.sax.XMLReader
java.io.IOException
org.xml.sax.SAXException
public boolean getFeature(java.lang.String poName) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
getFeature
in interface org.xml.sax.XMLReader
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
public void setFeature(java.lang.String poName, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
setFeature
in interface org.xml.sax.XMLReader
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
getProperty
in interface org.xml.sax.XMLReader
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
setProperty
in interface org.xml.sax.XMLReader
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
public void setEntityResolver(org.xml.sax.EntityResolver resolver)
setEntityResolver
in interface org.xml.sax.XMLReader
public org.xml.sax.EntityResolver getEntityResolver()
getEntityResolver
in interface org.xml.sax.XMLReader
public void setDTDHandler(org.xml.sax.DTDHandler handler)
setDTDHandler
in interface org.xml.sax.XMLReader
public org.xml.sax.DTDHandler getDTDHandler()
getDTDHandler
in interface org.xml.sax.XMLReader
public void setErrorHandler(org.xml.sax.ErrorHandler handler)
setErrorHandler
in interface org.xml.sax.XMLReader
public org.xml.sax.ErrorHandler getErrorHandler()
getErrorHandler
in interface org.xml.sax.XMLReader
protected void startElement(org.biojava.bio.program.sax.QName poQName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
poQName
- a QName
valueatts
- an Attributes
valueorg.xml.sax.SAXException
- if an error occursprotected void endElement(org.biojava.bio.program.sax.QName poQName) throws org.xml.sax.SAXException
poQName
- -org.xml.sax.SAXException
- thrown ifthrown
- ifprotected void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
ch
- -start
- -length
- -org.xml.sax.SAXException
- thrown ifthrown
- ifpublic boolean getNamespaces()
public boolean getNamespacePrefixes()
public void addPrefixMapping(java.lang.String poPrefix, java.lang.String poURI)
poPrefix
- a String
representation of the
namespace prefixpoURI
- a String
representation of the URI
for the namespace prefix.public java.lang.String getURIFromPrefix(java.lang.String poPrefix)
poPrefix
- a String
The namespace prefix.public void setNamespacePrefix(java.lang.String poPrefix)
poPrefix
- a String
valuepublic java.lang.String getNamespacePrefix()
getNamespacePrefix
method here.String
valuepublic java.lang.String prefix(java.lang.String poElementName)
String
valueprotected java.io.BufferedReader getContentStream(org.xml.sax.InputSource poSource)
poSource
- an InputSource
valueBufferedReader
valueprotected void changeState(int piState)
piState
- an int
value