Class IndexingSink
- All Implemented Interfaces:
AutoCloseable, Markup, Sink
- Direct Known Subclasses:
CreateAnchorsForIndexEntries
IndexEntry objects for sections.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanIstrueif the sink is currently populating entry data (i.e.private booleanIstrueonce the sink has been closed.private booleanprivate final IndexEntryprivate final Stack<IndexEntry> The stack.private IndexEntry.TypeThe current type.private final Map<String, AtomicInteger> A map containing all used ids of index entries as key and how often they are used as value (0-based, i.e.Fields inherited from interface Markup
COLON, EOL, EQUAL, GREATER_THAN, LEFT_CURLY_BRACKET, LEFT_SQUARE_BRACKET, LESS_THAN, MINUS, PLUS, QUOTE, RIGHT_CURLY_BRACKET, RIGHT_SQUARE_BRACKET, SEMICOLON, SLASH, SPACE, STARFields inherited from interface Sink
JUSTIFY_CENTER, JUSTIFY_LEFT, JUSTIFY_RIGHT, NUMBERING_DECIMAL, NUMBERING_LOWER_ALPHA, NUMBERING_LOWER_ROMAN, NUMBERING_UPPER_ALPHA, NUMBERING_UPPER_ROMAN, SECTION_LEVEL_1, SECTION_LEVEL_2, SECTION_LEVEL_3, SECTION_LEVEL_4, SECTION_LEVEL_5, SECTION_LEVEL_6 -
Constructor Summary
ConstructorsModifierConstructorDescriptionIndexingSink(IndexEntry rootEntry) Deprecated.privateIndexingSink(IndexEntry rootEntry, Sink delegate) Default constructor.IndexingSink(Sink delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidanchor(String name, SinkEventAttributes attributes) Starts an element which defines an anchor.voidclose()Close the writer or the stream, if needed.This should only be called once the sink is closed.getTitle()Getter for the fieldtitle.(package private) StringgetUniqueId(String id) Converts the given id into a unique one by potentially suffixing it with an index value.(package private) voidprotected voidonIndexEntry(IndexEntry entry) Called at the beginning of each entry (once all metadata about it is collected).private booleanparseAnchor(String name) peek()peek.voidpop()Removes the IndexEntry at the top of this stack.voidpush(IndexEntry entry) Pushes an IndexEntry onto the top of this stack.private voidpushNewEntry(IndexEntry.Type type) Creates and pushes a new IndexEntry onto the top of this stack.voidsection(int level, SinkEventAttributes attributes) Start a new section at the given level.voidsection_(int level) Ends a section at the given level.voidsectionTitle_(int level) Ends a section title at the given level.private voidsetEntryId(IndexEntry entry, String id) voidtext(String text, SinkEventAttributes attributes) Adds a text.voidtitle(SinkEventAttributes attributes) Starts the title element.voidtitle_()Ends the title element.Methods inherited from class SinkWrapper
address, address_, anchor_, article, article_, author, author_, blockquote, blockquote_, body, body_, bold, bold_, comment, content, content_, data, data_, date, date_, definedTerm, definedTerm_, definition, definition_, definitionList, definitionList_, definitionListItem, definitionListItem_, division, division_, figure, figure_, figureCaption, figureCaption_, figureGraphics, flush, footer, footer_, getDocumentLocator, getWrappedSink, head, head_, header, header_, horizontalRule, inline, inline_, italic, italic_, lineBreak, lineBreakOpportunity, link, link_, list, list_, listItem, listItem_, monospaced, monospaced_, navigation, navigation_, nonBreakingSpace, numberedList, numberedList_, numberedListItem, numberedListItem_, pageBreak, paragraph, paragraph_, rawText, sectionTitle, setDocumentLocator, setWrappedSink, sidebar, sidebar_, table, table_, tableCaption, tableCaption_, tableCell, tableCell_, tableHeaderCell, tableHeaderCell_, tableRow, tableRow_, tableRows, tableRows_, time, time_, unknown, verbatim, verbatim_Methods inherited from class AbstractSink
address, anchor, article, author, blockquote, body, content, data, date, definedTerm, definition, definitionList, definitionListItem, division, figure, figureCaption, figureGraphics, footer, formatLocation, getLocationLogPrefix, head, header, horizontalRule, init, inline, lineBreak, lineBreakOpportunity, link, list, listItem, navigation, numberedList, numberedListItem, paragraph, section1, section1_, section2, section2_, section3, section3_, section4, section4_, section5, section5_, section6, section6_, sectionTitle, sectionTitle_, sectionTitle1, sectionTitle1_, sectionTitle2, sectionTitle2_, sectionTitle3, sectionTitle3_, sectionTitle4, sectionTitle4_, sectionTitle5, sectionTitle5_, sectionTitle6, sectionTitle6_, sidebar, table, tableCaption, tableCell, tableHeaderCell, tableRow, tableRows, text, time, title, unifyEOLs, verbatim
-
Field Details
-
type
The current type. -
stack
The stack. -
usedIds
A map containing all used ids of index entries as key and how often they are used as value (0-based, i.e. 0 means used 1 time).AtomicIntegeris only used here as it implements a mutable integer (not for its atomicity). -
rootEntry
-
isComplete
private boolean isCompleteIstrueonce the sink has been closed. -
isTitle
private boolean isTitle -
hasOpenEntry
private boolean hasOpenEntryIstrueif the sink is currently populating entry data (i.e. metadata about the current entry is not completely captured yet)
-
-
Constructor Details
-
IndexingSink
Deprecated.legacy constructor, useIndexingSink(Sink)withSinkAdapteras argument and callgetRootEntry()to retrieve the index tree afterwards. -
IndexingSink
-
IndexingSink
Default constructor.
-
-
Method Details
-
getRootEntry
This should only be called once the sink is closed. Before that the tree might not be complete.- Returns:
- the tree of entries starting from the root
- Throws:
IllegalStateException- in case the sink was not closed yet
-
getTitle
- Returns:
- the title
-
title
Description copied from interface:SinkStarts the title element. This is used to identify the document.Supported attributes are the
base attributes.- Specified by:
titlein interfaceSink- Overrides:
titlein classSinkWrapper- Parameters:
attributes- A set ofSinkEventAttributes, may benull.- See Also:
-
title_
public void title_()Description copied from interface:SinkEnds the title element.- Specified by:
title_in interfaceSink- Overrides:
title_in classSinkWrapper
-
section
Description copied from interface:SinkStart a new section at the given level.Sections with higher level have to be entirely contained within sections of lower level.
Supported attributes are the
base attributes.- Specified by:
sectionin interfaceSink- Overrides:
sectionin classSinkWrapper- Parameters:
level- the section level (must be a value between 1 and 6).attributes- A set ofSinkEventAttributes, may benull.
-
section_
-
sectionTitle_
public void sectionTitle_(int level) Description copied from interface:SinkEnds a section title at the given level.- Specified by:
sectionTitle_in interfaceSink- Overrides:
sectionTitle_in classSinkWrapper- Parameters:
level- the section title level (must be a value between 1 and 6).
-
text
Description copied from interface:SinkAdds a text.The
textparameter should contain only real content, ie any ignorable/collapsable whitespace/EOLs or other pretty-printing should be removed/normalized by a parser.If
textcontains any variants of line terminators, they should be normalized to the System EOL by an implementing Sink.Supported attributes are the
base attributesplusSEMANTICS(values "emphasis", "strong", "small", "line-through", "citation", "quote", "definition", "abbreviation", "italic", "bold", "monospaced", "variable", "sample", "keyboard", "superscript", "subscript", "annotation", "highlight", "ruby", "rubyBase", "rubyText", "rubyTextContainer", "rubyParentheses", "bidirectionalIsolation", "bidirectionalOverride", "phrase", "insert", "delete").The following attributes are deprecated:
VALIGN(values "sub", "sup"),DECORATION(values "underline", "overline", "line-through"),STYLE(values "italic", "bold", "monospaced").- Specified by:
textin interfaceSink- Overrides:
textin classSinkWrapper- Parameters:
text- The text to write.attributes- A set ofSinkEventAttributes, may benull.
-
anchor
Description copied from interface:SinkStarts an element which defines an anchor.The
nameparameter has to be a valid SGML NAME token. According to the HTML 4.01 specification section 6.2 SGML basic types:ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Supported attributes are the
base attributes. IfNAMEis specified in the SinkEventAttributes, it will be overwritten by thenameparameter.- Specified by:
anchorin interfaceSink- Overrides:
anchorin classSinkWrapper- Parameters:
name- the name of the anchor. This has to be a valid SGML NAME token.attributes- A set ofSinkEventAttributes, may benull.
-
parseAnchor
-
setEntryId
-
getUniqueId
-
indexEntryComplete
void indexEntryComplete() -
onIndexEntry
Called at the beginning of each entry (once all metadata about it is collected). The events for the metadata are buffered and only flushed after this method was called.- Parameters:
entry- the newly collected entry
-
pushNewEntry
Creates and pushes a new IndexEntry onto the top of this stack. -
push
Pushes an IndexEntry onto the top of this stack.- Parameters:
entry- to put.
-
pop
public void pop()Removes the IndexEntry at the top of this stack. -
peek
-
close
public void close()Description copied from interface:SinkClose the writer or the stream, if needed. Closing a previously-closed Sink has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSink- Overrides:
closein classSinkWrapper
-
IndexingSink(Sink)withSinkAdapteras argument and callgetRootEntry()to retrieve the index tree afterwards.