Package com.itextpdf.tool.xml.html
Class AbstractTagProcessor
- java.lang.Object
-
- com.itextpdf.tool.xml.html.AbstractTagProcessor
-
- All Implemented Interfaces:
CssAppliersAware
,TagProcessor
- Direct Known Subclasses:
Anchor
,Body
,Break
,Div
,Header
,HorizontalRule
,Image
,Link
,Meta
,NonSanitizedTag
,OrderedUnorderedList
,OrderedUnorderedListItem
,ParaGraph
,Span
,Style
,Table
,TableData
,TableRow
,Title
,XML
public abstract class AbstractTagProcessor extends java.lang.Object implements TagProcessor, CssAppliersAware
Abstract TagProcessor that allows setting the configuration object to a protected member variable.
ImplementsTagProcessor.startElement(WorkerContext, Tag)
andTagProcessor.endElement(WorkerContext, Tag, List)
to calculate font sizes and add new pages if needed.
Extend from this class instead of implementingTagProcessor
to benefit from auto fontsize metric conversion to pt and page-break-before/after insertion. Overridestart(WorkerContext, Tag)
andend(WorkerContext, Tag, List)
in your extension.
-
-
Field Summary
Fields Modifier and Type Field Description private CssAppliers
cssAppliers
private FontSizeTranslator
fontsizeTrans
private java.util.Set<java.lang.String>
ignoreDirAttribute
For some tags, if they have their own not inherited DIR attribute, this attribute will definitely not be applied for itext layout.private java.util.List<Tag>
tree
-
Constructor Summary
Constructors Constructor Description AbstractTagProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Element>
content(WorkerContext ctx, Tag tag, java.lang.String content)
This method is called if there is text content encountered between the opening and closing tags this TagProcessor is mapped to.protected Paragraph
createParagraph()
java.util.List<Element>
currentContentToParagraph(java.util.List<Element> currentContent, boolean addNewLines)
Default apply CSS to false and tag to null.java.util.List<Element>
currentContentToParagraph(java.util.List<Element> currentContent, boolean addNewLines, boolean applyCSS, Tag tag, WorkerContext ctx)
Adds currentContent list to a paragraph element.protected void
doRtlIndentCorrections(Indentable p)
java.util.List<Element>
end(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List)
.java.util.List<Element>
endElement(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)
Checks forCSS.Property.PAGE_BREAK_AFTER
, if the value is always aChunk.NEXTPAGE
is added to the currentContentList after callingend(WorkerContext, Tag, List)
.CssAppliers
getCssAppliers()
CSSResolver
getCSSResolver(WorkerContext context)
Utility method that fetches the CSSResolver from the if any and if it uses the default key.HtmlPipelineContext
getHtmlPipelineContext(WorkerContext context)
Utility method that fetches the HtmlPipelineContext used if any and if it uses the default key.private java.lang.String
getParentDirection()
protected int
getRunDirection(Tag tag)
protected void
invertTextAlignForParagraph(Paragraph p)
protected void
invertTextAlignForParagraph(NoNewLineParagraph p)
boolean
isStackOwner()
Defaults to false.void
setCssAppliers(CssAppliers cssAppliers)
java.util.List<Element>
start(WorkerContext ctx, Tag tag)
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.startElement(WorkerContext, Tag)
.java.util.List<Element>
startElement(WorkerContext ctx, Tag tag)
Calculates any found font size to pt values and set it in the CSS before callingstart(WorkerContext, Tag)
.
Checks forCSS.Property.PAGE_BREAK_BEFORE
, if the value is always aChunk.NEXTPAGE
added before the implementorsstart(WorkerContext, Tag)
method.protected java.util.List<Element>
textContent(WorkerContext ctx, Tag tag, java.lang.String content)
protected void
updateParagraphFontIfNeeded(Phrase p, Element child)
In case child font is of bigger size than paragraph font, text overlapping may occur.
-
-
-
Field Detail
-
fontsizeTrans
private final FontSizeTranslator fontsizeTrans
-
cssAppliers
private CssAppliers cssAppliers
-
ignoreDirAttribute
private java.util.Set<java.lang.String> ignoreDirAttribute
For some tags, if they have their own not inherited DIR attribute, this attribute will definitely not be applied for itext layout. For the most common such tags we use this set to ignore DIR attribute, in order to avoid unnecessary adjustments in XmlWorker. However if parent of these tags have DIR attribute, it may be applied to these tags.
-
tree
private java.util.List<Tag> tree
-
-
Method Detail
-
getCSSResolver
public CSSResolver getCSSResolver(WorkerContext context) throws NoCustomContextException
Utility method that fetches the CSSResolver from the if any and if it uses the default key.- Parameters:
context
- the WorkerContext- Returns:
- CSSResolver
- Throws:
NoCustomContextException
- if the context of theCssResolverPipeline
could not be found.
-
getHtmlPipelineContext
public HtmlPipelineContext getHtmlPipelineContext(WorkerContext context) throws NoCustomContextException
Utility method that fetches the HtmlPipelineContext used if any and if it uses the default key.- Parameters:
context
- the WorkerContext- Returns:
- a HtmlPipelineContext
- Throws:
NoCustomContextException
- if the context of theHtmlPipelineContext
could not be found.
-
startElement
public final java.util.List<Element> startElement(WorkerContext ctx, Tag tag)
Calculates any found font size to pt values and set it in the CSS before callingstart(WorkerContext, Tag)
.
Checks forCSS.Property.PAGE_BREAK_BEFORE
, if the value is always aChunk.NEXTPAGE
added before the implementorsstart(WorkerContext, Tag)
method.- Specified by:
startElement
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encountered- Returns:
- Element an Element to add to the current content;
-
start
public java.util.List<Element> start(WorkerContext ctx, Tag tag)
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.startElement(WorkerContext, Tag)
. ThestartElement(WorkerContext, Tag)
calls this method after or before doing certain stuff, (see it's description).- Parameters:
ctx
- the WorkerContexttag
- the tag- Returns:
- an element to be added to current content, may be null
-
content
public java.util.List<Element> content(WorkerContext ctx, Tag tag, java.lang.String content)
Description copied from interface:TagProcessor
This method is called if there is text content encountered between the opening and closing tags this TagProcessor is mapped to.- Specified by:
content
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encounteredcontent
- the text content between the tags this TagProcessor is mapped to.- Returns:
- the element to add to the currentContent list
-
getParentDirection
private java.lang.String getParentDirection()
-
getRunDirection
protected int getRunDirection(Tag tag)
-
textContent
protected java.util.List<Element> textContent(WorkerContext ctx, Tag tag, java.lang.String content)
-
endElement
public final java.util.List<Element> endElement(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)
Checks forCSS.Property.PAGE_BREAK_AFTER
, if the value is always aChunk.NEXTPAGE
is added to the currentContentList after callingend(WorkerContext, Tag, List)
.- Specified by:
endElement
in interfaceTagProcessor
- Parameters:
ctx
- the WorkerContexttag
- the tag encounteredcurrentContent
- a list of content possibly created by TagProcessing of inner tags, and bystartElement
andcontent
methods of thisTagProcessor
.- Returns:
- the resulting element to add to the document or a content stack.
-
end
public java.util.List<Element> end(WorkerContext ctx, Tag tag, java.util.List<Element> currentContent)
Classes extending AbstractTagProcessor should override this method for actions that should be done inTagProcessor.endElement(WorkerContext, Tag, List)
. TheendElement(WorkerContext, Tag, List)
calls this method after or before doing certain stuff, (see it's description).- Parameters:
ctx
- the WorkerContexttag
- the tagcurrentContent
- the content created from e.g. inner tags, inner content and not yet added to document.- Returns:
- a List containing iText Element objects
-
isStackOwner
public boolean isStackOwner()
Defaults to false.- Specified by:
isStackOwner
in interfaceTagProcessor
- Returns:
- true if the tag implementation must keep it's own currentContent stack.
- See Also:
TagProcessor.isStackOwner()
-
currentContentToParagraph
public java.util.List<Element> currentContentToParagraph(java.util.List<Element> currentContent, boolean addNewLines, boolean applyCSS, Tag tag, WorkerContext ctx)
Adds currentContent list to a paragraph element. If addNewLines is true a Paragraph object is returned, else a NoNewLineParagraph object is returned.- Parameters:
currentContent
- Listof the current elements to be added. addNewLines
- boolean to declare which paragraph element should be returned, true if new line should be added or not.applyCSS
- true if CSS should be applied on the paragraph.tag
- the relevant tag.ctx
- the WorkerContext.- Returns:
- a List of paragraphs.
-
currentContentToParagraph
public final java.util.List<Element> currentContentToParagraph(java.util.List<Element> currentContent, boolean addNewLines)
Default apply CSS to false and tag to null.- Parameters:
currentContent
- Listof the current elements to be added. addNewLines
- boolean to declare which paragraph element should be returned, true if new line should be added or not.- Returns:
- a List with paragraphs
- See Also:
currentContentToParagraph(List, boolean, boolean, Tag, WorkerContext)
-
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
-
createParagraph
protected Paragraph createParagraph()
-
doRtlIndentCorrections
protected void doRtlIndentCorrections(Indentable p)
-
invertTextAlignForParagraph
protected void invertTextAlignForParagraph(Paragraph p)
-
invertTextAlignForParagraph
protected void invertTextAlignForParagraph(NoNewLineParagraph p)
-
-