Package org.geotools.referencing.wkt
Class Preprocessor
-
- All Implemented Interfaces:
Serializable
,Cloneable
public class Preprocessor extends Format
A parser that performs string replacements before to delegate the work to an other parser. String replacements are specified through calls to theaddDefinition
method. In the example below, theWGS84
string in the parseObject call is expanded into the fullGEOGCS["WGS84", ...
string before to be parsed.addDefinition("WGS84", "GEOGCS[\"WGS84\", DATUM[
...etc...]]
...etc...
parseObject("PROJCS[\"Mercator_1SP\", WGS84, PROJECTION[]]")
- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class Format
Format.Field
-
-
Constructor Summary
Constructors Constructor Description Preprocessor(Format parser)
Creates a new preprocessor that delegates the work to the specified parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDefinition(String name, String value)
Adds a predefined Well Know Text (WKT).StringBuffer
format(Object object, StringBuffer toAppendTo, FieldPosition position)
Formats the specified object.Set
getDefinitionNames()
Returns an unmodifiable set which contains all definition's names given to theaddDefinition(name, ...)
method.Object
parseObject(String wkt)
Parses the specified Well Know Text without restriction on the expected type.Object
parseObject(String text, Class<?> type)
Parses the specified text and ensure that the resulting object is of the specified type.Object
parseObject(String wkt, ParsePosition position)
Parses the specified Well Know Text starting at the specified position.void
printDefinitions(Writer out)
Prints to the specified stream a table of all definitions.void
removeDefinition(String name)
Removes a definition set in some previous call toaddDefinition(name, ...)
.-
Methods inherited from class Format
clone, format, formatToCharacterIterator
-
-
-
-
Method Detail
-
format
public StringBuffer format(Object object, StringBuffer toAppendTo, FieldPosition position)
Formats the specified object. This method delegates the work to the parser given at construction time.
-
parseObject
public Object parseObject(String wkt, ParsePosition position)
Parses the specified Well Know Text starting at the specified position. The default implementation delegates the work toparseObject
(wkt.substring(position.getIndex()))- Specified by:
parseObject
in classFormat
- Parameters:
wkt
- The text to parse.position
- The index of the first character to parse.- Returns:
- The parsed object, or
null
in case of failure.
-
parseObject
public Object parseObject(String wkt) throws ParseException
Parses the specified Well Know Text without restriction on the expected type. The default implementation delegates the work toparseObject
(wkt, Object.class)- Overrides:
parseObject
in classFormat
- Parameters:
wkt
- The text to parse.- Returns:
- The parsed object.
- Throws:
ParseException
- if the text can't be parsed.
-
parseObject
public Object parseObject(String text, Class<?> type) throws ParseException, FactoryException
Parses the specified text and ensure that the resulting object is of the specified type. The text can be any of the following:
- A name declared in some previous call to
addDefinition(name, ...)
. - A Well Know Text, which may contains itself shortcuts declared in previous call to
addDefinition
. This text is given to the underlyingparser
. - Any services provided by subclasses. For example a subclass way recognize some
authority code like
EPSG:6326
.
- Parameters:
text
- The text, as a name, a WKT to parse, or an authority code.type
- The expected type for the object to be parsed (usually aCoordinateReferenceSystem.class
orMathTransform.class
).- Returns:
- The object.
- Throws:
ParseException
- if parsing the specified WKT failed.FactoryException
- if the object is not of the expected type.
- A name declared in some previous call to
-
addDefinition
public void addDefinition(String name, String value) throws ParseException
Adds a predefined Well Know Text (WKT). Thevalue
argument given to this method can contains itself other definitions specified in some previous calls to this method.- Parameters:
name
- The name for the definition to be added.value
- The Well Know Text (WKT) represented by the name.- Throws:
IllegalArgumentException
- if the name is invalid.ParseException
- if the WKT can't be parsed.
-
removeDefinition
public void removeDefinition(String name)
Removes a definition set in some previous call toaddDefinition(name, ...)
.- Parameters:
name
- The name of the definition to remove.
-
getDefinitionNames
public Set getDefinitionNames()
Returns an unmodifiable set which contains all definition's names given to theaddDefinition(name, ...)
method. The elements in this set are sorted in alphabetical order.
-
printDefinitions
public void printDefinitions(Writer out) throws IOException
Prints to the specified stream a table of all definitions. The content of this table is inferred from the values given to theaddDefinition(java.lang.String, java.lang.String)
method.- Parameters:
out
- writer The output stream where to write the table.- Throws:
IOException
- if an error occured while writting to the output stream.
-
-