Class FoAggregateSink

All Implemented Interfaces:
LogEnabled, Markup, XmlMarkup, FoMarkup, Sink

public class FoAggregateSink extends FoSink
A Doxia Sink that produces an aggregated FO model. The usage is similar to the following:
 FoAggregateSink sink = new FoAggregateSink( writer );
 sink.setDocumentModel( documentModel );
 sink.beginDocument();
 sink.coverPage();
 sink.toc();
 ...
 sink.endDocument();
 
Note: the documentModel object contains several document metadata, but only a few of them are used in this sink (i.e. author, confidential, date and title), the others are ignored.
Since:
1.1
  • Field Details

  • Constructor Details

    • FoAggregateSink

      public FoAggregateSink(Writer writer)
      Constructor.
      Parameters:
      writer - The writer for writing the result.
  • Method Details

    • head

      public void head()
      Starts the head element.
      Specified by:
      head in interface Sink
      Overrides:
      head in class FoSink
      See Also:
    • 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
      Overrides:
      head in class FoSink
      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 FoSink
    • title

      public void title()
      Starts the title element.
      Specified by:
      title in interface Sink
      Overrides:
      title in class FoSink
      See Also:
    • title

      public void title(SinkEventAttributes attributes)
      Starts the title element. This is used to identify the document.

      Supported attributes are the base attributes.

      Specified by:
      title in interface Sink
      Overrides:
      title in class FoSink
      Parameters:
      attributes - A set of SinkEventAttributes, may be null.
      See Also:
    • title_

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

      public void author()
      Starts an author element.
      Specified by:
      author in interface Sink
      Overrides:
      author in class FoSink
      See Also:
    • author

      public void author(SinkEventAttributes attributes)
      Starts an author element. This is used to identify the author of the document.

      Supported attributes are: EMAIL.

      Specified by:
      author in interface Sink
      Overrides:
      author in class FoSink
      Parameters:
      attributes - A set of SinkEventAttributes, may be null.
      See Also:
    • author_

      public void author_()
      Ends an author element.
      Specified by:
      author_ in interface Sink
      Overrides:
      author_ in class FoSink
    • date

      public void date()
      Starts the date element.
      Specified by:
      date in interface Sink
      Overrides:
      date in class FoSink
      See Also:
    • 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
      Overrides:
      date in class FoSink
      Parameters:
      attributes - A set of SinkEventAttributes, may be null.
      See Also:
    • date_

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

      public void body()
      Starts the body of a document.
      Specified by:
      body in interface Sink
      Overrides:
      body in class FoSink
      See Also:
    • body

      public void body(SinkEventAttributes attributes)
      Starts the body of a document. This contains the document's content.

      Supported attributes are the base attributes.

      Specified by:
      body in interface Sink
      Overrides:
      body in class FoSink
      Parameters:
      attributes - A set of SinkEventAttributes, may be null.
      See Also:
    • body_

      public void body_()
      Ends the body element.
      Specified by:
      body_ in interface Sink
      Overrides:
      body_ in class FoSink
    • setDocumentTitle

      public void setDocumentTitle(String title)
      Sets the title of the current document. This is used as a chapter title in the page header.
      Parameters:
      title - the title of the current document.
    • setDocumentName

      public void setDocumentName(String name)
      Sets the name of the current source document, relative to the source root. Used to resolve links to other source documents.
      Parameters:
      name - the name for the current document.
    • setDocumentModel

      public void setDocumentModel(DocumentModel model)
      Sets the DocumentModel to be used by this sink. The DocumentModel provides all the meta-information required to render a document, eg settings for the cover page, table of contents, etc.
      By default, a TOC will be added at the beginning of the document.
      Parameters:
      model - the DocumentModel.
      See Also:
    • setDocumentModel

      public void setDocumentModel(DocumentModel model, int tocPos)
      Sets the DocumentModel to be used by this sink. The DocumentModel provides all the meta-information required to render a document, eg settings for the cover page, table of contents, etc.
      Parameters:
      model - the DocumentModel, could be null.
      tocPos - should be one of these values: TOC_NONE, TOC_START and TOC_END.
      Since:
      1.1.2
    • getIdName

      private String getIdName(String name)
      Translates the given name to a usable id. Prepends "./" and strips any extension.
      Parameters:
      name - the name for the current document.
      Returns:
      String
    • figureGraphics

      public void figureGraphics(String name)
      Adding a source of a graphic.
      Specified by:
      figureGraphics in interface Sink
      Overrides:
      figureGraphics in class FoSink
      Parameters:
      name - the source
    • figureGraphics

      public void figureGraphics(String src, SinkEventAttributes attributes)
      Adds a graphic element.

      The src parameter should be a valid link, ie it can be an absolute URL or a link relative to the current source document.

      Supported attributes are the base attributes plus:

      SRC, ALT, WIDTH, HEIGHT, ALIGN, BORDER, HSPACE, VSPACE, ISMAP, USEMAP.

      If the SRC attribute is specified in SinkEventAttributes, it will be overridden by the src parameter.

      Specified by:
      figureGraphics in interface Sink
      Overrides:
      figureGraphics in class FoSink
      Parameters:
      src - the image source, a valid URL.
      attributes - A set of SinkEventAttributes, may be null.
      See Also:
    • anchor

      public void anchor(String name)
      Starts an element which defines an anchor.
      Specified by:
      anchor in interface Sink
      Overrides:
      anchor in class FoSink
      Parameters:
      name - the name of the anchor.
      See Also:
    • anchor

      public void anchor(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
      Overrides:
      anchor in class FoSink
      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(String name)
      Starts an element which defines a link.
      Specified by:
      link in interface Sink
      Overrides:
      link in class FoSink
      Parameters:
      name - the name of the link.
      See Also:
    • link

      public void link(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
      Overrides:
      link in class FoSink
      Parameters:
      name - the name of the link.
      attributes - A set of SinkEventAttributes, may be null.
    • resolveLinkRelativeToBase

      private String resolveLinkRelativeToBase(String name)
    • chopExtension

      private String chopExtension(String name)
    • writeStartTag

      protected void writeStartTag(HTML.Tag tag, String attributeId)
      Writes a start tag, prepending EOL.
      Overrides:
      writeStartTag in class FoSink
      Parameters:
      tag - The tag.
      attributeId - An id identifying the attribute set.
    • writeStartTag

      protected void writeStartTag(HTML.Tag tag, String id, String name)
      Writes a start tag, prepending EOL.
      Overrides:
      writeStartTag in class FoSink
      Parameters:
      tag - The tag.
      id - An id to add.
      name - The name (value) of the id.
    • writeEndTag

      protected void writeEndTag(HTML.Tag t)
      Ends a Tag without writing an EOL. For instance:
      </tag>
      .
      Overrides:
      writeEndTag in class FoSink
      Parameters:
      t - a HTML.Tag object.
    • writeEmptyTag

      protected void writeEmptyTag(HTML.Tag tag, String attributeId)
      Writes a simple tag, appending EOL.
      Overrides:
      writeEmptyTag in class FoSink
      Parameters:
      tag - The tag name.
      attributeId - An id identifying the attribute set.
    • write

      protected void write(String text)
      Write a text to the sink. Writes a text, swallowing any exceptions.
      Overrides:
      write in class FoSink
      Parameters:
      text - the given text to write
    • writeln

      protected void writeln(String text)
      Writes a text, appending EOL.
      Overrides:
      writeln in class FoSink
      Parameters:
      text - The text to write.
    • content

      protected void content(String text)
      Writes content, escaping special characters.
      Overrides:
      content in class FoSink
      Parameters:
      text - The text to write.
    • newline

      protected void newline()
      Writes EOL.
    • startPageSequence

      protected void startPageSequence(String headerText, String footerText)
      Starts a page sequence, depending on the current chapter.
      Parameters:
      headerText - The text to write in the header, if null, nothing is written.
      footerText - The text to write in the footer, if null, nothing is written.
    • getHeaderText

      protected String getHeaderText()
      Returns the text to write in the header of each page.
      Returns:
      String
    • getFooterText

      protected String getFooterText()
      Returns the text to write in the footer of each page.
      Returns:
      String
    • getChapterString

      protected String getChapterString()
      Returns the current chapter number as a string. By default does nothing, gets overridden by AggregateSink.
      Overrides:
      getChapterString in class FoSink
      Returns:
      an empty String.
    • regionBefore

      protected void regionBefore(String headerText)
      Writes a 'xsl-region-before' block.
      Overrides:
      regionBefore in class FoSink
      Parameters:
      headerText - The text to write in the header, if null, nothing is written.
    • regionAfter

      protected void regionAfter(String footerText)
      Writes a 'xsl-region-after' block. By default does nothing, gets overridden by AggregateSink.
      Overrides:
      regionAfter in class FoSink
      Parameters:
      footerText - The text to write in the footer, if null, nothing is written.
    • chapterHeading

      protected void chapterHeading(String headerText, boolean chapterNumber)
      Writes a chapter heading. By default does nothing, gets overridden by AggregateSink.
      Overrides:
      chapterHeading in class FoSink
      Parameters:
      headerText - The text to write in the header, if null, the current document title is written.
      chapterNumber - True if the chapter number should be written in front of the text.
    • toc

      public void toc()
      Writes a table of contents. The DocumentModel has to contain a DocumentTOC for this to work.
    • writeTocItems

      private void writeTocItems(List<DocumentTOCItem> tocItems, int level)
    • currentTocNumber

      private String currentTocNumber()
    • pdfBookmarks

      protected void pdfBookmarks()
      Writes a fo:bookmark-tree. The DocumentModel has to contain a DocumentTOC for this to work.
      Overrides:
      pdfBookmarks in class FoSink
    • renderBookmarkItems

      private void renderBookmarkItems(List<DocumentTOCItem> items)
    • coverPage

      public void coverPage()
      Writes a cover page. The DocumentModel has to contain a DocumentMeta for this to work.
    • writeCoverHead

      private void writeCoverHead(DocumentCover cover)
    • writeCoverBody

      private void writeCoverBody(DocumentCover cover, DocumentMeta meta)
    • writeCoverFooter

      private void writeCoverFooter(DocumentCover cover, DocumentMeta meta)
    • getBundle

      private ResourceBundle getBundle(Locale locale)
    • getGraphicsAttributes

      private SinkEventAttributeSet getGraphicsAttributes(String logo)