org.geotools.xml
Class Parser

Object
  extended by Parser

public class Parser
extends Object

Main interface to the geotools xml parser.

Schema Resolution

See Configuration javadocs for instructions on how to customize schema resolution. This is often desirable in the case that the instance document being parsed contains invalid uri's in schema imports and includes.

Author:
Justin Deoliveira, The Open Planning Project

Nested Class Summary
static interface Parser.Properties
          Deprecated.  
 
Constructor Summary
Parser(Configuration configuration)
          Creats a new instance of the parser.
Parser(Configuration configuration, InputStream input)
          Deprecated. use Parser(Configuration) and parse(InputStream).
Parser(Configuration configuration, String input)
          Deprecated. use Parser(Configuration) and parse(InputStream).
 
Method Summary
 NamespaceSupport getNamespaces()
          Returns the namespace mappings maintained by the parser.
 XSDSchema[] getSchemas()
          Returns the schema objects referenced by the instance document being parsed.
 List getValidationErrors()
          Returns a list of any validation errors that occured while parsing.
 boolean isFailOnValidationError()
           
 boolean isValidating()
           
 Object parse()
          Deprecated. use parse(InputStream)
 Object parse(InputSource source)
          Parses an instance documented defined by a sax input source.
 Object parse(InputStream input)
          Parses an instance documented defined by an input stream.
 Object parse(Reader reader)
          Parses an instance documented defined by a reader.
protected  SAXParser parser()
           
 void setFailOnValidationError(boolean fail)
          Sets the flag which controls how the parser handles validation errors.
 void setStrict(boolean strict)
          Sets the strict parsing flag.
 void setValidating(boolean validating)
          Sets the flag controlling wether the parser should validate or not.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser(Configuration configuration)
Creats a new instance of the parser.

Parameters:
configuration - The parser configuration, bindings and context, must never be null.

Parser

public Parser(Configuration configuration,
              String input)
       throws IOException,
              URISyntaxException
Deprecated. use Parser(Configuration) and parse(InputStream).

Creates a new instance of the parser.

Parameters:
configuration - Object representing the configuration of the parser.
input - A uri representing the instance document to be parsed.
Throws:
ParserConfigurationException
SAXException - If a sax parser can not be created.
URISyntaxException - If input is not a valid uri.
IOException

Parser

public Parser(Configuration configuration,
              InputStream input)
Deprecated. use Parser(Configuration) and parse(InputStream).

Creates a new instance of the parser.

Parameters:
configuration - Object representing the configuration of the parser.
input - The stream representing the instance document to be parsed.
Method Detail

parse

public Object parse()
             throws IOException,
                    SAXException,
                    ParserConfigurationException
Deprecated. use parse(InputStream)

Signals the parser to parse the entire instance document. The object returned from the parse is the object which has been bound to the root element of the document. This method should only be called once for a single instance document.

Returns:
The object representation of the root element of the document.
Throws:
IOException
SAXException
ParserConfigurationException

parse

public Object parse(InputStream input)
             throws IOException,
                    SAXException,
                    ParserConfigurationException
Parses an instance documented defined by an input stream.

The object returned from the parse is the object which has been bound to the root element of the document. This method should only be called once for a single instance document.

Returns:
The object representation of the root element of the document.
Throws:
IOException
SAXException
ParserConfigurationException

parse

public Object parse(Reader reader)
             throws IOException,
                    SAXException,
                    ParserConfigurationException
Parses an instance documented defined by a reader.

The object returned from the parse is the object which has been bound to the root element of the document. This method should only be called once for a single instance document.

Returns:
The object representation of the root element of the document.
Throws:
IOException
SAXException
ParserConfigurationException

parse

public Object parse(InputSource source)
             throws IOException,
                    SAXException,
                    ParserConfigurationException
Parses an instance documented defined by a sax input source.

The object returned from the parse is the object which has been bound to the root element of the document. This method should only be called once for a single instance document.

Returns:
The object representation of the root element of the document.
Throws:
IOException
SAXException
ParserConfigurationException

setStrict

public void setStrict(boolean strict)
Sets the strict parsing flag.

When set to true, this will cause the parser to operate in a strict mode, which means that xml being parsed must be exactly correct with respect to the schema it references.

Some examples of cases in which the parser will throw an exception while operating in strict mode:

Parameters:
strict - The strict flag.

setValidating

public void setValidating(boolean validating)
Sets the flag controlling wether the parser should validate or not.

Parameters:
validating - Validation flag, true to validate, otherwise false

isValidating

public boolean isValidating()
Returns:
Flag determining if the parser is validatin or not.

setFailOnValidationError

public void setFailOnValidationError(boolean fail)
Sets the flag which controls how the parser handles validation errors.

When this flag is set, the parser will throw an exception when it encounters a validation error. Otherise the error will be stored, retreivable from getValidationErrors().

The default behavior is to set this flag to false. So client code should explicitly set this flag if it is desired that the exception be thrown when the validation error occurs.

Parameters:
fail - failure flag, true to fail, otherwise false

isFailOnValidationError

public boolean isFailOnValidationError()
Returns:
The flag determining how the parser deals with validation errors.

getValidationErrors

public List getValidationErrors()
Returns a list of any validation errors that occured while parsing.

Returns:
A list of errors, or an empty list if none.

getSchemas

public XSDSchema[] getSchemas()
Returns the schema objects referenced by the instance document being parsed. This method can only be called after a successful parse has begun.

Returns:
The schema objects used to parse the document, or null if parsing has not commenced.

getNamespaces

public NamespaceSupport getNamespaces()
Returns the namespace mappings maintained by the parser.

Clients may register additional namespace mappings. This is useful when an application whishes to provide some "default" namespace mappings.

Clients should register namespace mappings in the current "context", ie do not call NamespaceSupport.pushContext(). Example: Parser parser = new Parser( ... ); parser.getNamespaces().declarePrefix( "foo", "http://www.foo.com" ); ...

Returns:
The namespace support containing prefix to uri mappings.
Since:
2.4

parser

protected SAXParser parser()
                    throws ParserConfigurationException,
                           SAXException
Throws:
ParserConfigurationException
SAXException


Copyright © 1996-2009 Geotools. All Rights Reserved.