Package com.itextpdf.tool.xml
Class XMLWorker
- java.lang.Object
-
- com.itextpdf.tool.xml.XMLWorker
-
- All Implemented Interfaces:
XMLParserListener
public class XMLWorker extends java.lang.Object implements XMLParserListener
The implementation of theXMLParserListener.
Important Note: This class the XMLWorker stores theWorkerContext(Which is aWorkerContextImpl) in a ThreadLocal variable, WorkerContext is confined to threads here.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ThreadLocal<WorkerContextImpl>contextprotected booleanparseHtmlprotected Pipeline<?>rootpPipe
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Triggered when parsing is finished and the stream will be closed.protected static voidcloseLocalWC()voidcomment(java.lang.String comment)Triggered for comments that are found.protected TagcreateTag(java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> attr, java.lang.String ns)Creates a new Tag object from the given parameters.voidendElement(java.lang.String tag, java.lang.String ns)Triggered on a closing tag.protected TaggetCurrentTag()Returns the current tag.protected static WorkerContextgetLocalWC()Returns the local WorkerContext, beware: could be a newly initialized one, ifclose()orcloseLocalWC()has been called before.protected booleanignoreCdata()voidinit()Triggered when parsing has started.voidstartElement(java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> attr, java.lang.String ns)Triggered on an opening tag.voidtext(java.lang.String text)This method passes encountered text to the pipeline via thePipeline.content(WorkerContext, Tag, String, ProcessObject)method.voidunknownText(java.lang.String text)Triggered for text found outside root tag.
-
-
-
Field Detail
-
rootpPipe
protected final Pipeline<?> rootpPipe
-
context
private static java.lang.ThreadLocal<WorkerContextImpl> context
-
parseHtml
protected final boolean parseHtml
-
-
Constructor Detail
-
XMLWorker
public XMLWorker(Pipeline<?> pipeline, boolean parseHtml)
Constructs a new XMLWorker- Parameters:
pipeline- the pipelineparseHtml- true if this XMLWorker is parsing HTML, this actually just means: convert all tags to lowercase.
-
-
Method Detail
-
init
public void init()
Description copied from interface:XMLParserListenerTriggered when parsing has started.- Specified by:
initin interfaceXMLParserListener
-
startElement
public void startElement(java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> attr, java.lang.String ns)Description copied from interface:XMLParserListenerTriggered on an opening tag.- Specified by:
startElementin interfaceXMLParserListener- Parameters:
tag- the tag of the elementattr- the attributes found on the tagns- the namespace or empty String
-
createTag
protected Tag createTag(java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> attr, java.lang.String ns)
Creates a new Tag object from the given parameters.- Parameters:
tag- the tag nameattr- the attributesns- the namespace if any- Returns:
- a Tag
-
endElement
public void endElement(java.lang.String tag, java.lang.String ns)Description copied from interface:XMLParserListenerTriggered on a closing tag.- Specified by:
endElementin interfaceXMLParserListener- Parameters:
tag- the tagns- the namespace or empty String
-
text
public void text(java.lang.String text)
This method passes encountered text to the pipeline via thePipeline.content(WorkerContext, Tag, String, ProcessObject)method.- Specified by:
textin interfaceXMLParserListener- Parameters:
text- the text
-
unknownText
public void unknownText(java.lang.String text)
Description copied from interface:XMLParserListenerTriggered for text found outside root tag.- Specified by:
unknownTextin interfaceXMLParserListener- Parameters:
text- the text
-
comment
public void comment(java.lang.String comment)
Description copied from interface:XMLParserListenerTriggered for comments that are found.- Specified by:
commentin interfaceXMLParserListener- Parameters:
comment- the comment
-
close
public void close()
Description copied from interface:XMLParserListenerTriggered when parsing is finished and the stream will be closed.- Specified by:
closein interfaceXMLParserListener
-
getCurrentTag
protected Tag getCurrentTag()
Returns the current tag.- Returns:
- the current tag
-
getLocalWC
protected static WorkerContext getLocalWC()
Returns the local WorkerContext, beware: could be a newly initialized one, ifclose()orcloseLocalWC()has been called before.- Returns:
- the local WorkerContext
-
closeLocalWC
protected static void closeLocalWC()
-
ignoreCdata
protected boolean ignoreCdata()
-
-