Package org.apache.sis.internal.book
Class CodeColorizer
java.lang.Object
org.apache.sis.internal.book.CodeColorizer
Apply syntax colorization on Java code. This class is different than most other colorization tools
since its apply different colors depending on whether a word is known to be defined in an OGC/ISO
standard, in GeoAPI or in Apache SIS.
- Since:
- 0.7
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
The specifier of an identifier. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Document
The object to use for creating nodes.private final Map<String,
CodeColorizer.Specifier> Map of predefined identifiers and the authority who defined them.Lists of Java keywords. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate CodeColorizer.Specifier
getSpecifier
(String word) Returns the re-defined identifiers and authority who defined it for the given word.void
Applies emphasing on the words found in all text node of the given node.private static boolean
isJavaIdentifier
(String identifier, int i, int upper) Returnstrue
if the given string fromi
inclusive toupper
exclusive is a Java identifier.private static boolean
startsWithWord
(String string, String prefix) Returnstrue
if the given string starts with the given prefix, and the character following the prefix is not an identifier character.(package private) final String
Returns the value to put inside inclass
attribute of a<code>
element encompassing the given identifier.(package private) static Node[]
Returns all nodes in the given list as an array.
-
Field Details
-
JAVA_KEYWORDS
Lists of Java keywords. -
identifierSpecifiers
Map of predefined identifiers and the authority who defined them. -
document
The object to use for creating nodes.
-
-
Constructor Details
-
CodeColorizer
Creates a new color colorizer.- Parameters:
document
- the object to use for creating nodes.- Throws:
IOException
- if an error occurred while reading the list of predefined identifiers.BookException
- if an identifier is defined twice.
-
-
Method Details
-
toArray
Returns all nodes in the given list as an array. This method is used for getting a snapshot of the list before to modify it (for example before the elements are moved to another node). -
getSpecifier
Returns the re-defined identifiers and authority who defined it for the given word.- Parameters:
word
- the word for which to get a specifier.- Returns:
- the specifier for the given word, or
null
if none.
-
startsWithWord
Returnstrue
if the given string starts with the given prefix, and the character following the prefix is not an identifier character. -
isJavaIdentifier
Returnstrue
if the given string fromi
inclusive toupper
exclusive is a Java identifier. Ignore zero-width space and soft hyphen. -
styleForSingleIdentifier
Returns the value to put inside inclass
attribute of a<code>
element encompassing the given identifier.This method differs from
highlight(Node, String)
in that it is used for applying a single style on the whole string. By contrast,highlight(…)
parses the text and may apply different styles for different words. -
highlight
Applies emphasing on the words found in all text node of the given node.- Parameters:
parent
- the root element where to put Java keywords in bold characters. This is typically a<samp>
or<code>
element.type
-"xml"
if the element to process is XML rather than Java code.- Throws:
BookException
- if an element cannot be processed.
-