com.itextpdf.tool.xml.html
Class AbstractTagProcessor

java.lang.Object
  extended by 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 Object
implements TagProcessor, CssAppliersAware

Abstract TagProcessor that allows setting the configuration object to a protected member variable.
Implements TagProcessor.startElement(WorkerContext, Tag) and TagProcessor.endElement(WorkerContext, Tag, List) to calculate font sizes and add new pages if needed.
Extend from this class instead of implementing TagProcessor to benefit from auto fontsize metric conversion to pt and page-break-before/after insertion. Override start(WorkerContext, Tag) and end(WorkerContext, Tag, List) in your extension.

Author:
redlab_b

Constructor Summary
AbstractTagProcessor()
           
 
Method Summary
 List<Element> content(WorkerContext ctx, Tag tag, 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()
           
 List<Element> currentContentToParagraph(List<Element> currentContent, boolean addNewLines)
          Default apply CSS to false and tag to null.
 List<Element> currentContentToParagraph(List<Element> currentContent, boolean addNewLines, boolean applyCSS, Tag tag, WorkerContext ctx)
          Adds currentContent list to a paragraph element.
protected  void doRtlIndentCorrections(Indentable p)
           
 List<Element> end(WorkerContext ctx, Tag tag, List<Element> currentContent)
          Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.endElement(WorkerContext, Tag, List).
 List<Element> endElement(WorkerContext ctx, Tag tag, List<Element> currentContent)
          Checks for CSS.Property.PAGE_BREAK_AFTER, if the value is always a Chunk.NEXTPAGE is added to the currentContentList after calling end(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.
protected  int getRunDirection(Tag tag)
           
 boolean isStackOwner()
          Defaults to false.
 void setCssAppliers(CssAppliers cssAppliers)
           
 List<Element> start(WorkerContext ctx, Tag tag)
          Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.startElement(WorkerContext, Tag).
 List<Element> startElement(WorkerContext ctx, Tag tag)
          Calculates any found font size to pt values and set it in the CSS before calling start(WorkerContext, Tag).
protected  List<Element> textContent(WorkerContext ctx, Tag tag, String content)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTagProcessor

public AbstractTagProcessor()
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 the CssResolverPipeline 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 the HtmlPipelineContext could not be found.

startElement

public final List<Element> startElement(WorkerContext ctx,
                                        Tag tag)
Calculates any found font size to pt values and set it in the CSS before calling start(WorkerContext, Tag).
Checks for CSS.Property.PAGE_BREAK_BEFORE, if the value is always a Chunk.NEXTPAGE added before the implementors start(WorkerContext, Tag) method.

Specified by:
startElement in interface TagProcessor
Parameters:
ctx - the WorkerContext
tag - the tag encountered
Returns:
Element an Element to add to the current content;

start

public List<Element> start(WorkerContext ctx,
                           Tag tag)
Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.startElement(WorkerContext, Tag). The startElement(WorkerContext, Tag) calls this method after or before doing certain stuff, (see it's description).

Parameters:
ctx - the WorkerContext
tag - the tag
Returns:
an element to be added to current content, may be null

content

public List<Element> content(WorkerContext ctx,
                             Tag tag,
                             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 interface TagProcessor
Parameters:
ctx - the WorkerContext
tag - the tag encountered
content - the text content between the tags this TagProcessor is mapped to.
Returns:
the element to add to the currentContent list

getRunDirection

protected int getRunDirection(Tag tag)

textContent

protected List<Element> textContent(WorkerContext ctx,
                                    Tag tag,
                                    String content)

endElement

public final List<Element> endElement(WorkerContext ctx,
                                      Tag tag,
                                      List<Element> currentContent)
Checks for CSS.Property.PAGE_BREAK_AFTER, if the value is always a Chunk.NEXTPAGE is added to the currentContentList after calling end(WorkerContext, Tag, List).

Specified by:
endElement in interface TagProcessor
Parameters:
ctx - the WorkerContext
tag - the tag encountered
currentContent - a list of content possibly created by TagProcessing of inner tags, and by startElement and content methods of this TagProcessor .
Returns:
the resulting element to add to the document or a content stack.

end

public List<Element> end(WorkerContext ctx,
                         Tag tag,
                         List<Element> currentContent)
Classes extending AbstractTagProcessor should override this method for actions that should be done in TagProcessor.endElement(WorkerContext, Tag, List). The endElement(WorkerContext, Tag, List) calls this method after or before doing certain stuff, (see it's description).

Parameters:
ctx - the WorkerContext
tag - the tag
currentContent - 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 interface TagProcessor
Returns:
true if the tag implementation must keep it's own currentContent stack.
See Also:
TagProcessor.isStackOwner()

currentContentToParagraph

public List<Element> currentContentToParagraph(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 - List of 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 List<Element> currentContentToParagraph(List<Element> currentContent,
                                                     boolean addNewLines)
Default apply CSS to false and tag to null.

Parameters:
currentContent - List of 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 interface CssAppliersAware
Parameters:
cssAppliers - the CssAppliers

getCssAppliers

public CssAppliers getCssAppliers()
Specified by:
getCssAppliers in interface CssAppliersAware
Returns:
the CssAppliers

createParagraph

protected Paragraph createParagraph()

doRtlIndentCorrections

protected void doRtlIndentCorrections(Indentable p)


Copyright © 2015. All Rights Reserved.