Class HtmlPipelineContext
- java.lang.Object
-
- com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext
-
- All Implemented Interfaces:
MarginMemory
,PageSizeContainable
,CustomContext
,CssAppliersAware
,java.lang.Cloneable
public class HtmlPipelineContext extends java.lang.Object implements CustomContext, java.lang.Cloneable, MarginMemory, PageSizeContainable, CssAppliersAware
The CustomContext object for the HtmlPipeline.
Use this to configure yourHtmlPipeline
.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
acceptUnknown
private boolean
autoBookmark
static java.lang.String
BOOKMARK_TREE
Key for the memory, used to store bookmark nodesprivate java.nio.charset.Charset
charset
private CssAppliers
cssAppliers
private java.util.List<Element>
ctn
private ImageProvider
imageProvider
static java.lang.String
LAST_MARGIN_BOTTOM
Key for the memory, used in Html TagProcessingprivate LinkProvider
linkprovider
private java.util.Map<java.lang.String,java.lang.Object>
memory
private Rectangle
pageSize
private java.util.LinkedList<StackKeeper>
queue
private java.lang.String
resourcesRootPath
private java.util.List<java.lang.String>
roottags
private TagProcessorFactory
tagFactory
-
Constructor Summary
Constructors Constructor Description HtmlPipelineContext(CssAppliers cssAppliers)
Construct a new HtmlPipelineContext object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptUnknown()
protected void
addFirst(StackKeeper stackKeeper)
Add aStackKeeper
to the top of the stack list.boolean
autoBookmark()
HtmlPipelineContext
autoBookmark(boolean autoBookmark)
Set to true to enable the automatic creation of bookmarks on <h1> to <h6> tags.java.nio.charset.Charset
charSet()
HtmlPipelineContext
charSet(java.nio.charset.Charset cSet)
Set aCharset
to use.HtmlPipelineContext
clone()
Create a clone of this HtmlPipelineContext, the clone only contains the initial values, not the internal values.protected java.util.List<Element>
currentContent()
CssAppliers
getCssAppliers()
ImageProvider
getImageProvider()
java.lang.Float
getLastMarginBottom()
LinkProvider
getLinkProvider()
Returns the LinkProvider, used to prepend e.g.java.util.Map<java.lang.String,java.lang.Object>
getMemory()
Rectangle
getPageSize()
Returns aRectangle
java.lang.String
getResourcesRootPath()
java.util.List<java.lang.String>
getRootTags()
protected boolean
isEmpty()
protected StackKeeper
peek()
Retrieves, but does not remove, the head (first element) of this list.protected StackKeeper
poll()
Retrieves and removes the top of the stack.protected TagProcessor
resolveProcessor(java.lang.String tag, java.lang.String nameSpace)
HtmlPipelineContext
setAcceptUnknown(boolean acceptUnknown)
Set to true to allow the HtmlPipeline to accept tags it does not find in the givenTagProcessorFactory
HtmlPipelineContext
setCssApplier(CssAppliers cssAppliers)
Fluent variant ofsetCssAppliers(CssAppliers)
void
setCssAppliers(CssAppliers cssAppliers)
HtmlPipelineContext
setImageProvider(ImageProvider imageProvider)
An ImageProvider can be provided and works in conjunction withImage
andListStyleTypeCssApplier
for List Images.void
setLastMarginBottom(java.lang.Float lmb)
Set the last margin bottom.HtmlPipelineContext
setLinkProvider(LinkProvider linkprovider)
Set the LinkProvider to use if any.HtmlPipelineContext
setPageSize(Rectangle pageSize)
If no pageSize is set, the default value A4 is used.void
setResourcesRootPath(java.lang.String resourcesRootPath)
HtmlPipelineContext
setRootTags(java.util.List<java.lang.String> roottags)
Set the root-tags, this matters for margins.HtmlPipelineContext
setTagFactory(TagProcessorFactory tagFactory)
Set theTagProcessorFactory
to be used.
-
-
-
Field Detail
-
BOOKMARK_TREE
public static final java.lang.String BOOKMARK_TREE
Key for the memory, used to store bookmark nodes- See Also:
- Constant Field Values
-
LAST_MARGIN_BOTTOM
public static final java.lang.String LAST_MARGIN_BOTTOM
Key for the memory, used in Html TagProcessing- See Also:
- Constant Field Values
-
queue
private final java.util.LinkedList<StackKeeper> queue
-
acceptUnknown
private boolean acceptUnknown
-
tagFactory
private TagProcessorFactory tagFactory
-
ctn
private final java.util.List<Element> ctn
-
imageProvider
private ImageProvider imageProvider
-
resourcesRootPath
private java.lang.String resourcesRootPath
-
pageSize
private Rectangle pageSize
-
charset
private java.nio.charset.Charset charset
-
roottags
private java.util.List<java.lang.String> roottags
-
linkprovider
private LinkProvider linkprovider
-
autoBookmark
private boolean autoBookmark
-
memory
private final java.util.Map<java.lang.String,java.lang.Object> memory
-
cssAppliers
private CssAppliers cssAppliers
-
-
Constructor Detail
-
HtmlPipelineContext
public HtmlPipelineContext(CssAppliers cssAppliers)
Construct a new HtmlPipelineContext object
-
-
Method Detail
-
resolveProcessor
protected TagProcessor resolveProcessor(java.lang.String tag, java.lang.String nameSpace)
- Parameters:
tag
- the tag to find a TagProcessor fornameSpace
- the namespace.- Returns:
- a TagProcessor
-
addFirst
protected void addFirst(StackKeeper stackKeeper)
Add aStackKeeper
to the top of the stack list.- Parameters:
stackKeeper
- theStackKeeper
-
peek
protected StackKeeper peek()
Retrieves, but does not remove, the head (first element) of this list.- Returns:
- a StackKeeper or null if there are no elements on the stack
-
currentContent
protected java.util.List<Element> currentContent()
- Returns:
- the current content of elements.
-
acceptUnknown
public boolean acceptUnknown()
- Returns:
- if this pipelines tag processing accept unknown tags: true. False otherwise
-
isEmpty
protected boolean isEmpty()
- Returns:
- returns true if the stack is empty
-
poll
protected StackKeeper poll() throws NoStackException
Retrieves and removes the top of the stack.- Returns:
- a StackKeeper
- Throws:
NoStackException
- if there are no elements on the stack
-
autoBookmark
public boolean autoBookmark()
- Returns:
- true if auto-bookmarks should be enabled. False otherwise.
-
getMemory
public java.util.Map<java.lang.String,java.lang.Object> getMemory()
- Returns:
- the memory
-
getImageProvider
public ImageProvider getImageProvider()
- Returns:
- the image provider or null if there is no
ImageProvider
.
-
charSet
@Experimental public HtmlPipelineContext charSet(java.nio.charset.Charset cSet)
Set aCharset
to use.- Parameters:
cSet
- the charset.- Returns:
- this
HtmlPipelineContext
-
charSet
public java.nio.charset.Charset charSet()
- Returns:
- the
Charset
to use, or null if none configured.
-
getPageSize
public Rectangle getPageSize()
Returns aRectangle
- Specified by:
getPageSize
in interfacePageSizeContainable
- Returns:
- the pagesize.
-
getRootTags
public java.util.List<java.lang.String> getRootTags()
- Specified by:
getRootTags
in interfaceMarginMemory
- Returns:
- a list of tags to be taken as root-tags. This matters for margins. By default the root-tags are <body> and <div>
-
getLinkProvider
public LinkProvider getLinkProvider()
Returns the LinkProvider, used to prepend e.g. http://www.example.org/ to found <a> tags that have no absolute url.- Returns:
- the LinkProvider if any.
-
setPageSize
public HtmlPipelineContext setPageSize(Rectangle pageSize)
If no pageSize is set, the default value A4 is used.- Parameters:
pageSize
- the pageSize to set- Returns:
- this
HtmlPipelineContext
-
clone
public HtmlPipelineContext clone() throws java.lang.CloneNotSupportedException
Create a clone of this HtmlPipelineContext, the clone only contains the initial values, not the internal values. Beware, the state of the current Context is not copied to the clone. Only the configurational important stuff like the LinkProvider (same object), ImageProvider (newAbstractImageProvider
with same ImageRootPath) , TagProcessorFactory (same object), acceptUnknown (primitive), charset (Charset.forName to get a new charset), autobookmark (primitive) are copied.- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
setAcceptUnknown
public HtmlPipelineContext setAcceptUnknown(boolean acceptUnknown)
Set to true to allow the HtmlPipeline to accept tags it does not find in the givenTagProcessorFactory
- Parameters:
acceptUnknown
- true or false- Returns:
- this
HtmlPipelineContext
-
setTagFactory
public HtmlPipelineContext setTagFactory(TagProcessorFactory tagFactory)
Set theTagProcessorFactory
to be used. For HTML useTags.getHtmlTagProcessorFactory()
- Parameters:
tagFactory
- theTagProcessorFactory
that should be used- Returns:
- this
HtmlPipelineContext
-
autoBookmark
public HtmlPipelineContext autoBookmark(boolean autoBookmark)
Set to true to enable the automatic creation of bookmarks on <h1> to <h6> tags. Works in conjunction withHeader
.- Parameters:
autoBookmark
- true or false- Returns:
- this
HtmlPipelineContext
-
setRootTags
public HtmlPipelineContext setRootTags(java.util.List<java.lang.String> roottags)
Set the root-tags, this matters for margins. By default these are set to <body> and <div>.- Parameters:
roottags
- the root tags- Returns:
- this
HtmlPipelineContext
-
setImageProvider
public HtmlPipelineContext setImageProvider(ImageProvider imageProvider)
An ImageProvider can be provided and works in conjunction withImage
andListStyleTypeCssApplier
for List Images.- Parameters:
imageProvider
- theImageProvider
to use.- Returns:
- this
HtmlPipelineContext
-
setLinkProvider
public HtmlPipelineContext setLinkProvider(LinkProvider linkprovider)
Set the LinkProvider to use if any.- Parameters:
linkprovider
- the LinkProvider (@seegetLinkProvider()
- Returns:
- this
HtmlPipelineContext
-
getLastMarginBottom
public java.lang.Float getLastMarginBottom() throws NoDataException
- Specified by:
getLastMarginBottom
in interfaceMarginMemory
- Returns:
- a Float
- Throws:
NoDataException
- if there is no LastMarginBottom set
-
setLastMarginBottom
public void setLastMarginBottom(java.lang.Float lmb)
Description copied from interface:MarginMemory
Set the last margin bottom.- Specified by:
setLastMarginBottom
in interfaceMarginMemory
- Parameters:
lmb
- set the float for lmb
-
setCssAppliers
public void setCssAppliers(CssAppliers cssAppliers)
- Specified by:
setCssAppliers
in interfaceCssAppliersAware
- Parameters:
cssAppliers
- the CssAppliers
-
getCssAppliers
public CssAppliers getCssAppliers()
- Specified by:
getCssAppliers
in interfaceCssAppliersAware
- Returns:
- the CssAppliers
-
setCssApplier
public HtmlPipelineContext setCssApplier(CssAppliers cssAppliers)
Fluent variant ofsetCssAppliers(CssAppliers)
- Parameters:
cssAppliers
- the cssAppliers- Returns:
- this
-
getResourcesRootPath
public java.lang.String getResourcesRootPath()
-
setResourcesRootPath
public void setResourcesRootPath(java.lang.String resourcesRootPath)
-
-