Class RandomAccessSink

  • All Implemented Interfaces:
    LogEnabled, Sink

    public class RandomAccessSink
    extends java.lang.Object
    implements Sink
    The RandomAccessSink provides the ability to create a Sink with hooks. A page can be prepared by first creating its structure and specifying the positions of these hooks. After specifying the structure, the page can be filled with content from one or more models. These hooks can prevent you to have to loop over the model multiple times to build the page as desired.
    Since:
    1.3
    • Field Detail

      • encoding

        private java.lang.String encoding
      • coreOutputStream

        private java.io.OutputStream coreOutputStream
      • coreSink

        private Sink coreSink
      • sinks

        private java.util.List<Sink> sinks
      • outputStreams

        private java.util.List<java.io.ByteArrayOutputStream> outputStreams
      • currentSink

        private Sink currentSink
    • Constructor Detail

      • RandomAccessSink

        public RandomAccessSink​(SinkFactory sinkFactory,
                                java.io.OutputStream stream)
                         throws java.io.IOException

        Constructor for RandomAccessSink.

        Parameters:
        sinkFactory - a SinkFactory object.
        stream - a OutputStream object.
        Throws:
        java.io.IOException - if any.
      • RandomAccessSink

        public RandomAccessSink​(SinkFactory sinkFactory,
                                java.io.OutputStream stream,
                                java.lang.String encoding)
                         throws java.io.IOException

        Constructor for RandomAccessSink.

        Parameters:
        sinkFactory - a SinkFactory object.
        stream - a OutputStream object.
        encoding - a String object.
        Throws:
        java.io.IOException - if any.
      • RandomAccessSink

        public RandomAccessSink​(SinkFactory sinkFactory,
                                java.io.File outputDirectory,
                                java.lang.String outputName)
                         throws java.io.IOException

        Constructor for RandomAccessSink.

        Parameters:
        sinkFactory - a SinkFactory object.
        outputDirectory - a File object.
        outputName - a String object.
        Throws:
        java.io.IOException - if any.
      • RandomAccessSink

        public RandomAccessSink​(SinkFactory sinkFactory,
                                java.io.File outputDirectory,
                                java.lang.String outputName,
                                java.lang.String encoding)
                         throws java.io.IOException

        Constructor for RandomAccessSink.

        Parameters:
        sinkFactory - a SinkFactory object.
        outputDirectory - a File object.
        outputName - a String object.
        encoding - a String object.
        Throws:
        java.io.IOException - if any.
    • Method Detail

      • address_

        public void address_()
        Ends an address element.
        Specified by:
        address_ in interface Sink
      • addSinkHook

        public Sink addSinkHook()
        By calling this method a sink reference is added at the current position. You can write to both the new sink reference and the original sink. After flushing all sinks will be flushed in the right order.
        Returns:
        a subsink reference you can write to
      • anchor

        public void anchor​(java.lang.String name,
                           SinkEventAttributes attributes)
        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
        Parameters:
        name - the name of the anchor. This has to be a valid SGML NAME token.
        attributes - A set of SinkEventAttributes, may be null.
      • anchor_

        public void anchor_()
        Ends an anchor element.
        Specified by:
        anchor_ in interface Sink
      • article_

        public void article_()
        Ends the article element.
        Specified by:
        article_ in interface Sink
      • author_

        public void author_()
        Ends an author element.
        Specified by:
        author_ in interface Sink
      • blockquote_

        public void blockquote_()
        Ends an blockquote element.
        Specified by:
        blockquote_ in interface Sink
      • body_

        public void body_()
        Ends the body element.
        Specified by:
        body_ in interface Sink
      • close

        public void close()
        Close all sinks
        Specified by:
        close in interface Sink
      • comment

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

        public void content()
        Start the main content section between the header and the footer within the sections and/or body.
        Specified by:
        content in interface Sink
      • content

        public void content​(SinkEventAttributes attributes)
        Start the main content section between the header and the footer within the sections and/or body.

        Supported attributes are the base attributes.

        Specified by:
        content in interface Sink
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • content_

        public void content_()
        Ends a main content section.
        Specified by:
        content_ in interface Sink
      • data

        public void data​(java.lang.String value)
        Starts a data element which groups together other elements representing microformats.
        Specified by:
        data in interface Sink
        Parameters:
        value - a String object.
        See Also:
        Sink.data(String, SinkEventAttributes)
      • data

        public void data​(java.lang.String value,
                         SinkEventAttributes attributes)
        Starts a data element which groups together other elements representing microformats.

        Supported attributes are the base attributes plus VALUE.

        Specified by:
        data in interface Sink
        Parameters:
        value - the machine readable value of the data, may be null.
        attributes - A set of SinkEventAttributes, may be null.
      • data_

        public void data_()
        Ends an data element.
        Specified by:
        data_ in interface Sink
      • date

        public void date​(SinkEventAttributes attributes)
        Starts the date element. This is used to identify the date of the document: there is no strict definition if it is creation date or last modification date, which are the 2 classical semantics. There is no formal formatting requirements either.
        The date is recommended (but it is not a requirement) to be aligned to the ISO-8601 standard, i.e.:
        YYYY-MM-DD
        where
        • YYYY is the year in the Gregorian calendar,
        • MM is the month of the year between 01 (January) and 12 (December),
        • and DD is the day of the month between 01 and 31.

        Supported attributes are: none.

        Specified by:
        date in interface Sink
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
        See Also:
        Sink.head(SinkEventAttributes)
      • date_

        public void date_()
        Ends the date element.
        Specified by:
        date_ in interface Sink
      • definedTerm_

        public void definedTerm_()
        Ends a definition term element within a definition list.
        Specified by:
        definedTerm_ in interface Sink
      • definitionListItem_

        public void definitionListItem_()
        Ends a list item element within a definition list.
        Specified by:
        definitionListItem_ in interface Sink
      • definitionList_

        public void definitionList_()
        Ends a definition list element.
        Specified by:
        definitionList_ in interface Sink
      • definition_

        public void definition_()
        Ends a definition element within a definition list.
        Specified by:
        definition_ in interface Sink
      • division_

        public void division_()
        Ends a division element.
        Specified by:
        division_ in interface Sink
      • figure

        public void figure​(SinkEventAttributes attributes)
        Starts a basic image embedding element.

        The canonical sequence of events for the figure element is:

           sink.figure();
        
           sink.figureGraphics( "figure.png" );
        
           sink.figureCaption();
           sink.text( "Figure caption",);
           sink.figureCaption_();
        
           sink.figure_();
         

        where the figureCaption element is optional.

        However, NOTE that the order of figureCaption and figureGraphics events is arbitrary, ie a parser may emit the figureCaption before or after the figureGraphics. Implementing sinks should be prepared to handle both possibilities.

        NOTE also that the figureGraphics() event does not have to be embedded inside figure(), in particular for in-line images the figureGraphics() should be used stand-alone (in HTML language, figureGraphics() produces a <img> tag, while figure() opens a paragraph- or <div>- like environment).

        Supported attributes are the base attributes.

        Specified by:
        figure in interface Sink
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • figureCaption_

        public void figureCaption_()
        Ends a caption of an image.
        Specified by:
        figureCaption_ in interface Sink
      • figureGraphics

        public void figureGraphics​(java.lang.String name)
        Adding a source of a graphic.
        Specified by:
        figureGraphics in interface Sink
        Parameters:
        name - the source
      • figure_

        public void figure_()
        Ends a basic image embedding element.
        Specified by:
        figure_ in interface Sink
      • flush

        public void flush()
        Flush all sinks
        Specified by:
        flush in interface Sink
      • footer

        public void footer()
        Start a new footer within the section or body.
        Specified by:
        footer in interface Sink
      • footer_

        public void footer_()
        Ends a footer element.
        Specified by:
        footer_ in interface Sink
      • head

        public void head​(SinkEventAttributes attributes)
        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
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • head_

        public void head_()
        Ends the head element.
        Specified by:
        head_ in interface Sink
      • header

        public void header()
        Start a new header within the section or body.
        Specified by:
        header in interface Sink
      • header_

        public void header_()
        Ends a header element.
        Specified by:
        header_ in interface Sink
      • 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
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • inline_

        public void inline_()
        Ends an inline element.
        Specified by:
        inline_ in interface Sink
      • link

        public void link​(java.lang.String name,
                         SinkEventAttributes attributes)
        Starts a link.

        The name parameter has to be a valid html href parameter, ie for internal links (links to an anchor within the same source document), name should start with the character "#".

        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
        Parameters:
        name - the name of the link.
        attributes - A set of SinkEventAttributes, may be null.
      • link_

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

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

        public void list_()
        Ends an unordered list element.
        Specified by:
        list_ in interface Sink
      • navigation_

        public void navigation_()
        Ends the navigation element.
        Specified by:
        navigation_ in interface Sink
      • nonBreakingSpace

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

        public void numberedListItem_()
        Ends a list item element within an ordered list.
        Specified by:
        numberedListItem_ in interface Sink
      • numberedList_

        public void numberedList_()
        Ends an ordered list element.
        Specified by:
        numberedList_ in interface Sink
      • pageBreak

        public void pageBreak()
        Adding a new page separator.
        Specified by:
        pageBreak in interface Sink
      • paragraph_

        public void paragraph_()
        Ends a paragraph element.
        Specified by:
        paragraph_ in interface Sink
      • 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
        Parameters:
        text - The text to write.
      • section

        public void section​(int level,
                            SinkEventAttributes attributes)
        Start 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:
        section in interface Sink
        Parameters:
        level - the section level.
        attributes - A set of SinkEventAttributes, may be null.
      • section1_

        public void section1_()
        Ends a first heading element.
        Specified by:
        section1_ in interface Sink
      • section2_

        public void section2_()
        Ends a second heading element.
        Specified by:
        section2_ in interface Sink
      • section3_

        public void section3_()
        Ends a third heading element.
        Specified by:
        section3_ in interface Sink
      • section4_

        public void section4_()
        Ends a 4th heading element.
        Specified by:
        section4_ in interface Sink
      • section5_

        public void section5_()
        Ends a 5th heading element.
        Specified by:
        section5_ in interface Sink
      • section6_

        public void section6_()
        Ends a 6th heading element.
        Specified by:
        section6_ in interface Sink
      • sectionTitle

        public void sectionTitle()
        Starts a title heading element.
        Specified by:
        sectionTitle in interface Sink
      • sectionTitle

        public void sectionTitle​(int level,
                                 SinkEventAttributes attributes)
        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
        Parameters:
        level - the section title level.
        attributes - A set of SinkEventAttributes, may be null.
      • sectionTitle1_

        public void sectionTitle1_()
        Ends a first title heading element.
        Specified by:
        sectionTitle1_ in interface Sink
      • sectionTitle2_

        public void sectionTitle2_()
        Ends a second title heading element.
        Specified by:
        sectionTitle2_ in interface Sink
      • sectionTitle3_

        public void sectionTitle3_()
        Ends a third title heading element.
        Specified by:
        sectionTitle3_ in interface Sink
      • sectionTitle4_

        public void sectionTitle4_()
        Ends a 4th title heading element.
        Specified by:
        sectionTitle4_ in interface Sink
      • sectionTitle5_

        public void sectionTitle5_()
        Ends a 5th title heading element.
        Specified by:
        sectionTitle5_ in interface Sink
      • sectionTitle6_

        public void sectionTitle6_()
        Ends a 6th title heading element.
        Specified by:
        sectionTitle6_ in interface Sink
      • sectionTitle_

        public void sectionTitle_()
        Ends a title heading element.
        Specified by:
        sectionTitle_ in interface Sink
      • sectionTitle_

        public void sectionTitle_​(int level)
        Ends a section title at the given level.
        Specified by:
        sectionTitle_ in interface Sink
        Parameters:
        level - the section title level.
      • section_

        public void section_​(int level)
        Ends a section at the given level.
        Specified by:
        section_ in interface Sink
        Parameters:
        level - the section level.
      • sidebar_

        public void sidebar_()
        Ends the sidebar element.
        Specified by:
        sidebar_ in interface Sink
      • table

        public void table​(SinkEventAttributes attributes)
        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
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • tableCaption_

        public void tableCaption_()
        Ends a caption element of a table.
        Specified by:
        tableCaption_ in interface Sink
      • tableCell

        public void tableCell​(java.lang.String width)
        Starts a cell element which defines a cell that contains data.
        Specified by:
        tableCell in interface Sink
        Parameters:
        width - the size of the cell.
      • tableCell_

        public void tableCell_()
        Ends a cell element.
        Specified by:
        tableCell_ in interface Sink
      • tableHeaderCell

        public void tableHeaderCell​(java.lang.String width)
        Starts a cell element which defines a cell that contains header information.
        Specified by:
        tableHeaderCell in interface Sink
        Parameters:
        width - the size of the header cell.
      • tableHeaderCell_

        public void tableHeaderCell_()
        Ends a cell header element.
        Specified by:
        tableHeaderCell_ in interface Sink
      • tableRow_

        public void tableRow_()
        Ends a row element.
        Specified by:
        tableRow_ in interface Sink
      • tableRows

        public void tableRows​(int[] justification,
                              boolean grid)
        Starts an element that contains rows of table data.
        Specified by:
        tableRows in interface Sink
        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
      • table_

        public void table_()
        Ends a table element.
        Specified by:
        table_ in interface Sink
      • text

        public void text​(java.lang.String text,
                         SinkEventAttributes attributes)
        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
        Parameters:
        text - The text to write.
        attributes - A set of SinkEventAttributes, may be null.
      • time

        public void time​(java.lang.String datetime,
                         SinkEventAttributes attributes)
        Starts a time element which groups together other elements representing a time.

        Supported attributes are the base attributes plus DATETIME.

        Specified by:
        time in interface Sink
        Parameters:
        datetime - the machine readable value of the time, may be null.
        attributes - A set of SinkEventAttributes, may be null.
      • time_

        public void time_()
        Ends a time element.
        Specified by:
        time_ in interface Sink
      • title_

        public void title_()
        Ends the title element.
        Specified by:
        title_ in interface Sink
      • 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.
        Specified by:
        unknown in interface Sink
        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.
      • verbatim

        public void verbatim​(boolean boxed)
        Starts an element which indicates that whitespace in the enclosed text has semantic relevance.
        Specified by:
        verbatim in interface Sink
        Parameters:
        boxed - true to add a box, false otherwise
      • verbatim

        public void verbatim​(SinkEventAttributes attributes)
        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 (value: "boxed"), ALIGN, WIDTH.
        Specified by:
        verbatim in interface Sink
        Parameters:
        attributes - A set of SinkEventAttributes, may be null.
      • verbatim_

        public void verbatim_()
        Ends a verbatim element.
        Specified by:
        verbatim_ in interface Sink
      • enableLogging

        public void enableLogging​(Log log)
        Enable a Doxia logger for this Doxia component.
        Specified by:
        enableLogging in interface LogEnabled
        Parameters:
        log - a Log.