com.hp.hpl.jena.rdf.arp
Class SAX2RDF

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.hp.hpl.jena.rdf.arp.SAX2RDFImpl
          extended by com.hp.hpl.jena.rdf.arp.SAX2RDF
All Implemented Interfaces:
ARPConfig, ARPErrorNumbers, RDFParserConstants, ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler
Direct Known Subclasses:
SAX2Model

public class SAX2RDF
extends SAX2RDFImpl
implements ARPConfig

Allows connecting an arbitrary source of SAX events with ARP.

For use with a DOM tree, see The Java Developer's Almanac for a discussion of how to transform a DOM into a source of SAX events.

The use pattern is to create and initialize one of these, then set it as the content, lexical and error handler for some source of SAX events (e.g. from a parser). It must be configured to use namespaces, and namespace prefixes. This initializing can be done for XMLReaders using installHandlers(org.xml.sax.XMLReader, com.hp.hpl.jena.rdf.arp.XMLHandler).

Triples and errors are reported on a different thread. Do not expect synchronous behaviour between the SAX events and the triples or errors being generated.

This class does not support multithreaded SAX sources, nor IO interruption.

There is further documentation: here and here.

Author:
Jeremy Carroll

Field Summary
 
Fields inherited from interface com.hp.hpl.jena.rdf.arp.RDFParserConstants
A_ABOUT, A_DATATYPE, A_ID, A_NODEID, A_OTHER, A_PARSETYPE, A_RDF_N, A_RESOURCE, A_TYPE, A_XMLBASE, A_XMLLANG, A_XMLNS, A_XMLSPACE, AV_COLLECTION, AV_DAMLCOLLECTION, AV_LITERAL, AV_RESOURCE, AV_STRING, CD_STRING, COMMENT, E_DESCRIPTION, E_END, E_LI, E_OTHER, E_RDF, E_RDF_N, EOF, PROCESSING_INSTRUCTION, tokenImage, X_SAX_EX, X_WARNING
 
Fields inherited from interface com.hp.hpl.jena.rdf.arp.ARPErrorNumbers
EM_ERROR, EM_FATAL, EM_IGNORE, EM_WARNING, ERR_ABOUTEACH_NOT_TOPLEVEL, ERR_BAD_RDF_ATTRIBUTE, ERR_BAD_RDF_ELEMENT, ERR_ENCODING_MISMATCH, ERR_GENERIC_IO, ERR_INTERNAL_ERROR, ERR_LI_AS_TYPE, ERR_NOT_WHITESPACE, ERR_RESOLVING_URI_AGAINST_NULL_BASE, ERR_SAX_ERROR, ERR_SAX_FATAL_ERROR, ERR_STRING_NOT_NORMAL_FORM_C, ERR_SYNTAX_ERROR, ERR_UNABLE_TO_RECOVER, ERR_URI_NOT_NORMAL_FORM_C, ERR_UTF_ENCODING, IGN_DAML_COLLECTION, IGN_NO_BASE_URI_SPECIFIED, IGN_PRIVATE_XMLLANG, IGN_XMLBASE_SIGNIFICANT, IGN_XMLBASE_USED, WARN_BAD_NAME, WARN_BAD_NAMESPACE_URI, WARN_BAD_RDF_NAMESPACE_URI, WARN_BAD_XML, WARN_BAD_XML_NAMESPACE_URI, WARN_BAD_XMLLANG, WARN_DEPRECATED_XMLLANG, WARN_ENCODING_MISMATCH, WARN_IN_STRICT_MODE, WARN_LEGAL_REUSE_OF_ID, WARN_MALFORMED_URI, WARN_MALFORMED_XMLLANG, WARN_MINOR_INTERNAL_ERROR, WARN_PROCESSING_INSTRUCTION_IN_RDF, WARN_QNAME_AS_ID, WARN_RDF_NN_AS_TYPE, WARN_REDEFINITION_OF_ID, WARN_RELATIVE_NAMESPACE_URI_DEPRECATED, WARN_RESOLVING_URI_AGAINST_EMPTY_BASE, WARN_SAX_WARNING, WARN_STRING_COMPOSING_CHAR, WARN_STRING_NOT_NORMAL_FORM_C, WARN_UNKNOWN_PARSETYPE, WARN_UNKNOWN_RDF_ATTRIBUTE, WARN_UNKNOWN_RDF_ELEMENT, WARN_UNKNOWN_XML_ATTRIBUTE, WARN_UNQUALIFIED_ATTRIBUTE, WARN_UNQUALIFIED_ELEMENT, WARN_UNQUALIFIED_RDF_ATTRIBUTE, WARN_URI_COMPOSING_CHAR, WARN_XMLBASE_MISSING
 
Method Summary
 ARPHandlers getHandlers()
          This is used when configuring a parser that is not loading into a Jena Model, but is processing the triples etc. in some other way.
 ARPOptions getOptions()
          The options used during parsing.
static void installHandlers(XMLReader rdr, com.hp.hpl.jena.rdf.arp.XMLHandler sax2rdf)
          Initializes an XMLReader to use the SAX2RDF object as its handler for all events, and to use namespaces and namespace prefixes.
static SAX2RDF newInstance(String base)
          Factory method to create a new SAX2RDF.
