1 21 package au.id.jericho.lib.html; 22 23 import java.util.*; 24 25 152 public final class HTMLElements implements HTMLElementName { 153 private static final List ALL=new ArrayList(Arrays.asList(new String [] {A,ABBR,ACRONYM,ADDRESS,APPLET,AREA,B,BASE,BASEFONT,BDO,BIG,BLOCKQUOTE,BODY,BR,BUTTON,CAPTION,CENTER,CITE,CODE,COL,COLGROUP,DD,DEL,DFN,DIR,DIV,DL,DT,EM,FIELDSET,FONT,FORM,FRAME,FRAMESET,H1,H2,H3,H4,H5,H6,HEAD,HR,HTML,I,IFRAME,IMG,INPUT,INS,ISINDEX,KBD,LABEL,LEGEND,LI,LINK,MAP,MENU,META,NOFRAMES,NOSCRIPT,OBJECT,OL,OPTGROUP,OPTION,P,PARAM,PRE,Q,S,SAMP,SCRIPT,SELECT,SMALL,SPAN,STRIKE,STRONG,STYLE,SUB,SUP,TABLE,TBODY,TD,TEXTAREA,TFOOT,TH,THEAD,TITLE,TR,TT,U,UL,VAR})); 154 private static final HTMLElementNameSet BLOCK=new HTMLElementNameSet(new String [] {P,H1,H2,H3,H4,H5,H6,UL,OL,DIR,MENU,PRE,DL,DIV,CENTER,NOSCRIPT,NOFRAMES,BLOCKQUOTE,FORM,ISINDEX,HR,TABLE,FIELDSET,ADDRESS}); 155 private static final HTMLElementNameSet INLINE=new HTMLElementNameSet(new String [] {TT,I,B,U,S,STRIKE,BIG,SMALL,EM,STRONG,DFN,CODE,SAMP,KBD,VAR,CITE,ABBR,ACRONYM,A,IMG,APPLET,OBJECT,FONT,BASEFONT,BR,SCRIPT,MAP,Q,SUB,SUP,SPAN,BDO,IFRAME,INPUT,SELECT,TEXTAREA,LABEL,BUTTON,INS,DEL}); 156 157 private static final HTMLElementNameSet END_TAG_FORBIDDEN_SET=new HTMLElementNameSet(new String [] {AREA,BASE,BASEFONT,BR,COL,FRAME,HR,IMG,INPUT,ISINDEX,LINK,META,PARAM}); 158 159 private static final HTMLElementNameSet _UL_OL=new HTMLElementNameSet(UL).union(OL); 160 private static final HTMLElementNameSet _DD_DT=new HTMLElementNameSet(DD).union(DT); 161 private static final HTMLElementNameSet _THEAD_TBODY_TFOOT_TR=new HTMLElementNameSet(THEAD).union(TBODY).union(TFOOT).union(TR); 162 private static final HTMLElementNameSet _THEAD_TBODY_TFOOT_TR_TD_TH=new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR).union(TD).union(TH); 163 164 private static final HTMLElementNameSet DEPRECATED=new HTMLElementNameSet().union(APPLET).union(BASEFONT).union(CENTER).union(DIR).union(FONT).union(ISINDEX).union(MENU).union(S).union(STRIKE).union(U); 165 private static final HTMLElementNameSet START_TAG_OPTIONAL_SET=new HTMLElementNameSet().union(BODY).union(HEAD).union(HTML).union(TBODY); 166 167 private static final HashMap CONSTANT_NAME_MAP=buildTagMap(); private static final HashMap TERMINATING_TAG_NAME_SETS_MAP=buildTerminatingTagNameSetsMap(); private static final Set END_TAG_OPTIONAL_SET=TERMINATING_TAG_NAME_SETS_MAP.keySet(); 170 private static final HTMLElementNameSet END_TAG_REQUIRED_SET=new HTMLElementNameSet().union(ALL).minus(END_TAG_FORBIDDEN_SET).minus(END_TAG_OPTIONAL_SET); 171 private static final HTMLElementNameSet CLOSING_SLASH_IGNORED_SET=new HTMLElementNameSet().union(END_TAG_OPTIONAL_SET).union(END_TAG_REQUIRED_SET); 172 173 static final HTMLElementNameSet END_TAG_REQUIRED_NESTING_FORBIDDEN_SET=new HTMLElementNameSet().union(A).union(ADDRESS).union(APPLET).union(BUTTON).union(CAPTION).union(FORM).union(IFRAME).union(LABEL).union(LEGEND).union(OPTGROUP).union(SCRIPT).union(SELECT).union(STYLE).union(TEXTAREA).union(TITLE); 174 private static final HTMLElementNameSet END_TAG_OPTIONAL_NESTING_FORBIDDEN_SET=new HTMLElementNameSet().union(BODY).union(COLGROUP).union(HEAD).union(HTML).union(OPTION).union(P); 175 private static final HTMLElementNameSet NESTING_FORBIDDEN_SET=new HTMLElementNameSet().union(END_TAG_REQUIRED_NESTING_FORBIDDEN_SET).union(END_TAG_OPTIONAL_NESTING_FORBIDDEN_SET).union(END_TAG_FORBIDDEN_SET); 176 177 private HTMLElements() {} 178 179 186 public static final List getElementNames() { 187 return ALL; 188 } 189 190 212 public static Set getBlockLevelElementNames() { 213 return BLOCK; 214 } 215 216 245 public static Set getInlineLevelElementNames() { 246 return INLINE; 247 } 248 249 254 public static Set getDeprecatedElementNames() { 255 return DEPRECATED; 256 } 257 258 272 public static Set getEndTagForbiddenElementNames() { 273 return END_TAG_FORBIDDEN_SET; 274 } 275 276 296 public static Set getEndTagOptionalElementNames() { 297 return END_TAG_OPTIONAL_SET; 298 } 299 300 314 public static Set getEndTagRequiredElementNames() { 315 return END_TAG_REQUIRED_SET; 316 } 317 318 339 public static Set getStartTagOptionalElementNames() { 340 return START_TAG_OPTIONAL_SET; 341 } 342 343 357 public static Set getTerminatingStartTagNames(final String endTagOptionalElementName) { 358 final HTMLElementTerminatingTagNameSets terminatingTagNameSets=getTerminatingTagNameSets(endTagOptionalElementName); 359 if (terminatingTagNameSets==null) return null; 360 return terminatingTagNameSets.TerminatingStartTagNameSet; 361 } 362 363 380 public static Set getTerminatingEndTagNames(final String endTagOptionalElementName) { 381 final HTMLElementTerminatingTagNameSets terminatingTagNameSets=getTerminatingTagNameSets(endTagOptionalElementName); 382 if (terminatingTagNameSets==null) return null; 383 return terminatingTagNameSets.TerminatingEndTagNameSet; 384 } 385 386 403 public static Set getNonterminatingElementNames(final String endTagOptionalElementName) { 404 final HTMLElementTerminatingTagNameSets terminatingTagNameSets=getTerminatingTagNameSets(endTagOptionalElementName); 405 if (terminatingTagNameSets==null) return null; 406 return terminatingTagNameSets.NonterminatingElementNameSet; 407 } 408 409 415 public static Set getNestingForbiddenElementNames() { 416 return NESTING_FORBIDDEN_SET; 417 } 418 419 static final String getConstantElementName(final String elementName) { 420 final String elementNameConstant=(String )CONSTANT_NAME_MAP.get(elementName); 421 return elementNameConstant!=null ? elementNameConstant : elementName; 422 } 423 424 static final boolean isClosingSlashIgnored(final String elementName) { 425 return CLOSING_SLASH_IGNORED_SET.contains(elementName); 426 } 427 428 static final HTMLElementTerminatingTagNameSets getTerminatingTagNameSets(final String endTagOptionalElementName) { 429 return (HTMLElementTerminatingTagNameSets)TERMINATING_TAG_NAME_SETS_MAP.get(endTagOptionalElementName); 430 } 431 432 private static HashMap buildTerminatingTagNameSetsMap() { 433 final HashMap map=new HashMap(20,1.0F); map.put(BODY,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(), new HTMLElementNameSet(HTML).union(BODY), new HTMLElementNameSet(HTML))); 436 map.put(COLGROUP,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR).union(COLGROUP), new HTMLElementNameSet(TABLE).union(COLGROUP), new HTMLElementNameSet(TABLE))); 437 map.put(DD,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_DD_DT), new HTMLElementNameSet(DL).union(DD), new HTMLElementNameSet(DL))); 438 map.put(DT,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_DD_DT), new HTMLElementNameSet(DL).union(DT), new HTMLElementNameSet(DL))); 439 map.put(HEAD,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(BODY).union(FRAMESET), new HTMLElementNameSet(HTML).union(HEAD), new HTMLElementNameSet())); 440 map.put(HTML,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(), new HTMLElementNameSet(HTML), new HTMLElementNameSet(HTML))); 441 map.put(LI,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(LI), new HTMLElementNameSet(_UL_OL).union(LI), new HTMLElementNameSet(_UL_OL))); 442 map.put(OPTION,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(OPTION).union(OPTGROUP), new HTMLElementNameSet(SELECT).union(OPTION), new HTMLElementNameSet())); 443 map.put(P,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(BLOCK).union(_DD_DT).union(TH).union(TD).union(LI), new HTMLElementNameSet(BLOCK).union(_DD_DT).union(BODY).union(HTML).union(_THEAD_TBODY_TFOOT_TR_TD_TH).union(CAPTION).union(LEGEND), new HTMLElementNameSet())); 444 map.put(TBODY,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(TBODY).union(TFOOT).union(THEAD), new HTMLElementNameSet(TABLE).union(TBODY), new HTMLElementNameSet(TABLE))); 445 map.put(TD,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR_TD_TH), new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR).union(TABLE).union(TD), new HTMLElementNameSet(TABLE))); 446 map.put(TFOOT,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(TBODY).union(TFOOT).union(THEAD), new HTMLElementNameSet(TABLE).union(TFOOT), new HTMLElementNameSet(TABLE))); 447 map.put(TH,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR_TD_TH), new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR).union(TABLE).union(TH), new HTMLElementNameSet(TABLE))); 448 map.put(THEAD,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(TBODY).union(TFOOT).union(THEAD), new HTMLElementNameSet(TABLE).union(THEAD), new HTMLElementNameSet(TABLE))); 449 map.put(TR,new HTMLElementTerminatingTagNameSets(new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR), new HTMLElementNameSet(_THEAD_TBODY_TFOOT_TR).union(TABLE), new HTMLElementNameSet(TABLE))); 450 return map; 451 } 452 453 private static HashMap buildTagMap() { 454 final HashMap map=new HashMap(132,1.0F); for (final Iterator i=ALL.iterator(); i.hasNext();) { 456 final String tagName=(String )i.next(); 457 map.put(tagName,tagName); 458 } 459 map.put(StartTagTypeMarkupDeclaration.ELEMENT,StartTagTypeMarkupDeclaration.ELEMENT); 460 map.put(StartTagTypeMarkupDeclaration.ATTLIST,StartTagTypeMarkupDeclaration.ATTLIST); 461 map.put(StartTagTypeMarkupDeclaration.ENTITY,StartTagTypeMarkupDeclaration.ENTITY); 462 map.put(StartTagTypeMarkupDeclaration.NOTATION,StartTagTypeMarkupDeclaration.NOTATION); 463 map.put(StartTagType.COMMENT.getNamePrefixForTagConstant(),StartTagType.COMMENT.getNamePrefixForTagConstant()); 465 map.put(StartTagType.XML_PROCESSING_INSTRUCTION.getNamePrefixForTagConstant(),StartTagType.XML_PROCESSING_INSTRUCTION.getNamePrefixForTagConstant()); 466 map.put(StartTagType.XML_DECLARATION.getNamePrefixForTagConstant(),StartTagType.XML_DECLARATION.getNamePrefixForTagConstant()); 467 map.put(StartTagType.DOCTYPE_DECLARATION.getNamePrefixForTagConstant(),StartTagType.DOCTYPE_DECLARATION.getNamePrefixForTagConstant()); 468 map.put(PHPTagTypes.PHP_STANDARD.getNamePrefixForTagConstant(),PHPTagTypes.PHP_STANDARD.getNamePrefixForTagConstant()); 469 map.put(StartTagType.SERVER_COMMON.getNamePrefixForTagConstant(),StartTagType.SERVER_COMMON.getNamePrefixForTagConstant()); 470 map.put(MasonTagTypes.MASON_COMPONENT_CALL.getNamePrefixForTagConstant(),MasonTagTypes.MASON_COMPONENT_CALL.getNamePrefixForTagConstant()); 471 map.put(MasonTagTypes.MASON_COMPONENT_CALLED_WITH_CONTENT.getNamePrefixForTagConstant(),MasonTagTypes.MASON_COMPONENT_CALLED_WITH_CONTENT.getNamePrefixForTagConstant()); 472 return map; 473 } 474 } 475 | Popular Tags |