org.geotools.referencing.wkt
Class AbstractParser

Object
  extended by Format
      extended by AbstractParser
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
MathTransformParser

public abstract class AbstractParser
extends Format

Base class for Well Know Text (WKT) parser.

Since:
2.0
Author:
Remi Eve, Martin Desruisseaux (IRD)
See Also:
Well Know Text specification, OGC WKT Coordinate System Issues, Serialized Form
Module:

Nested Class Summary
 
Nested classes/interfaces inherited from class Format
Format.Field
 
Constructor Summary
AbstractParser(Symbols symbols)
          Constructs a parser using the specified set of symbols.
 
Method Summary
 StringBuffer format(Object object, StringBuffer toAppendTo, FieldPosition pos)
          Format the specified object as a Well Know Text.
 Citation getAuthority()
          Returns the preferred authority for formatting WKT entities.
protected  Element getTree(String text, ParsePosition position)
          Returns a tree of Element for the specified text.
 String getWarning()
          If a warning occured during the last WKT formatting, returns the warning.
 boolean isColorEnabled()
          Returns true if syntax coloring is enabled.
protected abstract  Object parse(Element element)
          Parses the next element in the specified Well Know Text (WKT) tree.
 Object parseObject(String text)
          Parses a Well Know Text (WKT).
 Object parseObject(String text, ParsePosition position)
          Parses a Well Know Text (WKT).
 void reformat(BufferedReader in, Writer out, PrintWriter err)
          Read WKT strings from an input stream and reformat them to the specified output stream.
 void setAuthority(Citation authority)
          Set the preferred authority for formatting WKT entities.
 void setColorEnabled(boolean enabled)
          Enables or disables syntax coloring on ANSI X3.64 (aka ECMA-48 and ISO/IEC 6429) compatible terminal.
 
Methods inherited from class Format
clone, format, formatToCharacterIterator
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser(Symbols symbols)
Constructs a parser using the specified set of symbols.

Parameters:
symbols - The set of symbols to use.
Method Detail

getAuthority

public Citation getAuthority()
Returns the preferred authority for formatting WKT entities. The format methods will uses the name specified by this authority, if available.

Returns:
The expected authority.

setAuthority

public void setAuthority(Citation authority)
Set the preferred authority for formatting WKT entities. The format methods will uses the name specified by this authority, if available.

Parameters:
authority - The new authority.

isColorEnabled

public boolean isColorEnabled()
Returns true if syntax coloring is enabled. By default, syntax coloring is disabled.

Returns:
true if syntax coloring are enabled.
Since:
2.4

setColorEnabled

public void setColorEnabled(boolean enabled)
Enables or disables syntax coloring on ANSI X3.64 (aka ECMA-48 and ISO/IEC 6429) compatible terminal. This apply only when formatting text. By default, syntax coloring is disabled. When enabled, Format.format(Object) tries to highlight most of the elements compared by CRS.equalsIgnoreMetadata(java.lang.Object, java.lang.Object).

Parameters:
enabled - true for enabling syntax coloring.
Since:
2.4

parseObject

public final Object parseObject(String text)
                         throws ParseException
Parses a Well Know Text (WKT).

Overrides:
parseObject in class Format
Parameters:
text - The text to be parsed.
Returns:
The object.
Throws:
ParseException - if the string can't be parsed.

parseObject

public final Object parseObject(String text,
                                ParsePosition position)
Parses a Well Know Text (WKT).

Specified by:
parseObject in class Format
Parameters:
text - The text to be parsed.
position - The position to start parsing from.
Returns:
The object.

parse

protected abstract Object parse(Element element)
                         throws ParseException
Parses the next element in the specified Well Know Text (WKT) tree.

Parameters:
element - The element to be parsed.
Returns:
The object.
Throws:
ParseException - if the element can't be parsed.

getTree

protected final Element getTree(String text,
                                ParsePosition position)
                         throws ParseException
Returns a tree of Element for the specified text.

Parameters:
text - The text to parse.
position - In input, the position where to start parsing from. In output, the first character after the separator.
Returns:
The tree of elements to parse.
Throws:
ParseException - If an parsing error occured while creating the tree.

format

public StringBuffer format(Object object,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Format the specified object as a Well Know Text. Formatting will uses the same set of symbols than the one used for parsing.

Specified by:
format in class Format
Parameters:
object - The object to format.
toAppendTo - Where the text is to be appended.
pos - An identification of a field in the formatted text.
See Also:
getWarning()

reformat

public void reformat(BufferedReader in,
                     Writer out,
                     PrintWriter err)
              throws IOException
Read WKT strings from an input stream and reformat them to the specified output stream. WKT strings are read until the the end-of-stream, or until an unparsable WKT has been hit. In this later case, an error message is formatted to the specified error stream.

Parameters:
in - The input stream.
out - The output stream.
err - The error stream.
Throws:
IOException - if an error occured while reading from the input stream or writting to the output stream.

getWarning

public String getWarning()
If a warning occured during the last WKT formatting, returns the warning. Otherwise returns null. The warning is cleared every time a new object is formatted.

Returns:
The last warning, or null if none.
Since:
2.4


Copyright © 1996-2009 Geotools. All Rights Reserved.