1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: ElemDesc.java,v 1.4 2004/02/17 04:18:19 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.serializer;
  20. import com.sun.org.apache.xml.internal.utils.StringToIntTable;
  21. /**
  22. * This class has a series of flags (bit values) that describe an HTML element
  23. */
  24. public final class ElemDesc
  25. {
  26. /** Bit flags to tell about this element type. */
  27. int m_flags;
  28. /**
  29. * Table of attribute names to integers, which contain bit flags telling about
  30. * the attributes.
  31. */
  32. StringToIntTable m_attrs = null;
  33. /** Bit position if this element type is empty. */
  34. public static final int EMPTY = (1 << 1);
  35. /** Bit position if this element type is a flow. */
  36. public static final int FLOW = (1 << 2);
  37. /** Bit position if this element type is a block. */
  38. public static final int BLOCK = (1 << 3);
  39. /** Bit position if this element type is a block form. */
  40. public static final int BLOCKFORM = (1 << 4);
  41. /** Bit position if this element type is a block form field set (?? -sb). */
  42. public static final int BLOCKFORMFIELDSET = (1 << 5);
  43. /** Bit position if this element type is CDATA. */
  44. public static final int CDATA = (1 << 6);
  45. /** Bit position if this element type is PCDATA. */
  46. public static final int PCDATA = (1 << 7);
  47. /** Bit position if this element type is should be raw characters. */
  48. public static final int RAW = (1 << 8);
  49. /** Bit position if this element type should be inlined. */
  50. public static final int INLINE = (1 << 9);
  51. /** Bit position if this element type is INLINEA (?? -sb). */
  52. public static final int INLINEA = (1 << 10);
  53. /** Bit position if this element type is an inline label. */
  54. public static final int INLINELABEL = (1 << 11);
  55. /** Bit position if this element type is a font style. */
  56. public static final int FONTSTYLE = (1 << 12);
  57. /** Bit position if this element type is a phrase. */
  58. public static final int PHRASE = (1 << 13);
  59. /** Bit position if this element type is a form control. */
  60. public static final int FORMCTRL = (1 << 14);
  61. /** Bit position if this element type is ???. */
  62. public static final int SPECIAL = (1 << 15);
  63. /** Bit position if this element type is ???. */
  64. public static final int ASPECIAL = (1 << 16);
  65. /** Bit position if this element type is an odd header element. */
  66. public static final int HEADMISC = (1 << 17);
  67. /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
  68. public static final int HEAD = (1 << 18);
  69. /** Bit position if this element type is a list. */
  70. public static final int LIST = (1 << 19);
  71. /** Bit position if this element type is a preformatted type. */
  72. public static final int PREFORMATTED = (1 << 20);
  73. /** Bit position if this element type is whitespace sensitive. */
  74. public static final int WHITESPACESENSITIVE = (1 << 21);
  75. /** Bit position if this element type is a header element (i.e. HEAD). */
  76. public static final int HEADELEM = (1 << 22);
  77. /** Bit position if this attribute type is a URL. */
  78. public static final int ATTRURL = (1 << 1);
  79. /** Bit position if this attribute type is an empty type. */
  80. public static final int ATTREMPTY = (1 << 2);
  81. /**
  82. * Construct an ElemDesc from a set of bit flags.
  83. *
  84. *
  85. * @param flags Bit flags that describe the basic properties of this element type.
  86. */
  87. public ElemDesc(int flags)
  88. {
  89. m_flags = flags;
  90. }
  91. /**
  92. * Tell if this element type has the basic bit properties that are passed
  93. * as an argument.
  94. *
  95. * @param flags Bit flags that describe the basic properties of interest.
  96. *
  97. * @return true if any of the flag bits are true.
  98. */
  99. public boolean is(int flags)
  100. {
  101. // int which = (m_flags & flags);
  102. return (m_flags & flags) != 0;
  103. }
  104. public int getFlags() {
  105. return m_flags;
  106. }
  107. /**
  108. * Set an attribute name and it's bit properties.
  109. *
  110. *
  111. * @param name non-null name of attribute, in upper case.
  112. * @param flags flag bits.
  113. */
  114. public void setAttr(String name, int flags)
  115. {
  116. if (null == m_attrs)
  117. m_attrs = new StringToIntTable();
  118. m_attrs.put(name, flags);
  119. }
  120. /**
  121. * Tell if any of the bits of interest are set for a named attribute type.
  122. *
  123. * @param name non-null reference to attribute name, in any case.
  124. * @param flags flag mask.
  125. *
  126. * @return true if any of the flags are set for the named attribute.
  127. */
  128. public boolean isAttrFlagSet(String name, int flags)
  129. {
  130. return (null != m_attrs)
  131. ? ((m_attrs.getIgnoreCase(name) & flags) != 0)
  132. : false;
  133. }
  134. }