public class HtmlDocumentBuilder extends AbstractXmlDocumentBuilder
Modifier and Type | Class and Description |
---|---|
static class |
HtmlDocumentBuilder.Stylesheet
A CSS stylesheet definition, created via one of
addCssStylesheet(File) or
addCssStylesheet(String) . |
DocumentBuilder.BlockType, DocumentBuilder.SpanType
base, baseInHead, writer
locator
Constructor and Description |
---|
HtmlDocumentBuilder(java.io.Writer out)
construct the HtmlDocumentBuilder.
|
HtmlDocumentBuilder(java.io.Writer out,
boolean formatting)
construct the HtmlDocumentBuilder.
|
HtmlDocumentBuilder(XmlStreamWriter writer)
construct the HtmlDocumentBuilder.
|
Modifier and Type | Method and Description |
---|---|
void |
acronym(java.lang.String text,
java.lang.String definition)
Emit an acronym
|
void |
addCssStylesheet(java.io.File file)
Deprecated.
use
addCssStylesheet(Stylesheet) instead |
void |
addCssStylesheet(HtmlDocumentBuilder.Stylesheet stylesheet)
Add a CSS stylesheet to the output document.
|
void |
addCssStylesheet(java.lang.String url)
Deprecated.
use
addCssStylesheet(Stylesheet) instead |
void |
beginBlock(DocumentBuilder.BlockType type,
Attributes attributes)
Begin a block of the specified type.
|
protected void |
beginBody()
begin the body by emitting the body element.
|
void |
beginDocument()
Begin a document.
|
void |
beginHeading(int level,
Attributes attributes)
Begin a heading of the specified level (usually 1-6).
|
void |
beginSpan(DocumentBuilder.SpanType type,
Attributes attributes)
Begin a span of the specified type.
|
void |
charactersUnescaped(java.lang.String literal)
Create unescaped characters, usually with some embedded HTML markup.
|
protected void |
checkFileReadable(java.io.File file) |
void |
copyConfiguration(HtmlDocumentBuilder other)
Copy the configuration of this builder to the provided one.
|
protected static XmlStreamWriter |
createFormattingXmlStreamWriter(java.io.Writer out) |
protected void |
emitAnchorHref(java.lang.String href)
emit the href attribute of an anchor.
|
protected void |
emitHead()
Emit the HTML head, including the head tag itself.
|
protected void |
emitHeadContents()
emit the contents of the HTML head, excluding the head tag itself.
|
void |
endBlock()
End a block that was
started . |
protected void |
endBody()
end the body by emitting the body end element tag.
|
void |
endDocument()
End a document.
|
void |
endHeading()
End a span that was
started . |
void |
endSpan()
End a span that was
started . |
void |
entityReference(java.lang.String entity)
An XML entity reference.
|
java.lang.String |
getCopyrightNotice()
the copyright notice that should appear in the generated output
|
java.lang.String |
getDefaultAbsoluteLinkTarget()
A default target attribute for links that have absolute (not relative) urls.
|
java.lang.String |
getEncoding()
Specify the character encoding for use in the HTML meta tag.
|
java.lang.String |
getHtmlDtd()
The DTD to emit, if
isEmitDtd() and isEmitAsDocument() . |
java.lang.String |
getHtmlFilenameFormat()
Provides the HTML filename format which is used to rewrite relative URLs having no filename extension.
|
java.lang.String |
getHtmlNsUri()
The XML Namespace URI of the HTML elements, only used if
isEmitAsDocument() . |
java.lang.String |
getLinkRel()
The 'rel' value for HTML links.
|
java.lang.String |
getPrependImagePrefix()
if specified, the prefix is prepended to relative image urls.
|
protected java.io.Reader |
getReader(java.io.File inputFile) |
java.lang.String |
getTitle()
Set the document title, which will be emitted into the <title> element.
|
void |
horizontalRule()
Create a horizontal rule (eg: hr in html).
|
void |
image(Attributes attributes,
java.lang.String url)
Build the image with the given attributes
|
void |
imageLink(Attributes linkAttributes,
Attributes imageAttributes,
java.lang.String href,
java.lang.String imageUrl)
Create a hyperlink whose visual representation is an image.
|
boolean |
isEmitAsDocument()
Indicate if the resulting HTML should be emitted as a document.
|
boolean |
isEmitDtd()
Indicate if the resulting HTML should include a DTD.
|
boolean |
isFilterEntityReferences()
Indicates that
entity references should be filtered. |
boolean |
isSuppressBuiltInStyles()
indicate if default built-in CSS styles should be suppressed.
|
boolean |
isUseInlineStyles()
Indicate if inline styles should be used when creating output such as text boxes.
|
boolean |
isXhtmlStrict()
indicate if the builder should attempt to conform to strict XHTML rules.
|
void |
lineBreak()
Create a line break (eg: br in html).
|
void |
link(Attributes attributes,
java.lang.String hrefOrHashName,
java.lang.String text)
Create a hyperlink to the given url.
|
void |
setCopyrightNotice(java.lang.String copyrightNotice)
the copyright notice that should appear in the generated output
|
void |
setDefaultAbsoluteLinkTarget(java.lang.String defaultAbsoluteLinkTarget)
A default target attribute for links that have absolute (not relative) urls.
|
void |
setDocumentHandler(HtmlDocumentHandler documentHandler)
Provides an
HtmlDocumentHandler for this builder. |
void |
setEmitAsDocument(boolean emitAsDocument)
Indicate if the resulting HTML should be emitted as a document.
|
void |
setEmitDtd(boolean emitDtd)
Indicate if the resulting HTML should include a DTD.
|
void |
setEncoding(java.lang.String encoding)
Specify the character encoding for use in the HTML meta tag.
|
void |
setFilterEntityReferences(boolean filterEntityReferences)
Indicates that
entity references should be filtered. |
void |
setHtmlDtd(java.lang.String htmlDtd)
The DTD to emit, if
isEmitDtd() and isEmitAsDocument() . |
void |
setHtmlFilenameFormat(java.lang.String htmlFilenameFormat)
Sets the HTML filename format which is used to rewrite relative URLs having no filename extension.
|
void |
setHtmlNsUri(java.lang.String htmlNsUri)
The XML Namespace URI of the HTML elements, only used if
isEmitAsDocument() . |
void |
setLinkRel(java.lang.String linkRel)
The 'rel' value for HTML links.
|
void |
setPrependImagePrefix(java.lang.String prependImagePrefix)
if specified, the prefix is prepended to relative image urls.
|
void |
setSuppressBuiltInStyles(boolean suppressBuiltInStyles)
indicate if default built-in CSS styles should be suppressed.
|
void |
setTitle(java.lang.String title)
Set the document title, which will be emitted into the <title> element.
|
void |
setUseInlineStyles(boolean useInlineStyles)
Indicate if inline styles should be used when creating output such as text boxes.
|
void |
setXhtmlStrict(boolean xhtmlStrict)
indicate if the builder should attempt to conform to strict XHTML rules.
|
characters, createXmlStreamWriter, flush, getBase, getWriter, isBaseInHead, isExternalLink, makeUrlAbsolute, setBase, setBaseInHead
getLocator, imageLink, imageLink, link, setLocator
public HtmlDocumentBuilder(java.io.Writer out)
out
- the writer to which content is writtenpublic HtmlDocumentBuilder(java.io.Writer out, boolean formatting)
out
- the writer to which content is writtenformatting
- indicate if the output should be formattedpublic HtmlDocumentBuilder(XmlStreamWriter writer)
writer
- the writer to which content is writtenpublic void copyConfiguration(HtmlDocumentBuilder other)
other
- the builder to which settings are copied.protected static XmlStreamWriter createFormattingXmlStreamWriter(java.io.Writer out)
public java.lang.String getHtmlNsUri()
isEmitAsDocument()
. The default value is "
http://www.w3.org/1999/xhtml
".public void setHtmlNsUri(java.lang.String htmlNsUri)
isEmitAsDocument()
. The default value is "
http://www.w3.org/1999/xhtml
".public java.lang.String getHtmlDtd()
isEmitDtd()
and isEmitAsDocument()
. The default value is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
public void setHtmlDtd(java.lang.String htmlDtd)
isEmitDtd()
and isEmitAsDocument()
.getHtmlDtd()
public boolean isEmitAsDocument()
public void setEmitAsDocument(boolean emitAsDocument)
public boolean isEmitDtd()
isEmitAsDocument()
. Default value is
false.public void setEmitDtd(boolean emitDtd)
isEmitAsDocument()
. Default value is
false.public java.lang.String getEncoding()
"utf-8"
: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
The
default is "utf-8"
. Ignored unless isEmitAsDocument()
public void setEncoding(java.lang.String encoding)
"utf-8"
: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
The
default is "utf-8"
.encoding
- the character encoding to use, or null if the HTML meta tag should not be emitted Ignored unless
isEmitAsDocument()
public java.lang.String getTitle()
isEmitAsDocument()
public void setTitle(java.lang.String title)
isEmitAsDocument()
title
- the title or null if there is nonepublic java.lang.String getDefaultAbsoluteLinkTarget()
LinkAttributes
.public void setDefaultAbsoluteLinkTarget(java.lang.String defaultAbsoluteLinkTarget)
LinkAttributes
.public boolean isXhtmlStrict()
public void setXhtmlStrict(boolean xhtmlStrict)
@Deprecated public void addCssStylesheet(java.lang.String url)
addCssStylesheet(Stylesheet)
insteadstarting the document
has no effect. Generates code similar to
the following:
<link type="text/css" rel="stylesheet" href="url"/>
url
- the CSS url to use, which may be relative or absoluteaddCssStylesheet(File)
@Deprecated public void addCssStylesheet(java.io.File file)
addCssStylesheet(Stylesheet)
insteadstarting the document
has no effect. Generates code similar to
the following:
<code> <style type="text/css"> ... contents of the file ... </style> </code>
file
- the CSS file whose contents must be availableaddCssStylesheet(String)
public void addCssStylesheet(HtmlDocumentBuilder.Stylesheet stylesheet)
starting the
document
has no effect.protected void checkFileReadable(java.io.File file)
public boolean isUseInlineStyles()
isEmitAsDocument()
is false, this option has the same effect as
isSuppressBuiltInStyles()
. The default is true.isSuppressBuiltInStyles()
public void setUseInlineStyles(boolean useInlineStyles)
isEmitAsDocument()
is false, this option has the same effect as
isSuppressBuiltInStyles()
. The default is true.public boolean isSuppressBuiltInStyles()
isUseInlineStyles()
public void setSuppressBuiltInStyles(boolean suppressBuiltInStyles)
public java.lang.String getLinkRel()
LinkAttributes.getRel()
public void setLinkRel(java.lang.String linkRel)
linkRel
- the rel or null if there is none.LinkAttributes.getRel()
public void setDocumentHandler(HtmlDocumentHandler documentHandler)
HtmlDocumentHandler
for this builder.documentHandler
- the document handlerHtmlDocumentHandler
public void beginDocument()
DocumentBuilder
DocumentBuilder.endDocument()
.beginDocument
in class DocumentBuilder
DocumentBuilder.endDocument()
protected void emitHead()
emitHeadContents()
protected void emitHeadContents()
super.emitHeadContents()
in order to preserve
features such as emitting the base, title and stylesheets.emitHead()
public void endDocument()
DocumentBuilder
endDocument
in class DocumentBuilder
DocumentBuilder.beginDocument()
,
DocumentBuilder.flush()
protected void beginBody()
super.beginBody()
.endBody()
protected void endBody()
super.endBody()
.beginBody()
public void entityReference(java.lang.String entity)
DocumentBuilder
entityReference
in class DocumentBuilder
entity
- the entitypublic void acronym(java.lang.String text, java.lang.String definition)
DocumentBuilder
acronym
in class DocumentBuilder
text
- the acronym to emitdefinition
- the definition of the acronym, which is typically displayed on mouse hoverpublic void link(Attributes attributes, java.lang.String hrefOrHashName, java.lang.String text)
DocumentBuilder
LinkAttributes
are used, the attributes must not have the
href
attribute set.link
in class DocumentBuilder
attributes
- the attributes of the linkhrefOrHashName
- the url (which may be internal to the page if prefixed with a hash '#')text
- the text of the hyperlinkpublic void beginBlock(DocumentBuilder.BlockType type, Attributes attributes)
DocumentBuilder
Attributes
class, in which case
the builder may attempt to apply the attributes specified. Builders may choose to ignore attributes, and should
fail silently if the given attributes are not as expected. Each call to this method must be matched by a
corresponding call to DocumentBuilder.endBlock()
.beginBlock
in class DocumentBuilder
attributes
- the attributes to apply to the block. Callers may choose to specify a more specialized set of
attributes by providing a subclass instance.DocumentBuilder.endBlock()
public void beginHeading(int level, Attributes attributes)
DocumentBuilder
DocumentBuilder.endHeading()
.beginHeading
in class DocumentBuilder
level
- the level of the heading, usually 1-6attributes
- the attributes to apply to the headingDocumentBuilder.endHeading()
public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
DocumentBuilder
DocumentBuilder.endSpan()
.beginSpan
in class DocumentBuilder
attributes
- the attributes to apply to the spanDocumentBuilder.endSpan()
public void endBlock()
DocumentBuilder
started
.endBlock
in class DocumentBuilder
public void endHeading()
DocumentBuilder
started
.endHeading
in class DocumentBuilder
DocumentBuilder.beginHeading(int, Attributes)
public void endSpan()
DocumentBuilder
started
.endSpan
in class DocumentBuilder
#beginSpan(org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType, Attributes)
public void image(Attributes attributes, java.lang.String url)
DocumentBuilder
image
in class DocumentBuilder
attributes
- the attributes, which may be an ImageAttributes
.url
- the URL to the image, possibly relativepublic void imageLink(Attributes linkAttributes, Attributes imageAttributes, java.lang.String href, java.lang.String imageUrl)
DocumentBuilder
<a href="..."><img src="..."/></a>
. In this case if the attributes define a css class then
the resulting HTML should look like this: <a href="..."><img src="..." class="..."/></a>
imageLink
in class DocumentBuilder
linkAttributes
- the attributes of the link, which may be LinkAttributes
imageAttributes
- the attributes of the image , which may be ImageAttributes
href
- the url (which may be internal to the page if prefixed with a hash '#')imageUrl
- the url of the image, which may be relativeprotected void emitAnchorHref(java.lang.String href)
onclick
. Overriding classes should pass the href to
AbstractXmlDocumentBuilder.makeUrlAbsolute(String)
prior to writing it to the writer.href
- the url for the href attributegetHtmlFilenameFormat()
public java.lang.String getHtmlFilenameFormat()
null
.null
setHtmlFilenameFormat(String)
public void setHtmlFilenameFormat(java.lang.String htmlFilenameFormat)
null
.htmlFilenameFormat
- the HTML filename format or null
getHtmlFilenameFormat()
public void lineBreak()
DocumentBuilder
lineBreak
in class DocumentBuilder
public void horizontalRule()
DocumentBuilder
horizontalRule
in class DocumentBuilder
public void charactersUnescaped(java.lang.String literal)
DocumentBuilder
charactersUnescaped
in class DocumentBuilder
literal
- the literal characters to emitprotected java.io.Reader getReader(java.io.File inputFile) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public void setPrependImagePrefix(java.lang.String prependImagePrefix)
public java.lang.String getPrependImagePrefix()
public boolean isFilterEntityReferences()
entity references
should be filtered. Defaults to false. When
filtered, known HTML entity references are converted to their numeric counterpart, and unknown entity references
are emitted as plain text.public void setFilterEntityReferences(boolean filterEntityReferences)
entity references
should be filtered. Defaults to false. When
filtered, known HTML entity references are converted to their numeric counterpart, and unknown entity references
are emitted as plain text.public java.lang.String getCopyrightNotice()
public void setCopyrightNotice(java.lang.String copyrightNotice)
copyrightNotice
- the notice, or null if there should be noneCopyright © 2007, 2013 David Green and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html