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 booleanacceptUnknownprivate booleanautoBookmarkstatic java.lang.StringBOOKMARK_TREEKey for the memory, used to store bookmark nodesprivate java.nio.charset.Charsetcharsetprivate CssApplierscssAppliersprivate java.util.List<Element>ctnprivate ImageProviderimageProviderstatic java.lang.StringLAST_MARGIN_BOTTOMKey for the memory, used in Html TagProcessingprivate LinkProviderlinkproviderprivate java.util.Map<java.lang.String,java.lang.Object>memoryprivate RectanglepageSizeprivate java.util.LinkedList<StackKeeper>queueprivate java.lang.StringresourcesRootPathprivate java.util.List<java.lang.String>roottagsprivate TagProcessorFactorytagFactory
-
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 booleanacceptUnknown()protected voidaddFirst(StackKeeper stackKeeper)Add aStackKeeperto the top of the stack list.booleanautoBookmark()HtmlPipelineContextautoBookmark(boolean autoBookmark)Set to true to enable the automatic creation of bookmarks on <h1> to <h6> tags.java.nio.charset.CharsetcharSet()HtmlPipelineContextcharSet(java.nio.charset.Charset cSet)Set aCharsetto use.HtmlPipelineContextclone()Create a clone of this HtmlPipelineContext, the clone only contains the initial values, not the internal values.protected java.util.List<Element>currentContent()CssAppliersgetCssAppliers()ImageProvidergetImageProvider()java.lang.FloatgetLastMarginBottom()LinkProvidergetLinkProvider()Returns the LinkProvider, used to prepend e.g.java.util.Map<java.lang.String,java.lang.Object>getMemory()RectanglegetPageSize()Returns aRectanglejava.lang.StringgetResourcesRootPath()java.util.List<java.lang.String>getRootTags()protected booleanisEmpty()protected StackKeeperpeek()Retrieves, but does not remove, the head (first element) of this list.protected StackKeeperpoll()Retrieves and removes the top of the stack.protected TagProcessorresolveProcessor(java.lang.String tag, java.lang.String nameSpace)HtmlPipelineContextsetAcceptUnknown(boolean acceptUnknown)Set to true to allow the HtmlPipeline to accept tags it does not find in the givenTagProcessorFactoryHtmlPipelineContextsetCssApplier(CssAppliers cssAppliers)Fluent variant ofsetCssAppliers(CssAppliers)voidsetCssAppliers(CssAppliers cssAppliers)HtmlPipelineContextsetImageProvider(ImageProvider imageProvider)An ImageProvider can be provided and works in conjunction withImageandListStyleTypeCssApplierfor List Images.voidsetLastMarginBottom(java.lang.Float lmb)Set the last margin bottom.HtmlPipelineContextsetLinkProvider(LinkProvider linkprovider)Set the LinkProvider to use if any.HtmlPipelineContextsetPageSize(Rectangle pageSize)If no pageSize is set, the default value A4 is used.voidsetResourcesRootPath(java.lang.String resourcesRootPath)HtmlPipelineContextsetRootTags(java.util.List<java.lang.String> roottags)Set the root-tags, this matters for margins.HtmlPipelineContextsetTagFactory(TagProcessorFactory tagFactory)Set theTagProcessorFactoryto 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 aStackKeeperto 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 aCharsetto use.- Parameters:
cSet- the charset.- Returns:
- this
HtmlPipelineContext
-
charSet
public java.nio.charset.Charset charSet()
- Returns:
- the
Charsetto use, or null if none configured.
-
getPageSize
public Rectangle getPageSize()
Returns aRectangle- Specified by:
getPageSizein interfacePageSizeContainable- Returns:
- the pagesize.
-
getRootTags
public java.util.List<java.lang.String> getRootTags()
- Specified by:
getRootTagsin 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 (newAbstractImageProviderwith same ImageRootPath) , TagProcessorFactory (same object), acceptUnknown (primitive), charset (Charset.forName to get a new charset), autobookmark (primitive) are copied.- Overrides:
clonein 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 theTagProcessorFactoryto be used. For HTML useTags.getHtmlTagProcessorFactory()- Parameters:
tagFactory- theTagProcessorFactorythat 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 withImageandListStyleTypeCssApplierfor List Images.- Parameters:
imageProvider- theImageProviderto 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:
getLastMarginBottomin interfaceMarginMemory- Returns:
- a Float
- Throws:
NoDataException- if there is no LastMarginBottom set
-
setLastMarginBottom
public void setLastMarginBottom(java.lang.Float lmb)
Description copied from interface:MarginMemorySet the last margin bottom.- Specified by:
setLastMarginBottomin interfaceMarginMemory- Parameters:
lmb- set the float for lmb
-
setCssAppliers
public void setCssAppliers(CssAppliers cssAppliers)
- Specified by:
setCssAppliersin interfaceCssAppliersAware- Parameters:
cssAppliers- the CssAppliers
-
getCssAppliers
public CssAppliers getCssAppliers()
- Specified by:
getCssAppliersin 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)
-
-