Class AptSink

    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • buffer

        private java.lang.StringBuffer buffer
        A buffer that holds the current text when headerFlag or bufferFlag set to true.
      • tableCaptionBuffer

        private java.lang.StringBuilder tableCaptionBuffer
        A buffer that holds the table caption.
      • authors

        private java.util.Collection<java.lang.String> authors
        authors.
      • title

        private java.lang.String title
        title.
      • date

        private java.lang.String date
        date.
      • startFlag

        private boolean startFlag
        startFlag.
      • tableCaptionFlag

        private boolean tableCaptionFlag
        tableCaptionFlag.
      • tableCellFlag

        private boolean tableCellFlag
        tableCellFlag.
      • headerFlag

        private boolean headerFlag
        headerFlag.
      • bufferFlag

        private boolean bufferFlag
        bufferFlag.
      • itemFlag

        private boolean itemFlag
        itemFlag.
      • verbatimFlag

        private boolean verbatimFlag
        verbatimFlag.
      • isSource

        private boolean isSource
        verbatim source.
      • gridFlag

        private boolean gridFlag
        gridFlag for tables.
      • cellCount

        private int cellCount
        number of cells in a table.
      • writer

        private final java.io.PrintWriter writer
        The writer to use.
      • cellJustif

        private int[] cellJustif
        justification of table cells.
      • rowLine

        private java.lang.String rowLine
        a line of a row in a table.
      • listNestingIndent

        private java.lang.String listNestingIndent
        listNestingIndent.
      • listStyles

        private final java.util.Stack<java.lang.String> listStyles
        listStyles.
      • inlineStack

        protected java.util.Stack<java.util.List<java.lang.String>> inlineStack
        Keep track of the closing tags for inline events.
    • Constructor Detail

      • AptSink

        protected AptSink​(java.io.Writer writer)
        Constructor, initialize the Writer and the variables.
        Parameters:
        writer - not null writer to write the result. Should be an UTF-8 Writer. You could use newWriter methods from org.codehaus.plexus.util.WriterFactory.
    • Method Detail

      • getBuffer

        protected java.lang.StringBuffer getBuffer()
        Returns the buffer that holds the current text.
        Returns:
        A StringBuffer.
      • setHeadFlag

        protected void setHeadFlag​(boolean headFlag)
        Used to determine whether we are in head mode.
        Parameters:
        headFlag - True for head mode.
      • resetBuffer

        protected void resetBuffer()
        Reset the StringBuilder.
      • resetTableCaptionBuffer

        protected void resetTableCaptionBuffer()
        Reset the TableCaptionBuffer.
      • head

        public void head​(SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Starts the head element.

        This contains information about the current document, (eg its title) that is not considered document content. The head element is optional but if it exists, it has to be unique within a sequence of Sink events that produces one output document, and it has to come before the Sink.body(SinkEventAttributes) element.

        The canonical sequence of events for the head element is:

           sink.head();
        
           sink.title();
           sink.text("Title");
           sink.title_();
        
           sink.author();
           sink.text("Author");
           sink.author_();
        
           sink.date();
           sink.text("Date");
           sink.date_();
        
           sink.head_();
         

        but none of the enclosed events is required. However, if they exist they have to occur in the order shown, and the title() and date() events have to be unique (author() events may occur any number of times).

        Supported attributes are:

        PROFILE, LANG.
        Specified by:
        head in interface Sink
        Overrides:
        head in class SinkAdapter
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • head_

        public void head_()
        Ends the head element.
        Specified by:
        head_ in interface Sink
        Overrides:
        head_ in class SinkAdapter
      • title_

        public void title_()
        Ends the title element.
        Specified by:
        title_ in interface Sink
        Overrides:
        title_ in class SinkAdapter
      • date_

        public void date_()
        Ends the date element.
        Specified by:
        date_ in interface Sink
        Overrides:
        date_ in class SinkAdapter
      • section_

        public void section_​(int level)
        Description copied from class: SinkAdapter
        Ends a section at the given level.
        Specified by:
        section_ in interface Sink
        Overrides:
        section_ in class SinkAdapter
        Parameters:
        level - the section level (must be a value between 1 and 6).
      • sectionTitle

        public void sectionTitle​(int level,
                                 SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Start a new section title at the given level.

        This element is optional, but if it exists, it has to be contained, and be the first element, within a corresponding section element of the same level.

        NOTE: It is strongly recommended not to make section titles implicit anchors. Neither Parsers nor Sinks should insert any content that is not explicitly present in the original source document, as this would lead to undefined behaviour for multi-format processing chains. However, while Parsers must never emit anchors for section titles, some specialized Sinks may implement such a feature if the resulting output documents are not going to be further processed (and this is properly documented).

        Supported attributes are the base attributes plus ALIGN.

        Specified by:
        sectionTitle in interface Sink
        Overrides:
        sectionTitle in class SinkAdapter
        Parameters:
        level - the section title level (must be a value between 1 and 6).
        attributes - A set of SinkEventAttributes, may be null.
      • sectionTitle_

        public void sectionTitle_​(int level)
        Description copied from class: SinkAdapter
        Ends a section title at the given level.
        Specified by:
        sectionTitle_ in interface Sink
        Overrides:
        sectionTitle_ in class SinkAdapter
        Parameters:
        level - the section title level (must be a value between 1 and 6).
      • list_

        public void list_()
        Ends an unordered list element.
        Specified by:
        list_ in interface Sink
        Overrides:
        list_ in class SinkAdapter
      • listItem_

        public void listItem_()
        Ends a list item element within an unordered list.
        Specified by:
        listItem_ in interface Sink
        Overrides:
        listItem_ in class SinkAdapter
      • definition_

        public void definition_()
        Ends a definition element within a definition list.
        Specified by:
        definition_ in interface Sink
        Overrides:
        definition_ in class SinkAdapter
      • verbatim

        public void verbatim​(SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Starts a verbatim block, ie a block where whitespace has semantic relevance.

        Text in a verbatim block must only be wrapped at the linebreaks in the source, and spaces should not be collapsed. It should be displayed in a fixed-width font to retain the formatting but the overall size may be chosen by the implementation.

        Most Sink events may be emitted within a verbatim block, the only elements explicitly forbidden are font-changing events and figures. Also, verbatim blocks may not be nested.

        Supported attributes are the base attributes plus:

        DECORATION (values: "source"), ALIGN, WIDTH.
        Specified by:
        verbatim in interface Sink
        Overrides:
        verbatim in class SinkAdapter
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • table

        public void table​(SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Starts a table.

        The canonical sequence of events for the table element is:

           sink.table();
        
           sink.tableRows(justify, true);
        
           sink.tableRow();
           sink.tableCell();
           sink.text("cell 1,1");
           sink.tableCell_();
           sink.tableCell();
           sink.text("cell 1,2");
           sink.tableCell_();
           sink.tableRow_();
        
           sink.tableRows_();
        
           sink.tableCaption();
           sink.text("Table caption");
           sink.tableCaption_();
        
           sink.table_();
        
         

        where the tableCaption element is optional.

        However, NOTE that the order of tableCaption and Sink.tableRows(int[],boolean) events is arbitrary, ie a parser may emit the tableCaption before or after the tableRows. Implementing sinks should be prepared to handle both possibilities.

        Supported attributes are the base attributes plus:

        ALIGN, BGCOLOR, BORDER, CELLPADDING, CELLSPACING, FRAME, RULES, SUMMARY, WIDTH.
        Specified by:
        table in interface Sink
        Overrides:
        table in class SinkAdapter
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • table_

        public void table_()
        Ends a table element.
        Specified by:
        table_ in interface Sink
        Overrides:
        table_ in class SinkAdapter
      • tableRows

        public void tableRows​(int[] justification,
                              boolean grid)
        Description copied from class: SinkAdapter
        Starts an element that contains rows of table data.
        Specified by:
        tableRows in interface Sink
        Overrides:
        tableRows in class SinkAdapter
        Parameters:
        justification - the default justification of columns. This can be overridden by individual table rows or table cells. If null a left alignment is assumed by default. If this array has less elements than there are columns in the table then the value of the last array element will be taken as default for the remaining table cells.
        grid - true to provide a grid, false otherwise.
        See Also:
        Sink.table(SinkEventAttributes), Sink.JUSTIFY_CENTER, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_RIGHT
      • tableRows_

        public void tableRows_()
        Ends an element that contains rows of table data.
        Specified by:
        tableRows_ in interface Sink
        Overrides:
        tableRows_ in class SinkAdapter
      • buildRowLine

        private void buildRowLine()
        Construct a table row.
      • tableCell

        public void tableCell​(boolean headerRow)
        Starts a table cell.
        Parameters:
        headerRow - If this cell is part of a header row.
      • endTableCell

        private void endTableCell()
        Ends a table cell.
      • anchor

        public void anchor​(java.lang.String name,
                           SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Starts an element which defines an anchor.

        The name parameter 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. If NAME is specified in the SinkEventAttributes, it will be overwritten by the name parameter.

        Specified by:
        anchor in interface Sink
        Overrides:
        anchor in class SinkAdapter
        Parameters:
        name - the name of the anchor. This has to be a valid SGML NAME token.
        attributes - A set of SinkEventAttributes, may be null.
      • link

        public void link​(java.lang.String name,
                         SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Starts a link.

        The name parameter has to be a valid URI according to RFC 3986, i.e. for internal links (links to an anchor within the same source document), name should start with the character "#". This also implies that all unsafe characters are already encoded.

        Supported attributes are the base attributes plus:

        CHARSET, COORDS, HREF, HREFLANG, REL, REV, SHAPE, TARGET, TYPE.

        If HREF is specified in the SinkEventAttributes, it will be overwritten by the name parameter.

        Specified by:
        link in interface Sink
        Overrides:
        link in class SinkAdapter
        Parameters:
        name - the name of the link.
        attributes - A set of SinkEventAttributes, may be null.
        See Also:
        URI.toASCIIString()
      • link_

        public void link_()
        Ends a link element.
        Specified by:
        link_ in interface Sink
        Overrides:
        link_ in class SinkAdapter
      • link

        public void link​(java.lang.String name,
                         java.lang.String target)
        A link with a target.
        Parameters:
        name - The name of the link.
        target - The link target.
      • inline

        public void inline​(SinkEventAttributes attributes)
        Starts an inline element.

        The inline method is similar to Sink.text(String,SinkEventAttributes), but allows you to wrap arbitrary elements in addition to text.

        Supported attributes are the base attributes plus

        SEMANTICS (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").
        Specified by:
        inline in interface Sink
        Overrides:
        inline in class SinkAdapter
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • nonBreakingSpace

        public void nonBreakingSpace()
        Adding a non breaking space, ie a space without any special formatting operations.
        Specified by:
        nonBreakingSpace in interface Sink
        Overrides:
        nonBreakingSpace in class SinkAdapter
      • text

        public void text​(java.lang.String text,
                         SinkEventAttributes attributes)
        Description copied from class: SinkAdapter
        Adds a text.

        The text parameter should contain only real content, ie any ignorable/collapsable whitespace/EOLs or other pretty-printing should be removed/normalized by a parser.

        If text contains any variants of line terminators, they should be normalized to the System EOL by an implementing Sink.

        Supported attributes are the base attributes plus

        SEMANTICS (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:
        text in interface Sink
        Overrides:
        text in class SinkAdapter
        Parameters:
        text - The text to write.
        attributes - A set of SinkEventAttributes, may be null.
      • rawText

        public void rawText​(java.lang.String text)
        Adding a raw text, ie a text without any special formatting operations.
        Specified by:
        rawText in interface Sink
        Overrides:
        rawText in class SinkAdapter
        Parameters:
        text - The text to write.
      • comment

        public void comment​(java.lang.String comment)
        Add a comment.
        Specified by:
        comment in interface Sink
        Overrides:
        comment in class SinkAdapter
        Parameters:
        comment - The comment to write.
      • unknown

        public void unknown​(java.lang.String name,
                            java.lang.Object[] requiredParams,
                            SinkEventAttributes attributes)
        Add an unknown event. This may be used by parsers to notify a general Sink about an event that doesn't fit into any event defined by the Sink API. Depending on the parameters, a Sink may decide whether or not to process the event, emit it as raw text, as a comment, log it, etc. Unkown events just log a warning message but are ignored otherwise.
        Specified by:
        unknown in interface Sink
        Overrides:
        unknown in class SinkAdapter
        Parameters:
        name - The name of the event.
        requiredParams - An optional array of required parameters to the event. May be null.
        attributes - A set of SinkEventAttributes, may be null.
        See Also:
        Sink.unknown(String,Object[],SinkEventAttributes)
      • write

        protected void write​(java.lang.String text)
        Write text to output.
        Parameters:
        text - The text to write.
      • content

        protected void content​(java.lang.String text)
        Write Apt escaped text to output.
        Parameters:
        text - The text to write.
      • verbatimContent

        protected void verbatimContent​(java.lang.String text)
        Write Apt escaped text to output.
        Parameters:
        text - The text to write.
      • flush

        public void flush()
        Flush the writer or the stream, if needed. Flushing a previously-flushed Sink has no effect.
        Specified by:
        flush in interface Sink
        Overrides:
        flush in class SinkAdapter
      • close

        public void close()
        Close the writer or the stream, if needed. Closing a previously-closed Sink has no effect.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface Sink
        Overrides:
        close in class SinkAdapter
      • escapeAPT

        private static java.lang.String escapeAPT​(java.lang.String text)
        Escape special characters in a text in APT:
         \~, \=, \-, \+, \*, \[, \], \<, \>, \{, \}, \\
         
        Parameters:
        text - the String to escape, may be null
        Returns:
        the text escaped, "" if null String input