static SAX2RDF newInstance(String base, String lang)
          Factory method to create a new SAX2RDF.
 void setDocumentLocator(Locator locator)
           
 void setHandlersWith(ARPHandlers handlers)
          This is used when configuring a parser that is not loading into a Jena Model, but is processing the triples etc. in some other way.
 void setOptionsWith(ARPOptions opts)
          Copies the options from the argument to be used by this instance.
 void startPrefixMapping(String prefix, String uri)
          Begin the scope of a prefix-URI Namespace mapping.
 
Methods inherited from class com.hp.hpl.jena.rdf.arp.SAX2RDFImpl
characters, comment, endCDATA, endDocument, endDTD, endElement, endEntity, endPrefixMapping, error, fatalError, ignorableWhitespace, processingInstruction, skippedEntity, startCDATA, startDocument, startDTD, startElement, startEntity, warning
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
notationDecl, resolveEntity, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
setDocumentLocator
 

Method Detail

newInstance

public static SAX2RDF newInstance(String base)
                           throws MalformedURIException
Factory method to create a new SAX2RDF. Use getHandlers() or setHandlersWith(com.hp.hpl.jena.rdf.arp.ARPHandlers) to provide a StatementHandler, and usually an ErrorHandler

Parameters:
base - The retrieval URL, or the base URI to be used while parsing.
Returns:
A new SAX2RDF
Throws:
MalformedURIException

newInstance

public static SAX2RDF newInstance(String base,
                                  String lang)
                           throws MalformedURIException
Factory method to create a new SAX2RDF. This is particularly intended for when parsing a non-root element within an XML document. In which case the application needs to find this value in the outer context. Optionally, namespace prefixes can be passed from the outer context using startPrefixMapping(java.lang.String, java.lang.String).

Parameters:
base - The retrieval URL, or the base URI to be used while parsing. Use getHandlers() or setHandlersWith(com.hp.hpl.jena.rdf.arp.ARPHandlers) to provide a StatementHandler, and usually an ErrorHandler
lang - The current value of xml:lang when parsing starts, usually "".
Returns:
A new SAX2RDF
Throws:
MalformedURIException - If base is bad.

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
Begin the scope of a prefix-URI Namespace mapping.

This is passed to any NamespaceHandler associated with this parser. It can be called before the initial SAX2RDFImpl.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) event, or other events associated with the elements being processed. When building a Jena Model, it is not required to match this with corresponding SAX2RDFImpl.endPrefixMapping(java.lang.String) events. Other NamespaceHandlers may be fussier. When building a Jena Model, the prefix bindings are remembered with the Model, and may be used in some output routines. It is permitted to not call this method for prefixes declared in the outer context, in which case, any output routine will need to use a gensym for such namespaces.

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class SAX2RDFImpl
Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI the prefix is mapped to.

getHandlers

public ARPHandlers getHandlers()
This is used when configuring a parser that is not loading into a Jena Model, but is processing the triples etc. in some other way.

Specified by:
getHandlers in interface ARPConfig
Returns:
The handlers used during parsing.
See Also:
ARPConfig.getHandlers()

setHandlersWith

public void setHandlersWith(ARPHandlers handlers)
This is used when configuring a parser that is not loading into a Jena Model, but is processing the triples etc. in some other way.

Specified by:
setHandlersWith in interface ARPConfig
Parameters:
handlers - The new values to use.
See Also:
ARPConfig.setHandlersWith(com.hp.hpl.jena.rdf.arp.ARPHandlers)

getOptions

public ARPOptions getOptions()
Description copied from interface: ARPConfig
The options used during parsing. The options can be changed by calling this method and then using the set.. methods in ARPOptions. The options can be copied onto another ARP instance using the ARPConfig.setOptionsWith(com.hp.hpl.jena.rdf.arp.ARPOptions) method.

Specified by:
getOptions in interface ARPConfig
Returns:
The handlers used during parsing.
See Also:
ARPOptions.setDefaultErrorMode(), ARPOptions.setLaxErrorMode(), ARPOptions.setStrictErrorMode(), ARPOptions.setStrictErrorMode(int), ARPOptions.setEmbedding(boolean), ARPOptions.setErrorMode(int, int), ARPConfig.setOptionsWith(com.hp.hpl.jena.rdf.arp.ARPOptions)

setOptionsWith

public void setOptionsWith(ARPOptions opts)
Description copied from interface: ARPConfig
Copies the options from the argument to be used by this instance. To make further modifications it is necessary to call ARPConfig.getOptions() to retrieve this instance's copy of the options.

Specified by:
setOptionsWith in interface ARPConfig
Parameters:
opts - The new values to use.

installHandlers

public static void installHandlers(XMLReader rdr,
                                   com.hp.hpl.jena.rdf.arp.XMLHandler sax2rdf)
                            throws SAXException
Initializes an XMLReader to use the SAX2RDF object as its handler for all events, and to use namespaces and namespace prefixes.

Parameters:
rdr - The XMLReader to initialize.
sax2rdf - The SAX2RDF instance to use.
Throws:
SAXException

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler


Copyright © 2000, 2001, 2002, 2003, 2004 Hewlett-Packard Development Company, LP