Package org.htmlcleaner
Class TagInfo
- java.lang.Object
-
- org.htmlcleaner.TagInfo
-
public class TagInfo extends java.lang.ObjectClass contains information about single HTML tag.
It also contains rules for tag balancing. For each tag, list of dependent tags may be defined. There are several kinds of dependencies used to reorder tags:- fatal tags - required outer tag - the tag will be ignored during parsing (will be skipped) if this fatal tag is missing. For example, most web browsers ignore elements TD, TR, TBODY if they are not in the context of TABLE tag.
- required enclosing tags - if there is no such, it is implicitly created. For example if TD is out of TR - open TR is created before.
- forbidden tags - it is not allowed to occur inside - for example FORM cannot be inside other FORM and it will be ignored during cleanup.
- allowed children tags - for example TR allows TD and TH. If there are some dependent allowed tags defined then cleaner ignores other tags, treating them as not allowed, unless they are in some other relationship with this tag.
- preferred child tag - where a child tag doesn't match, but we want to by default insert an intervening tag rather than just move it outside. For example, LI in UL, TD in TR.
- higher level tags - for example for TR higher tags are THEAD, TBODY, TFOOT.
-
tags that must be closed and copied - for example, in
<a href="#"><div>....tag A must be closed before DIV but copied again inside DIV. -
tags that must be closed before closing this tag and copied again after -
for example, in
<i><b>at</i> first</b> texttag B must be closed before closing I, but it must be copied again after resulting finally in sequence:<i><b>at</b></i><b> first</b> text.
Tag TR for instance (table row) may define the following dependencies:
- fatal tag is
table - required enclosing tag is
tbody - allowed children tags are
td,th - higher level tags are
thead,tfoot - tags that muste be closed before are
tr,td,th,caption,colgroup
trmust be in context oftable, otherwise it will be ignored,trmay can be directly insidetbody,tfootandthead, otherwisetbodywill be implicitly created in front of it.trcan containtdandth, all other tags and content will be pushed out of current limiting context, in the case of html tables, in front of enclosingtabletag.- if previous open tag is one of
tr,captionorcolgroup, it will be implicitly closed.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringassumedNamespaceprivate java.lang.StringassumedNamespacePrefixprivate BelongsTobelongsToprivate java.util.Set<java.lang.String>childTagsprivate CloseTagcloseTagprivate ContentTypecontentTypeprivate java.util.Set<java.lang.String>continueAfterTagsprivate java.util.Set<java.lang.String>copyTagsprivate booleandeprecatedprivate Displaydisplayprivate java.util.Set<java.lang.String>fatalTagsprivate java.util.Set<java.lang.String>higherTagsprivate java.util.Set<java.lang.String>mustCloseTagsprivate java.lang.Stringnameprivate java.util.Set<java.lang.String>permittedTagsprivate java.lang.StringpreferredChildTagprivate java.util.Set<java.lang.String>requiredParentTagsprivate booleanunique
-
Constructor Summary
Constructors Constructor Description TagInfo(java.lang.String name, ContentType contentType, BelongsTo belongsTo, boolean deprecated, boolean unique, boolean ignorePermitted, CloseTag closeTag, Display display)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanallowsAnything()(package private) booleanallowsBody()(package private) booleanallowsItem(BaseToken token)voiddefineAllowedChildrenTags(java.lang.String commaSeparatedListOfTags)voiddefineCloseBeforeCopyInsideTags(java.lang.String commaSeparatedListOfTags)voiddefineCloseBeforeTags(java.lang.String commaSeparatedListOfTags)voiddefineCloseInsideCopyAfterTags(java.lang.String commaSeparatedListOfTags)voiddefineFatalTags(java.lang.String commaSeparatedListOfTags)voiddefineForbiddenTags(java.lang.String commaSeparatedListOfTags)voiddefineHigherLevelTags(java.lang.String commaSeparatedListOfTags)voiddefineRequiredEnclosingTags(java.lang.String commaSeparatedListOfTags)java.lang.StringgetAssumedNamespace()java.lang.StringgetAssumedNamespacePrefix()BelongsTogetBelongsTo()java.util.Set<java.lang.String>getChildTags()ContentTypegetContentType()java.util.Set<java.lang.String>getContinueAfterTags()java.util.Set<java.lang.String>getCopyTags()DisplaygetDisplay()java.util.Set<java.lang.String>getFatalTags()java.util.Set<java.lang.String>getHigherTags()java.util.Set<java.lang.String>getMustCloseTags()java.lang.StringgetName()java.util.Set<java.lang.String>getPermittedTags()java.lang.StringgetPreferredChildTag()java.util.Set<java.lang.String>getRequiredParentTags()(package private) booleanhasCopyTags()(package private) booleanhasPermittedTags()(package private) booleanisContinueAfter(java.lang.String tagName)(package private) booleanisCopy(java.lang.String tagName)booleanisDeprecated()booleanisEmptyTag()booleanisFatalTag(java.lang.String tag)(package private) booleanisHeadAndBodyTag()(package private) booleanisHeadTag()(package private) booleanisHigher(java.lang.String tagName)booleanisMinimizedTagPermitted()(package private) booleanisMustCloseTag(TagInfo tagInfo)booleanisUnique()voidsetAssumedNamespace(java.lang.String assumedNamespace)voidsetAssumedNamespacePrefix(java.lang.String assumedNamespacePrefix)voidsetBelongsTo(BelongsTo belongsTo)voidsetChildTags(java.util.Set<java.lang.String> childTags)voidsetContinueAfterTags(java.util.Set<java.lang.String> continueAfterTags)voidsetCopyTags(java.util.Set<java.lang.String> copyTags)voidsetDeprecated(boolean deprecated)voidsetDisplay(Display display)voidsetFatalTag(java.lang.String fatalTag)voidsetHigherTags(java.util.Set<java.lang.String> higherTags)voidsetMustCloseTags(java.util.Set<java.lang.String> mustCloseTags)voidsetName(java.lang.String name)voidsetPermittedTags(java.util.Set<java.lang.String> permittedTags)voidsetPreferredChildTag(java.lang.String preferredChildTag)voidsetRequiredParent(java.lang.String requiredParent)voidsetUnique(boolean unique)
-
-
-
Field Detail
-
name
private java.lang.String name
-
contentType
private ContentType contentType
-
mustCloseTags
private java.util.Set<java.lang.String> mustCloseTags
-
higherTags
private java.util.Set<java.lang.String> higherTags
-
childTags
private java.util.Set<java.lang.String> childTags
-
permittedTags
private java.util.Set<java.lang.String> permittedTags
-
copyTags
private java.util.Set<java.lang.String> copyTags
-
continueAfterTags
private java.util.Set<java.lang.String> continueAfterTags
-
belongsTo
private BelongsTo belongsTo
-
requiredParentTags
private java.util.Set<java.lang.String> requiredParentTags
-
fatalTags
private java.util.Set<java.lang.String> fatalTags
-
preferredChildTag
private java.lang.String preferredChildTag
-
assumedNamespace
private java.lang.String assumedNamespace
-
assumedNamespacePrefix
private java.lang.String assumedNamespacePrefix
-
deprecated
private boolean deprecated
-
unique
private boolean unique
-
closeTag
private CloseTag closeTag
-
display
private Display display
-
-
Constructor Detail
-
TagInfo
public TagInfo(java.lang.String name, ContentType contentType, BelongsTo belongsTo, boolean deprecated, boolean unique, boolean ignorePermitted, CloseTag closeTag, Display display)
-
-
Method Detail
-
getAssumedNamespace
public java.lang.String getAssumedNamespace()
-
setAssumedNamespace
public void setAssumedNamespace(java.lang.String assumedNamespace)
-
getAssumedNamespacePrefix
public java.lang.String getAssumedNamespacePrefix()
-
setAssumedNamespacePrefix
public void setAssumedNamespacePrefix(java.lang.String assumedNamespacePrefix)
-
defineFatalTags
public void defineFatalTags(java.lang.String commaSeparatedListOfTags)
-
defineRequiredEnclosingTags
public void defineRequiredEnclosingTags(java.lang.String commaSeparatedListOfTags)
-
defineForbiddenTags
public void defineForbiddenTags(java.lang.String commaSeparatedListOfTags)
-
defineAllowedChildrenTags
public void defineAllowedChildrenTags(java.lang.String commaSeparatedListOfTags)
-
defineHigherLevelTags
public void defineHigherLevelTags(java.lang.String commaSeparatedListOfTags)
-
defineCloseBeforeCopyInsideTags
public void defineCloseBeforeCopyInsideTags(java.lang.String commaSeparatedListOfTags)
-
defineCloseInsideCopyAfterTags
public void defineCloseInsideCopyAfterTags(java.lang.String commaSeparatedListOfTags)
-
defineCloseBeforeTags
public void defineCloseBeforeTags(java.lang.String commaSeparatedListOfTags)
-
getDisplay
public Display getDisplay()
-
setDisplay
public void setDisplay(Display display)
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
getContentType
public ContentType getContentType()
-
getMustCloseTags
public java.util.Set<java.lang.String> getMustCloseTags()
-
setMustCloseTags
public void setMustCloseTags(java.util.Set<java.lang.String> mustCloseTags)
-
getHigherTags
public java.util.Set<java.lang.String> getHigherTags()
-
setHigherTags
public void setHigherTags(java.util.Set<java.lang.String> higherTags)
-
getChildTags
public java.util.Set<java.lang.String> getChildTags()
-
setChildTags
public void setChildTags(java.util.Set<java.lang.String> childTags)
-
getPermittedTags
public java.util.Set<java.lang.String> getPermittedTags()
-
setPermittedTags
public void setPermittedTags(java.util.Set<java.lang.String> permittedTags)
-
getCopyTags
public java.util.Set<java.lang.String> getCopyTags()
-
setCopyTags
public void setCopyTags(java.util.Set<java.lang.String> copyTags)
-
getContinueAfterTags
public java.util.Set<java.lang.String> getContinueAfterTags()
-
setContinueAfterTags
public void setContinueAfterTags(java.util.Set<java.lang.String> continueAfterTags)
-
getRequiredParentTags
public java.util.Set<java.lang.String> getRequiredParentTags()
-
setRequiredParent
public void setRequiredParent(java.lang.String requiredParent)
-
getBelongsTo
public BelongsTo getBelongsTo()
-
setBelongsTo
public void setBelongsTo(BelongsTo belongsTo)
-
getFatalTags
public java.util.Set<java.lang.String> getFatalTags()
-
isFatalTag
public boolean isFatalTag(java.lang.String tag)
-
setFatalTag
public void setFatalTag(java.lang.String fatalTag)
-
isDeprecated
public boolean isDeprecated()
-
setDeprecated
public void setDeprecated(boolean deprecated)
-
isUnique
public boolean isUnique()
-
setUnique
public void setUnique(boolean unique)
-
isEmptyTag
public boolean isEmptyTag()
-
allowsBody
boolean allowsBody()
-
isHigher
boolean isHigher(java.lang.String tagName)
-
isCopy
boolean isCopy(java.lang.String tagName)
-
hasCopyTags
boolean hasCopyTags()
-
isContinueAfter
boolean isContinueAfter(java.lang.String tagName)
-
hasPermittedTags
boolean hasPermittedTags()
-
isHeadTag
boolean isHeadTag()
-
isHeadAndBodyTag
boolean isHeadAndBodyTag()
-
isMustCloseTag
boolean isMustCloseTag(TagInfo tagInfo)
-
allowsItem
boolean allowsItem(BaseToken token)
- Parameters:
token-- Returns:
- true if the passed token is allowed to be nested in a Tag with this TagInfo.
-
allowsAnything
boolean allowsAnything()
-
isMinimizedTagPermitted
public boolean isMinimizedTagPermitted()
- Returns:
- True if the tag can be minimized
-
getPreferredChildTag
public java.lang.String getPreferredChildTag()
-
setPreferredChildTag
public void setPreferredChildTag(java.lang.String preferredChildTag)
-
-