Class IndexingSink
- java.lang.Object
-
- org.apache.maven.doxia.sink.impl.AbstractSink
-
- org.apache.maven.doxia.sink.impl.SinkWrapper
-
- org.apache.maven.doxia.index.IndexingSink
-
- Direct Known Subclasses:
CreateAnchorsForIndexEntries
public class IndexingSink extends SinkWrapper
A sink wrapper for populating an index tree for particular elements in a document. Currently this only generatesIndexEntryobjects for sections.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanhasOpenEntryIstrueif the sink is currently populating entry data (i.e.private booleanisCompleteIstrueonce the sink has been closed.private booleanisTitleprivate IndexEntryrootEntryprivate java.util.Stack<IndexEntry>stackThe stack.private IndexEntry.TypetypeThe current type.private java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger>usedIdsA 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 org.apache.maven.doxia.markup.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, STAR
-
Fields inherited from interface org.apache.maven.doxia.sink.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
Constructors Modifier Constructor Description IndexingSink(IndexEntry rootEntry)Deprecated.legacy constructor, useIndexingSink(Sink)withSinkAdapteras argument and callgetRootEntry()to retrieve the index tree afterwards.privateIndexingSink(IndexEntry rootEntry, Sink delegate)Default constructor.IndexingSink(Sink delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidanchor(java.lang.String name, SinkEventAttributes attributes)Starts an element which defines an anchor.voidclose()Close the writer or the stream, if needed.IndexEntrygetRootEntry()This should only be called once the sink is closed.java.lang.StringgetTitle()Getter for the fieldtitle.(package private) java.lang.StringgetUniqueId(java.lang.String id)Converts the given id into a unique one by potentially suffixing it with an index value.(package private) voidindexEntryComplete()protected voidonIndexEntry(IndexEntry entry)Called at the beginning of each entry (once all metadata about it is collected).private booleanparseAnchor(java.lang.String name)IndexEntrypeek()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, java.lang.String id)voidtext(java.lang.String text, SinkEventAttributes attributes)Adds a text.voidtitle(SinkEventAttributes attributes)Starts the title element.voidtitle_()Ends the title element.-
Methods inherited from class org.apache.maven.doxia.sink.impl.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 org.apache.maven.doxia.sink.impl.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 Detail
-
type
private IndexEntry.Type type
The current type.
-
stack
private final java.util.Stack<IndexEntry> stack
The stack.
-
usedIds
private final java.util.Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> 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
private final IndexEntry rootEntry
-
isComplete
private boolean isComplete
Istrueonce the sink has been closed.
-
isTitle
private boolean isTitle
-
hasOpenEntry
private boolean hasOpenEntry
Istrueif the sink is currently populating entry data (i.e. metadata about the current entry is not completely captured yet)
-
-
Constructor Detail
-
IndexingSink
@Deprecated public IndexingSink(IndexEntry rootEntry)
Deprecated.legacy constructor, useIndexingSink(Sink)withSinkAdapteras argument and callgetRootEntry()to retrieve the index tree afterwards.
-
IndexingSink
public IndexingSink(Sink delegate)
-
IndexingSink
private IndexingSink(IndexEntry rootEntry, Sink delegate)
Default constructor.
-
-
Method Detail
-
getRootEntry
public IndexEntry 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:
java.lang.IllegalStateException- in case the sink was not closed yet
-
getTitle
public java.lang.String getTitle()
- Returns:
- the title
-
title
public void title(SinkEventAttributes attributes)
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:
Sink.head(SinkEventAttributes)
-
title_
public void title_()
Description copied from interface:SinkEnds the title element.- Specified by:
title_in interfaceSink- Overrides:
title_in classSinkWrapper
-
section
public void section(int level, SinkEventAttributes attributes)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_
public void section_(int level)
Description copied from interface:SinkEnds a section at the given level.
-
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
public void text(java.lang.String text, SinkEventAttributes attributes)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
public void anchor(java.lang.String name, SinkEventAttributes attributes)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
private boolean parseAnchor(java.lang.String name)
-
setEntryId
private void setEntryId(IndexEntry entry, java.lang.String id)
-
getUniqueId
java.lang.String getUniqueId(java.lang.String id)
Converts the given id into a unique one by potentially suffixing it with an index value.- Parameters:
id-- Returns:
- the unique id
-
indexEntryComplete
void indexEntryComplete()
-
onIndexEntry
protected void onIndexEntry(IndexEntry entry)
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
private void pushNewEntry(IndexEntry.Type type)
Creates and pushes a new IndexEntry onto the top of this stack.
-
push
public void push(IndexEntry entry)
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
public IndexEntry peek()
peek.
- Returns:
- Looks at the IndexEntry at the top of this stack.
-
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 interfacejava.lang.AutoCloseable- Specified by:
closein interfaceSink- Overrides:
closein classSinkWrapper
-
-