Package org.geotools.referencing.wkt
Class Preprocessor
- All Implemented Interfaces:
Serializable
,Cloneable
A parser that performs string replacements before to delegate the work to an other parser. String replacements are
specified through calls to the
addDefinition
method. In the example below, the WGS84
string in the parseObject call is expanded into the full GEOGCS["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:
-
Nested Class Summary
Nested classes/interfaces inherited from class Format
Format.Field
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPreprocessor
(Format parser) Creates a new preprocessor that delegates the work to the specified parser. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefinition
(String name, String value) Adds a predefined Well Know Text (WKT).format
(Object object, StringBuffer toAppendTo, FieldPosition position) Formats the specified object.Returns an unmodifiable set which contains all definition's names given to theaddDefinition(name, ...)
method.parseObject
(String wkt) Parses the specified Well Know Text without restriction on the expected type.parseObject
(String text, Class<?> type) Parses the specified text and ensure that the resulting object is of the specified type.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
-
Field Details
-
parser
The WKT parser, usually aParser
object.
-
-
Constructor Details
-
Preprocessor
Creates a new preprocessor that delegates the work to the specified parser.- Parameters:
parser
- The WKT parser, usually aParser
object.
-
-
Method Details
-
format
Formats the specified object. This method delegates the work to the parser given at construction time. -
parseObject
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
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
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
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
Removes a definition set in some previous call toaddDefinition(name, ...)
.- Parameters:
name
- The name of the definition to remove.
-
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
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.
-