Package org.htmlcleaner
Class TagInfo
java.lang.Object
org.htmlcleaner.TagInfo
Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddefineAllowedChildrenTags(String commaSeparatedListOfTags) voiddefineCloseBeforeCopyInsideTags(String commaSeparatedListOfTags) voiddefineCloseBeforeTags(String commaSeparatedListOfTags) voiddefineCloseInsideCopyAfterTags(String commaSeparatedListOfTags) voiddefineFatalTags(String commaSeparatedListOfTags) voiddefineForbiddenTags(String commaSeparatedListOfTags) voiddefineHigherLevelTags(String commaSeparatedListOfTags) voiddefineRequiredEnclosingTags(String commaSeparatedListOfTags) getName()booleanbooleanbooleanisFatalTag(String tag) booleanbooleanisUnique()voidsetAssumedNamespace(String assumedNamespace) voidsetAssumedNamespacePrefix(String assumedNamespacePrefix) voidsetBelongsTo(BelongsTo belongsTo) voidsetChildTags(Set<String> childTags) voidsetContinueAfterTags(Set<String> continueAfterTags) voidsetCopyTags(Set<String> copyTags) voidsetDeprecated(boolean deprecated) voidsetDisplay(Display display) voidsetFatalTag(String fatalTag) voidsetHigherTags(Set<String> higherTags) voidsetMustCloseTags(Set<String> mustCloseTags) voidvoidsetPermittedTags(Set<String> permittedTags) voidsetPreferredChildTag(String preferredChildTag) voidsetRequiredParent(String requiredParent) voidsetUnique(boolean unique)
-
Constructor Details
-
TagInfo
public TagInfo(String name, ContentType contentType, BelongsTo belongsTo, boolean deprecated, boolean unique, boolean ignorePermitted, CloseTag closeTag, Display display)
-
-
Method Details
-
getAssumedNamespace
-
setAssumedNamespace
-
getAssumedNamespacePrefix
-
setAssumedNamespacePrefix
-
defineFatalTags
-
defineRequiredEnclosingTags
-
defineForbiddenTags
-
defineAllowedChildrenTags
-
defineHigherLevelTags
-
defineCloseBeforeCopyInsideTags
-
defineCloseInsideCopyAfterTags
-
defineCloseBeforeTags
-
getDisplay
-
setDisplay
-
getName
-
setName
-
getContentType
-
getMustCloseTags
-
setMustCloseTags
-
getHigherTags
-
setHigherTags
-
getChildTags
-
setChildTags
-
getPermittedTags
-
setPermittedTags
-
getCopyTags
-
setCopyTags
-
getContinueAfterTags
-
setContinueAfterTags
-
getRequiredParentTags
-
setRequiredParent
-
getBelongsTo
-
setBelongsTo
-
getFatalTags
-
isFatalTag
-
setFatalTag
-
isDeprecated
public boolean isDeprecated() -
setDeprecated
public void setDeprecated(boolean deprecated) -
isUnique
public boolean isUnique() -
setUnique
public void setUnique(boolean unique) -
isEmptyTag
public boolean isEmptyTag() -
isMinimizedTagPermitted
public boolean isMinimizedTagPermitted()- Returns:
- True if the tag can be minimized
-
getPreferredChildTag
-
setPreferredChildTag
-