|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.unidex.xflat.SaxFlatFileParser
Sax2FlatFileParser
class.
SAX 1.0 has been superseded by SAX 2.0.
The SaxFlatFileParser
class converts flat file data into
a stream of SAX
1.0 document events.
The SaxFlatFileParser
class is an implementation of the
SAX 1.0 org.xml.sax.Parser
and
org.xml.sax.Locator
interfaces.
In other words, it's a SAX 1.0 driver for the XML Convert
flat file parser.
Please note the following about the SaxFlatFileParser
class:
setXflatSchema()
method must be invoked before
the parse()
method is invoked;
Locator
provides information about the
record that generated the current document event;
getLineNumber()
method
is a record number, which will not be equal to
the line number when the records in the flat file data
are not lines;
getColumnNumber()
method
is a column number within a record;
setLocale()
method always throws a
SAXException
, since Locales are not supported;
org.xml.sax.EntityResolver
via the setEntityResolver()
method,
then SaxFlatFileParser
will not call the
EntityResolver
, since this
SAX 1.0 feature is not supported;
org.xml.sax.DTDHandler
via the setDTDHandler()
method,
then SaxFlatFileParser
will not call the
DTDHandler
, since this SAX 1.0 feature is not supported;
SaxFlatFileParser
class will ignore
the following XFlat attributes in the XFlat schema: DTD
,
EncodingName
, OmitXmlDeclaration
and
Standalone
;
SaxFlatFileParser
class will
generate a multiple streams of SAX 1.0 document events (i.e., the
class will generate multiple start document events).
Note that SAX 1.0 parsers, including SaxFlatFileParser
,
are reusable but not re-entrant;
the application may reuse a SaxFlatFileParser
object
(possibly with a different input source and/or a different
document handler and/or a different XFlat schema) once the first
parse has completed successfully,
but it may not invoke the parse() methods recursively within a parse.
The following sample application uses the SaxFlatFileParser
class to convert a flat file (i.e., "file:/c:/invoices.txt
")
into
a stream of SAX 1.0 document events. These events are handled by an
instance of the UserAppDocHandler
class, which is an
implementation of the org.xml.sax.DocumentHandler
interface. The conversion is driven by the XFlat schema
(i.e., "file:/c:/invoices.xfl
") that is specified via
the setXflatSchema()
method.
import com.unidex.xflat.SaxFlatFileParser ; import org.xml.sax.InputSource ; import org.xml.sax.Parser ; public class UserApp { public static void main ( String args[] ) throws Exception { // Create the input sources. InputSource xflat_schema_source = new InputSource( "file:/c:/invoices.xfl" ) ; InputSource flat_file_source = new InputSource( "file:/c:/invoices.txt" ) ; // Create the SaxFlatFileParser. SaxFlatFileParser parser = new SaxFlatFileParser() ; // Create the SAX document handler. UserAppDocHandler handler = new UserAppDocHandler() ; // Pass the XFlat schema input source to the parser. parser.setXflatSchema( xflat_schema_source, true ) ; // Pass the document handler to the parser. parser.setDocumentHandler( handler ) ; // Parse the flat file, and convert it to a stream // of SAX document events that will be handled by // the document handler. parser.parse( flat_file_source ) ; } }
The SaxFlatFileParser
class is thread-safe if the threads
do not share any SaxFlatFileParser
instances and if
the SaxFlatFileParser
instances do not share any
character streams or byte streams.
DocumentHandler
,
DTDHandler
,
EntityResolver
,
InputSource
,
Locator
,
Parser
,
SAXException
,
SAXParseException
Constructor Summary | |
SaxFlatFileParser()
Deprecated. Creates a SaxFlatFileParser instance
that can be used
to convert flat file data into a stream of
SAX 1.0
document events. |
Method Summary | |
int |
getColumnNumber()
Deprecated. Returns the column number for the current document event. |
int |
getLineNumber()
Deprecated. Returns the record number for the current document event. |
java.lang.String |
getPublicId()
Deprecated. Returns the public identifier for the current document event. |
java.lang.String |
getSystemId()
Deprecated. Returns the system identifier for the current document event. |
void |
parse(org.xml.sax.InputSource flat_file_data_source)
Deprecated. Parses flat file data and converts the flat file data into a stream of SAX 1.0 document events. |
void |
parse(java.lang.String system_id)
Deprecated. Same as the previous method, except that the source of the flat file data is specified with a system identifier. |
void |
setDocumentHandler(org.xml.sax.DocumentHandler document_handler)
Deprecated. Allows an application to register a document event handler. |
void |
setDTDHandler(org.xml.sax.DTDHandler dtd_handler)
Deprecated. If your application specifies an org.xml.sax.DTDHandler object
via the setDTDHandler() method,
then SaxFlatFileParser will not call the
DTDHandler , since this SAX feature is
not supported. |
void |
setEntityResolver(org.xml.sax.EntityResolver entity_resolver)
Deprecated. If your application specifies an org.xml.sax.EntityResolver object
via the setEntityResolver() method,
then SaxFlatFileParser will not call the
EntityResolver , since this SAX feature
is not supported. |
void |
setErrorHandler(org.xml.sax.ErrorHandler error_handler)
Deprecated. Allows an application to register an error event handler. |
void |
setLocale(java.util.Locale locale)
Deprecated. If your application calls the setLocale() method
to specify a java.util.Locale object, then
the method will throw a SAXException ,
since Locales are not supported. |
void |
setXflatSchema(org.xml.sax.InputSource schema_source,
boolean suppress_startup_message)
Deprecated. Specifies the source of an XFlat schema, which the parse() method will use
to parse and validate flat file data. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SaxFlatFileParser()
SaxFlatFileParser
instance
that can be used
to convert flat file data into a stream of
SAX 1.0
document events.
A SaxFlatFileParser
instance can be used to parse
multiple flat files that conform to different XFlat schemas.
It is more efficient to use a single SaxFlatFileParser
instance to parse multiple flat files than it
is to use multiple SaxFlatFileParser
instances.
Method Detail |
public void setXflatSchema(org.xml.sax.InputSource schema_source, boolean suppress_startup_message) throws org.xml.sax.SAXException
parse()
method will use
to parse and validate flat file data.
The application must call this method before it calls
the parse()
method for the first time.
The application may also call the setXflatSchema()
method between parses, so that
a SaxFlatFileParser
instance can
parse a variety of flat files that conform to
different XFlat schemas.
If the setXflatSchema()
method is called
in the middle of a parse, the
current parse will continue to use the previously
specified XFlat schema; once the current parse has completed,
the next parse (if any) will use the new XFlat schema.
The setXflatSchema()
method parses
the specified XFlat schema
and stores the information in an in-memory
data structure, which is not garbage collected until
the setXflatSchema()
method is called again or until
the SaxFlatFileParser
instance is
garbage collected.
If the specified XFlat schema is not a
well-formed XML document or if
it does not conform to the XFlat language, then this
method will throw an org.xml.sax.SAXException
,
whose message will
contain a detailed description of the syntax
error, including the following information about the
location of the error:
The line number of the first line in the schema is one. The column number of the first character in a line is one.
The setXflatSchema()
method writes a
start up message to standard output
unless the suppress_startup_message
parameter is
set to true
.
schema_source
- The org.xml.sax.InputSource object that
specifies an XFlat schema.suppress_startup_message
- The setXflatSchema()
method will not display the start up message to standard output
if this boolean flag is set to true
.org.xml.sax.SAXException
- if an I/O error occurs
while reading the XFlat schema input source or if the
XFlat schema is not well-formed or if the XFlat schema
does not conform to the XFlat language.InputSource
,
SAXException
public void setEntityResolver(org.xml.sax.EntityResolver entity_resolver)
org.xml.sax.EntityResolver
object
via the setEntityResolver()
method,
then SaxFlatFileParser
will not call the
EntityResolver
, since this SAX feature
is not supported.setEntityResolver
in interface org.xml.sax.Parser
entity_resolver
- The org.xml.sax.EntityResolver object for
resolving entities.EntityResolver
public void setDocumentHandler(org.xml.sax.DocumentHandler document_handler)
setDocumentHandler
in interface org.xml.sax.Parser
document_handler
- The org.xml.sax.DocumentHandler object for
handling document events.DocumentHandler
public void setDTDHandler(org.xml.sax.DTDHandler dtd_handler)
org.xml.sax.DTDHandler
object
via the setDTDHandler()
method,
then SaxFlatFileParser
will not call the
DTDHandler
, since this SAX feature is
not supported.setDTDHandler
in interface org.xml.sax.Parser
dtd_handler
- The org.xml.sax.DTDHandler object for
handling DTD events.DTDHandler
public void setErrorHandler(org.xml.sax.ErrorHandler error_handler)
org.xml.sax.ErrorHandler
object.setErrorHandler
in interface org.xml.sax.Parser
error_handler
- The org.xml.sax.ErrorHandler object for
handling errors.ErrorHandler
public void setLocale(java.util.Locale locale) throws org.xml.sax.SAXException
setLocale()
method
to specify a java.util.Locale
object, then
the method will throw a SAXException
,
since Locales are not supported.setLocale
in interface org.xml.sax.Parser
locale
- The java.util.Locale object, which specifies
the locale for errors and warnings.org.xml.sax.SAXException
- whenever this
method is called.SAXException
,
Locale
public void parse(org.xml.sax.InputSource flat_file_data_source) throws org.xml.sax.SAXException, java.io.IOException
parse()
method validates the flat file data
against the current XFlat schema.
The application must call the setXflatSchema()
method before it calls
the parse()
method for the first time.
The application may also call the setXflatSchema()
method between parses, so that
a SaxFlatFileParser
instance can
parse a variety of flat files that conform to
different XFlat schemas.
If the setXflatSchema()
method is called
in the middle of a parse, the
current parse will continue to use the previously
specified XFlat schema; once the current parse has completed,
the next parse (if any) will use the new XFlat schema.
When the parse()
completes, the input source is closed.
If the flat file data does not conform to the XFlat schema,
then the conversion is aborted and the parse()
method throws a SAXException
. The exception message
will contain a detailed description of the syntax
error, including the following information about the
location of the error:
The record number of the first record in the flat file data is one. The column number of the first character in a record is one. The record offset of the first record in the flat file data is one. If the first record is 80 characters in length, then the record offset of the second record is 81.
parse
in interface org.xml.sax.Parser
flat_file_data_source
- The org.xml.sax.InputSource object for
the flat file data to be parsed.org.xml.sax.SAXException
- if the flat file
data does not conform to the XFlat schema.java.io.IOException
- if an I/O error occurs
while reading the flat file data input source.InputSource
,
SAXException
,
IOException
public void parse(java.lang.String system_id) throws org.xml.sax.SAXException, java.io.IOException
parse
in interface org.xml.sax.Parser
system_id
- The system identifier for
the flat file data to be parsed.org.xml.sax.SAXException
- if the flat file
data does not conform to the XFlat schema.java.io.IOException
- if an I/O error occurs
while reading the flat file data.SAXException
,
IOException
public java.lang.String getPublicId()
getPublicId
in interface org.xml.sax.Locator
null
if none is available.Locator
,
getSystemId()
public java.lang.String getSystemId()
getSystemId
in interface org.xml.sax.Locator
null
if none is available.Locator
,
getPublicId()
public int getLineNumber()
getLineNumber
in interface org.xml.sax.Locator
Locator
,
getColumnNumber()
public int getColumnNumber()
getColumnNumber
in interface org.xml.sax.Locator
Locator
,
getLineNumber()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1999 - 2002 Unidex, Inc. |