Class FoAggregateSink
- java.lang.Object
-
- org.apache.maven.doxia.sink.impl.AbstractSink
-
- org.apache.maven.doxia.sink.impl.SinkAdapter
-
- org.apache.maven.doxia.sink.impl.AbstractXmlSink
-
- org.apache.maven.doxia.module.fo.FoSink
-
- org.apache.maven.doxia.module.fo.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 Summary
Fields Modifier and Type Field Description private int
chapter
Counts the current chapter level.private static java.lang.String
COVER_HEADER_HEIGHT
private DocumentModel
docModel
The document model to be used by this sink.private java.lang.String
docName
Name of the source file of the current document, relative to the source root.private java.lang.String
docTitle
Title of the chapter, used in the page header.private boolean
ignoreText
Content in head is ignored in aggregated documents.static int
TOC_END
Table Of Content at the end of the document.static int
TOC_NONE
No Table Of Content.static int
TOC_START
Table Of Content at the start of the document.private int
tocPosition
Current position of the TOC, see#TOC_POSITION
private java.util.Stack<NumberedListItem>
tocStack
Used to get the current position in the TOC.-
Fields inherited from class org.apache.maven.doxia.module.fo.FoSink
inlineStack, warnMessages
-
Fields inherited from interface org.apache.maven.doxia.module.fo.FoMarkup
BASIC_LINK_TAG, BLOCK_TAG, BOOKMARK_TAG, BOOKMARK_TITLE_TAG, BOOKMARK_TREE_TAG, FLOW_TAG, FO_NAMESPACE, INLINE_TAG, LAYOUT_MASTER_SET_TAG, LEADER_TAG, LIST_BLOCK_TAG, LIST_ITEM_BODY_TAG, LIST_ITEM_LABEL_TAG, LIST_ITEM_TAG, PAGE_NUMBER_CITATION_TAG, PAGE_NUMBER_TAG, PAGE_SEQUENCE_TAG, REGION_AFTER_TAG, REGION_BEFORE_TAG, REGION_BODY_TAG, ROOT_TAG, SIMPLE_PAGE_MASTER_TAG, STATIC_CONTENT_TAG, TABLE_AND_CAPTION_TAG, TABLE_BODY_TAG, TABLE_CAPTION_TAG, TABLE_CELL_TAG, TABLE_COLUMN_TAG, TABLE_ROW_TAG, TABLE_TAG
-
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, ROLE, SECTION_LEVEL_1, SECTION_LEVEL_2, SECTION_LEVEL_3, SECTION_LEVEL_4, SECTION_LEVEL_5, SECTION_LEVEL_6
-
Fields inherited from interface org.apache.maven.doxia.markup.XmlMarkup
BANG, CDATA, DOCTYPE_START, ENTITY_START, XML_NAMESPACE
-
-
Constructor Summary
Constructors Constructor Description FoAggregateSink(java.io.Writer writer)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
anchor(java.lang.String name)
Starts an element which defines an anchor.void
anchor(java.lang.String name, SinkEventAttributes attributes)
Starts an element which defines an anchor.void
author()
Starts an author element.void
author(SinkEventAttributes attributes)
Starts an author element.void
author_()
Ends an author element.void
body()
Starts the body of a document.void
body(SinkEventAttributes attributes)
Starts the body of a document.void
body_()
Ends the body element.protected void
chapterHeading(java.lang.String headerText, boolean chapterNumber)
Writes a chapter heading.private java.lang.String
chopExtension(java.lang.String name)
protected void
content(java.lang.String text)
Writes content, escaping special characters.void
coverPage()
Writes a cover page.private java.lang.String
currentTocNumber()
void
date()
Starts the date element.void
date(SinkEventAttributes attributes)
Starts the date element.void
date_()
Ends the date element.void
figureGraphics(java.lang.String name)
Adding a source of a graphic.void
figureGraphics(java.lang.String src, SinkEventAttributes attributes)
Adds a graphic element.private java.util.ResourceBundle
getBundle(java.util.Locale locale)
protected java.lang.String
getChapterString()
Returns the current chapter number as a string.protected java.lang.String
getFooterText()
Returns the text to write in the footer of each page.private SinkEventAttributeSet
getGraphicsAttributes(java.lang.String logo)
protected java.lang.String
getHeaderText()
Returns the text to write in the header of each page.private java.lang.String
getIdName(java.lang.String name)
Translates the given name to a usable id.void
head()
Starts the head element.void
head(SinkEventAttributes attributes)
Starts the head element.void
head_()
Ends the head element.void
link(java.lang.String name)
Starts an element which defines a link.void
link(java.lang.String name, SinkEventAttributes attributes)
Starts a link.protected void
newline()
Writes EOL.protected void
pdfBookmarks()
Writes a fo:bookmark-tree.protected void
regionAfter(java.lang.String footerText)
Writes a 'xsl-region-after' block.protected void
regionBefore(java.lang.String headerText)
Writes a 'xsl-region-before' block.private void
renderBookmarkItems(java.util.List<DocumentTOCItem> items)
private java.lang.String
resolveLinkRelativeToBase(java.lang.String name)
void
setDocumentModel(DocumentModel model)
Sets the DocumentModel to be used by this sink.void
setDocumentModel(DocumentModel model, int tocPos)
Sets the DocumentModel to be used by this sink.void
setDocumentName(java.lang.String name)
Sets the name of the current source document, relative to the source root.void
setDocumentTitle(java.lang.String title)
Sets the title of the current document.protected void
startPageSequence(java.lang.String headerText, java.lang.String footerText)
Starts a page sequence, depending on the current chapter.void
title()
Starts the title element.void
title(SinkEventAttributes attributes)
Starts the title element.void
title_()
Ends the title element.void
toc()
Writes a table of contents.protected void
write(java.lang.String text)
Write a text to the sink.private void
writeCoverBody(DocumentCover cover, DocumentMeta meta)
private void
writeCoverFooter(DocumentCover cover, DocumentMeta meta)
private void
writeCoverHead(DocumentCover cover)
protected void
writeEmptyTag(javax.swing.text.html.HTML.Tag tag, java.lang.String attributeId)
Writes a simple tag, appending EOL.protected void
writeEndTag(javax.swing.text.html.HTML.Tag t)
Ends a Tag without writing an EOL.protected void
writeln(java.lang.String text)
Writes a text, appending EOL.protected void
writeStartTag(javax.swing.text.html.HTML.Tag tag, java.lang.String attributeId)
Writes a start tag, prepending EOL.protected void
writeStartTag(javax.swing.text.html.HTML.Tag tag, java.lang.String id, java.lang.String name)
Writes a start tag, prepending EOL.private void
writeTocItems(java.util.List<DocumentTOCItem> tocItems, int level)
-
Methods inherited from class org.apache.maven.doxia.module.fo.FoSink
anchor_, beginDocument, bold, bold_, close, comment, definedTerm, definedTerm, definedTerm_, definition, definition, definition_, definitionList, definitionList, definitionList_, definitionListItem, definitionListItem, definitionListItem_, endDocument, escaped, figure, figure, figure_, figureCaption, figureCaption, figureCaption_, flush, getFoConfiguration, horizontalRule, horizontalRule, init, inline, inline, inline_, isFigure, italic, italic_, lineBreak, lineBreak, link_, list, list, list_, listItem, listItem, listItem_, load, logMessage, monospaced, monospaced_, nonBreakingSpace, numberedList, numberedList, numberedList_, numberedListItem, numberedListItem, numberedListItem_, pageBreak, paragraph, paragraph, paragraph_, rawText, resetSectionCounter, section, section_, section1, section1_, section2, section2_, section3, section3_, section4, section4_, section5, section5_, sectionTitle, sectionTitle, sectionTitle_, sectionTitle_, sectionTitle1, sectionTitle1_, sectionTitle2, sectionTitle2_, sectionTitle3, sectionTitle3_, sectionTitle4, sectionTitle4_, sectionTitle5, sectionTitle5_, startPageSequence, table, table, table_, tableCaption, tableCaption, tableCaption_, tableCell, tableCell, tableCell, tableCell_, tableHeaderCell, tableHeaderCell, tableHeaderCell, tableHeaderCell_, tableRow, tableRow, tableRow_, tableRows, tableRows_, text, text, unknown, verbatim, verbatim, verbatim_, writeEmptyTag, writeStartTag, writeStartTag
-
Methods inherited from class org.apache.maven.doxia.sink.impl.AbstractXmlSink
getNameSpace, setInsertNewline, setNameSpace, writeEOL, writeSimpleTag, writeSimpleTag, writeStartTag, writeStartTag
-
Methods inherited from class org.apache.maven.doxia.sink.impl.SinkAdapter
address, address, address_, article, article, article_, blockquote, blockquote, blockquote_, content, content, content_, data, data, data_, division, division, division_, footer, footer, footer_, header, header, header_, lineBreakOpportunity, lineBreakOpportunity, navigation, navigation, navigation_, section6, section6_, sectionTitle6, sectionTitle6_, sidebar, sidebar, sidebar_, time, time, time_
-
Methods inherited from class org.apache.maven.doxia.sink.impl.AbstractSink
enableLogging, getLog, unifyEOLs
-
-
-
-
Field Detail
-
TOC_NONE
public static final int TOC_NONE
No Table Of Content.
-
TOC_START
public static final int TOC_START
Table Of Content at the start of the document.
-
TOC_END
public static final int TOC_END
Table Of Content at the end of the document.
-
COVER_HEADER_HEIGHT
private static final java.lang.String COVER_HEADER_HEIGHT
- See Also:
- Constant Field Values
-
docModel
private DocumentModel docModel
The document model to be used by this sink.
-
chapter
private int chapter
Counts the current chapter level.
-
docName
private java.lang.String docName
Name of the source file of the current document, relative to the source root.
-
docTitle
private java.lang.String docTitle
Title of the chapter, used in the page header.
-
ignoreText
private boolean ignoreText
Content in head is ignored in aggregated documents.
-
tocPosition
private int tocPosition
Current position of the TOC, see#TOC_POSITION
-
tocStack
private final java.util.Stack<NumberedListItem> tocStack
Used to get the current position in the TOC.
-
-
Method Detail
-
head
public void head()
Starts the head element.- Specified by:
head
in interfaceSink
- Overrides:
head
in classFoSink
- See Also:
Sink.head(SinkEventAttributes)
-
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 interfaceSink
- Overrides:
head
in classFoSink
- Parameters:
attributes
- A set ofSinkEventAttributes
, may benull
.
-
head_
public void head_()
Ends the head element.
-
title
public void title()
Starts the title element.- Specified by:
title
in interfaceSink
- Overrides:
title
in classFoSink
- See Also:
Sink.title(SinkEventAttributes)
-
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 interfaceSink
- Overrides:
title
in classFoSink
- Parameters:
attributes
- A set ofSinkEventAttributes
, may benull
.- See Also:
Sink.head(SinkEventAttributes)
-
title_
public void title_()
Ends the title element.
-
author
public void author()
Starts an author element.- Specified by:
author
in interfaceSink
- Overrides:
author
in classFoSink
- See Also:
Sink.author(SinkEventAttributes)
-
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 interfaceSink
- Overrides:
author
in classFoSink
- Parameters:
attributes
- A set ofSinkEventAttributes
, may benull
.- See Also:
Sink.head(SinkEventAttributes)
-
author_
public void author_()
Ends an author element.
-
date
public void date()
Starts the date element.- Specified by:
date
in interfaceSink
- Overrides:
date
in classFoSink
- See Also:
Sink.date(SinkEventAttributes)
-
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
whereYYYY
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 interfaceSink
- Overrides:
date
in classFoSink
- Parameters:
attributes
- A set ofSinkEventAttributes
, may benull
.- See Also:
Sink.head(SinkEventAttributes)
-
date_
public void date_()
Ends the date element.
-
body
public void body()
Starts the body of a document.- Specified by:
body
in interfaceSink
- Overrides:
body
in classFoSink
- See Also:
Sink.body(SinkEventAttributes)
-
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 interfaceSink
- Overrides:
body
in classFoSink
- Parameters:
attributes
- A set ofSinkEventAttributes
, may benull
.- See Also:
Sink.head(SinkEventAttributes)
-
body_
public void body_()
Ends the body element.
-
setDocumentTitle
public void setDocumentTitle(java.lang.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(java.lang.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(DocumentModel, int)
,TOC_START
-
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.
-
getIdName
private java.lang.String getIdName(java.lang.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(java.lang.String name)
Adding a source of a graphic.- Specified by:
figureGraphics
in interfaceSink
- Overrides:
figureGraphics
in classFoSink
- Parameters:
name
- the source
-
figureGraphics
public void figureGraphics(java.lang.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 thesrc
parameter.- Specified by:
figureGraphics
in interfaceSink
- Overrides:
figureGraphics
in classFoSink
- Parameters:
src
- the image source, a valid URL.attributes
- A set ofSinkEventAttributes
, may benull
.- See Also:
Sink.figure(SinkEventAttributes)
-
anchor
public void anchor(java.lang.String name)
Starts an element which defines an anchor.- Specified by:
anchor
in interfaceSink
- Overrides:
anchor
in classFoSink
- Parameters:
name
- the name of the anchor.- See Also:
Sink.anchor(String,SinkEventAttributes)
-
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
. IfNAME
is specified in the SinkEventAttributes, it will be overwritten by thename
parameter.- Specified by:
anchor
in interfaceSink
- Overrides:
anchor
in classFoSink
- Parameters:
name
- the name of the anchor. This has to be a valid SGML NAME token.attributes
- A set ofSinkEventAttributes
, may benull
.
-
link
public void link(java.lang.String name)
Starts an element which defines a link.- Specified by:
link
in interfaceSink
- Overrides:
link
in classFoSink
- Parameters:
name
- the name of the link.- See Also:
Sink.link(String,SinkEventAttributes)
-
link
public void link(java.lang.String name, SinkEventAttributes attributes)
Starts a link.The
name
parameter has to be a valid htmlhref
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 thename
parameter.- Specified by:
link
in interfaceSink
- Overrides:
link
in classFoSink
- Parameters:
name
- the name of the link.attributes
- A set ofSinkEventAttributes
, may benull
.
-
resolveLinkRelativeToBase
private java.lang.String resolveLinkRelativeToBase(java.lang.String name)
-
chopExtension
private java.lang.String chopExtension(java.lang.String name)
-
writeStartTag
protected void writeStartTag(javax.swing.text.html.HTML.Tag tag, java.lang.String attributeId)
Writes a start tag, prepending EOL.- Overrides:
writeStartTag
in classFoSink
- Parameters:
tag
- The tag.attributeId
- An id identifying the attribute set.
-
writeStartTag
protected void writeStartTag(javax.swing.text.html.HTML.Tag tag, java.lang.String id, java.lang.String name)
Writes a start tag, prepending EOL.- Overrides:
writeStartTag
in classFoSink
- Parameters:
tag
- The tag.id
- An id to add.name
- The name (value) of the id.
-
writeEndTag
protected void writeEndTag(javax.swing.text.html.HTML.Tag t)
Ends a Tag without writing an EOL. For instance:</tag>
.- Overrides:
writeEndTag
in classFoSink
- Parameters:
t
- aHTML.Tag
object.
-
writeEmptyTag
protected void writeEmptyTag(javax.swing.text.html.HTML.Tag tag, java.lang.String attributeId)
Writes a simple tag, appending EOL.- Overrides:
writeEmptyTag
in classFoSink
- Parameters:
tag
- The tag name.attributeId
- An id identifying the attribute set.
-
write
protected void write(java.lang.String text)
Write a text to the sink. Writes a text, swallowing any exceptions.
-
writeln
protected void writeln(java.lang.String text)
Writes a text, appending EOL.
-
content
protected void content(java.lang.String text)
Writes content, escaping special characters.
-
newline
protected void newline()
Writes EOL.
-
startPageSequence
protected void startPageSequence(java.lang.String headerText, java.lang.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 java.lang.String getHeaderText()
Returns the text to write in the header of each page.- Returns:
- String
-
getFooterText
protected java.lang.String getFooterText()
Returns the text to write in the footer of each page.- Returns:
- String
-
getChapterString
protected java.lang.String getChapterString()
Returns the current chapter number as a string. By default does nothing, gets overridden by AggregateSink.- Overrides:
getChapterString
in classFoSink
- Returns:
- an empty String.
-
regionBefore
protected void regionBefore(java.lang.String headerText)
Writes a 'xsl-region-before' block.- Overrides:
regionBefore
in classFoSink
- Parameters:
headerText
- The text to write in the header, if null, nothing is written.
-
regionAfter
protected void regionAfter(java.lang.String footerText)
Writes a 'xsl-region-after' block. By default does nothing, gets overridden by AggregateSink.- Overrides:
regionAfter
in classFoSink
- Parameters:
footerText
- The text to write in the footer, if null, nothing is written.
-
chapterHeading
protected void chapterHeading(java.lang.String headerText, boolean chapterNumber)
Writes a chapter heading. By default does nothing, gets overridden by AggregateSink.- Overrides:
chapterHeading
in classFoSink
- 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(java.util.List<DocumentTOCItem> tocItems, int level)
-
currentTocNumber
private java.lang.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 classFoSink
-
renderBookmarkItems
private void renderBookmarkItems(java.util.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 java.util.ResourceBundle getBundle(java.util.Locale locale)
-
getGraphicsAttributes
private SinkEventAttributeSet getGraphicsAttributes(java.lang.String logo)
-
-