/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.htmlcheck.tags;

import java.util.*;
import com.silverwrist.dynamo.HTMLTagSet;

public class TagsList
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  private static TagsList _self = null;

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private HashMap m_tagname_to_object = new HashMap();
  private int m_tag_maxlen = 0;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  private TagsList()
  {
    install(new HTMLTag("!DOCTYPE",false,HTMLTagSet.DOCUMENT));
    install(new HTMLTag("%",false,HTMLTagSet.SERVER));
    install(new HTMLTag("%!",false,HTMLTagSet.SERVER));
    install(new HTMLTag("%=",false,HTMLTagSet.SERVER));
    install(new HTMLTag("?",false,HTMLTagSet.SERVER));
    install(new HTMLTag("?=",false,HTMLTagSet.SERVER));
    install(new HTMLTag("?PHP",false,HTMLTagSet.SERVER));
    install(new A_Tag());
    install(new BalancedTag("ABBR",false,HTMLTagSet.INLINE));
    install(new BalancedTag("ACRONYM",false,HTMLTagSet.INLINE));
    install(new BalancedTag("ADDRESS",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("APPLET",false,HTMLTagSet.ACTIVECONTENT));
    install(new HTMLTag("AREA",false,HTMLTagSet.IMAGEMAP));
    install(new BalancedTag("B",false,HTMLTagSet.INLINE));
    install(new HTMLTag("BASE",false,HTMLTagSet.DOCUMENT));
    install(new HTMLTag("BASEFONT",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("BDO",false,HTMLTagSet.INLINE));
    install(new BalancedTag("BEAN",false,HTMLTagSet.JAVASERVER));
    install(new HTMLTag("BGSOUND",false,HTMLTagSet.MSFT_DOCUMENT));
    install(new BalancedTag("BIG",false,HTMLTagSet.INLINE));
    install(new BalancedTag("BLINK",false,HTMLTagSet.NSCP_INLINE));
    install(new BalancedTag("BLOCKQUOTE",true,HTMLTagSet.BLOCK));
    install(new OpenCloseTag("BODY",true,HTMLTagSet.DOCUMENT));
    install(new HTMLTag("BR",true,HTMLTagSet.BLOCK));
    install(new OpenCloseTag("BUTTON",false,HTMLTagSet.FORMS));
    install(new BalancedTag("CAPTION",true,HTMLTagSet.TABLES));
    install(new BalancedTag("CENTER",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("CITE",false,HTMLTagSet.INLINE));
    install(new BalancedTag("CODE",false,HTMLTagSet.INLINE));
    install(new HTMLTag("COL",true,HTMLTagSet.TABLES));
    install(new OpenCloseTag("COLGROUP",true,HTMLTagSet.TABLES));
    install(new BalancedTag("COMMENT",false,HTMLTagSet.MSFT_INLINE));
    install(new ListElementTag("DD",HTMLTagSet.BLOCK));
    install(new BalancedTag("DEL",false,HTMLTagSet.CHANGE));
    install(new BalancedTag("DFN",false,HTMLTagSet.INLINE));
    install(new BalancedTag("DIR",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("DIV",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("DL",true,HTMLTagSet.BLOCK));
    install(new ListElementTag("DT",HTMLTagSet.BLOCK));
    install(new BalancedTag("EM",false,HTMLTagSet.INLINE));
    install(new BalancedTag("EMBED",false,HTMLTagSet.ACTIVECONTENT));
    install(new BalancedTag("FIELDSET",false,HTMLTagSet.FORMS));
    install(new BalancedTag("FONT",false,HTMLTagSet.FONT));
    install(new BalancedTag("FORM",false,HTMLTagSet.FORMS));
    install(new HTMLTag("FRAME",true,HTMLTagSet.FRAMES));
    install(new BalancedTag("FRAMESET",false,HTMLTagSet.FRAMES));
    install(new BalancedTag("H1",true,HTMLTagSet.FONT));
    install(new BalancedTag("H2",true,HTMLTagSet.FONT));
    install(new BalancedTag("H3",true,HTMLTagSet.FONT));
    install(new BalancedTag("H4",true,HTMLTagSet.FONT));
    install(new BalancedTag("H5",true,HTMLTagSet.FONT));
    install(new BalancedTag("H6",true,HTMLTagSet.FONT));
    install(new OpenCloseTag("HEAD",false,HTMLTagSet.DOCUMENT));
    install(new HTMLTag("HR",true,HTMLTagSet.BLOCK));
    install(new OpenCloseTag("HTML",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("I",false,HTMLTagSet.INLINE));
    install(new BalancedTag("IFRAME",true,HTMLTagSet.FRAMES));
    install(new BalancedTag("ILAYER",true,HTMLTagSet.NSCP_LAYERS));
    install(new HTMLTag("IMG",false,HTMLTagSet.IMAGES));
    install(new HTMLTag("INPUT",false,HTMLTagSet.FORMS));
    install(new BalancedTag("INS",false,HTMLTagSet.CHANGE));
    install(new HTMLTag("ISINDEX",false,HTMLTagSet.FORMS));
    install(new BalancedTag("KBD",false,HTMLTagSet.INLINE));
    install(new HTMLTag("KEYGEN",false,HTMLTagSet.NSCP_FORMS));
    install(new BalancedTag("LABEL",false,HTMLTagSet.FORMS));
    install(new BalancedTag("LAYER",true,HTMLTagSet.NSCP_LAYERS));
    install(new BalancedTag("LEGEND",false,HTMLTagSet.FORMS));
    install(new ListElementTag("LI",HTMLTagSet.BLOCK));
    install(new HTMLTag("LINK",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("LISTING",false,HTMLTagSet.MSFT_INLINE));
    install(new BalancedTag("MAP",false,HTMLTagSet.IMAGEMAP));
    install(new BalancedTag("MARQUEE",true,HTMLTagSet.MSFT_BLOCK));
    install(new BalancedTag("MENU",true,HTMLTagSet.BLOCK));
    install(new HTMLTag("META",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("MULTICOL",true,HTMLTagSet.NSCP_BLOCK));
    install(new NOBR_Tag());
    install(new BalancedTag("NOEMBED",false,HTMLTagSet.ACTIVECONTENT));
    install(new BalancedTag("NOFRAMES",false,HTMLTagSet.FRAMES));
    install(new BalancedTag("NOLAYER",false,HTMLTagSet.NSCP_LAYERS));
    install(new BalancedTag("NOSCRIPT",false,HTMLTagSet.ACTIVECONTENT));
    install(new BalancedTag("OBJECT",false,HTMLTagSet.ACTIVECONTENT));
    install(new BalancedTag("OL",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("OPTGROUP",false,HTMLTagSet.FORMS));
    install(new ListElementTag("OPTION",HTMLTagSet.FORMS));
    install(new OpenCloseTag("P",true,HTMLTagSet.BLOCK));
    install(new HTMLTag("PARAM",false,HTMLTagSet.ACTIVECONTENT));
    install(new HTMLTag("PLAINTEXT",false,HTMLTagSet.PREFORMAT));
    install(new BalancedTag("PRE",false,HTMLTagSet.PREFORMAT));
    install(new BalancedTag("Q",false,HTMLTagSet.INLINE));
    install(new HTMLTag("RT",false,HTMLTagSet.MSFT_ACTIVECONTENT));
    install(new BalancedTag("RUBY",false,HTMLTagSet.MSFT_ACTIVECONTENT));
    install(new BalancedTag("S",false,HTMLTagSet.INLINE));
    install(new BalancedTag("SAMP",false,HTMLTagSet.INLINE));
    install(new BalancedTag("SCRIPT",false,HTMLTagSet.ACTIVECONTENT));
    install(new BalancedTag("SELECT",false,HTMLTagSet.FORMS));
    install(new BalancedTag("SERVER",false,HTMLTagSet.NSCP_SERVER));
    install(new BalancedTag("SERVLET",false,HTMLTagSet.JAVASERVER));
    install(new BalancedTag("SMALL",false,HTMLTagSet.INLINE));
    install(new HTMLTag("SPACER",false,HTMLTagSet.NSCP_INLINE));
    install(new BalancedTag("SPAN",false,HTMLTagSet.INLINE));
    install(new BalancedTag("STRIKE",false,HTMLTagSet.INLINE));
    install(new BalancedTag("STRONG",false,HTMLTagSet.INLINE));
    install(new BalancedTag("STYLE",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("SUB",false,HTMLTagSet.INLINE));
    install(new BalancedTag("SUP",false,HTMLTagSet.INLINE));
    install(new BalancedTag("TABLE",true,HTMLTagSet.TABLES));
    install(new OpenCloseTag("TBODY",false,HTMLTagSet.TABLES));
    install(new BalancedTag("TD",true,HTMLTagSet.TABLES));
    install(new BalancedTag("TEXTAREA",true,HTMLTagSet.FORMS));
    install(new OpenCloseTag("TFOOT",false,HTMLTagSet.TABLES));
    install(new BalancedTag("TH",true,HTMLTagSet.TABLES));
    install(new OpenCloseTag("THEAD",false,HTMLTagSet.TABLES));
    install(new BalancedTag("TITLE",false,HTMLTagSet.DOCUMENT));
    install(new BalancedTag("TR",true,HTMLTagSet.TABLES));
    install(new BalancedTag("TT",false,HTMLTagSet.INLINE));
    install(new BalancedTag("U",false,HTMLTagSet.INLINE));
    install(new BalancedTag("UL",true,HTMLTagSet.BLOCK));
    install(new BalancedTag("VAR",false,HTMLTagSet.INLINE));
    install(new WBR_Tag());
    install(new BalancedTag("XML",false,HTMLTagSet.MSFT_ACTIVECONTENT));
    install(new BalancedTag("XMP",false,HTMLTagSet.NSCP_INLINE));

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Internal operations
   *--------------------------------------------------------------------------------
   */

  private final void install(HTMLTag tag)
  {
    m_tagname_to_object.put(tag.getTagName(),tag);
    int len = tag.getTagName().length();
    if (len>m_tag_maxlen)
      m_tag_maxlen = len;

  } // end install

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  public int getMaxTagLength()
  {
    return m_tag_maxlen;

  } // end getMaxTagLength

  public HTMLTag getTag(String name)
  {
    return (HTMLTag)(m_tagname_to_object.get(name.toUpperCase()));

  } // end getTag

  /*--------------------------------------------------------------------------------
   * External static operations
   *--------------------------------------------------------------------------------
   */

  public static synchronized TagsList get()
  {
    if (_self==null)
      _self = new TagsList();
    return _self;

  } // end get

} // end class TagsList
