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.7 2004/02/17 04:21:14 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.utils;
  20. import java.util.Hashtable;
  21. /**
  22. * This class is in support of SerializerToHTML, and acts as a sort
  23. * of element representative for HTML elements.
  24. * @xsl.usage internal
  25. */
  26. class ElemDesc
  27. {
  28. /** Table of attributes for the element */
  29. Hashtable m_attrs = null;
  30. /** Element's flags, describing the role this element plays during
  31. * formatting of the document. This is used as a bitvector; more than one flag
  32. * may be set at a time, bitwise-ORed together. Mnemonic and bits
  33. * have been assigned to the flag values. NOTE: Some bits are
  34. * currently assigned multiple mnemonics; it is the caller's
  35. * responsibility to disambiguate these if necessary. */
  36. int m_flags;
  37. /** Defines mnemonic and bit-value for the EMPTY flag */
  38. static final int EMPTY = (1 << 1);
  39. /** Defines mnemonic and bit-value for the FLOW flag */
  40. static final int FLOW = (1 << 2);
  41. /** Defines mnemonic and bit-value for the BLOCK flag */
  42. static final int BLOCK = (1 << 3);
  43. /** Defines mnemonic and bit-value for the BLOCKFORM flag */
  44. static final int BLOCKFORM = (1 << 4);
  45. /** Defines mnemonic and bit-value for the BLOCKFORMFIELDSET flag */
  46. static final int BLOCKFORMFIELDSET = (1 << 5);
  47. /** Defines mnemonic and bit-value for the CDATA flag */
  48. static final int CDATA = (1 << 6);
  49. /** Defines mnemonic and bit-value for the PCDATA flag */
  50. static final int PCDATA = (1 << 7);
  51. /** Defines mnemonic and bit-value for the RAW flag */
  52. static final int RAW = (1 << 8);
  53. /** Defines mnemonic and bit-value for the INLINE flag */
  54. static final int INLINE = (1 << 9);
  55. /** Defines mnemonic and bit-value for the INLINEA flag */
  56. static final int INLINEA = (1 << 10);
  57. /** Defines mnemonic and bit-value for the INLINELABEL flag */
  58. static final int INLINELABEL = (1 << 11);
  59. /** Defines mnemonic and bit-value for the FONTSTYLE flag */
  60. static final int FONTSTYLE = (1 << 12);
  61. /** Defines mnemonic and bit-value for the PHRASE flag */
  62. static final int PHRASE = (1 << 13);
  63. /** Defines mnemonic and bit-value for the FORMCTRL flag */
  64. static final int FORMCTRL = (1 << 14);
  65. /** Defines mnemonic and bit-value for the SPECIAL flag */
  66. static final int SPECIAL = (1 << 15);
  67. /** Defines mnemonic and bit-value for the ASPECIAL flag */
  68. static final int ASPECIAL = (1 << 16);
  69. /** Defines mnemonic and bit-value for the HEADMISC flag */
  70. static final int HEADMISC = (1 << 17);
  71. /** Defines mnemonic and bit-value for the HEAD flag */
  72. static final int HEAD = (1 << 18);
  73. /** Defines mnemonic and bit-value for the LIST flag */
  74. static final int LIST = (1 << 19);
  75. /** Defines mnemonic and bit-value for the PREFORMATTED flag */
  76. static final int PREFORMATTED = (1 << 20);
  77. /** Defines mnemonic and bit-value for the WHITESPACESENSITIVE flag */
  78. static final int WHITESPACESENSITIVE = (1 << 21);
  79. /** Defines mnemonic and bit-value for the ATTRURL flag */
  80. static final int ATTRURL = (1 << 1);
  81. /** Defines mnemonic and bit-value for the ATTREMPTY flag */
  82. static final int ATTREMPTY = (1 << 2);
  83. /**
  84. * Construct an ElementDescription with an initial set of flags.
  85. *
  86. * @param flags Element flags
  87. * @see m_flags
  88. */
  89. ElemDesc(int flags)
  90. {
  91. m_flags = flags;
  92. }
  93. /**
  94. * "is (this element described by these flags)".
  95. *
  96. * This might more properly be called areFlagsSet(). It accepts an
  97. * integer (being used as a bitvector) and checks whether all the
  98. * corresponding bits are set in our internal flags. Note that this
  99. * test is performed as a bitwise AND, not an equality test, so a
  100. * 0 bit in the input means "don't test", not "must be set false".
  101. *
  102. * @param flags Vector of flags to compare against this element's flags
  103. *
  104. * @return true if the flags set in the parameter are also set in the
  105. * element's stored flags.
  106. *
  107. * @see m_flags
  108. * @see isAttrFlagSet
  109. */
  110. boolean is(int flags)
  111. {
  112. // int which = (m_flags & flags);
  113. return (m_flags & flags) != 0;
  114. }
  115. /**
  116. * Set a new attribute for this element
  117. *
  118. *
  119. * @param name Attribute name
  120. * @param flags Attibute flags
  121. */
  122. void setAttr(String name, int flags)
  123. {
  124. if (null == m_attrs)
  125. m_attrs = new Hashtable();
  126. m_attrs.put(name, new Integer(flags));
  127. }
  128. /**
  129. * Find out if a flag is set in a given attribute of this element
  130. *
  131. *
  132. * @param name Attribute name
  133. * @param flags Flag to check
  134. *
  135. * @return True if the flag is set in the attribute. Returns false
  136. * if the attribute is not found
  137. * @see m_flags
  138. */
  139. boolean isAttrFlagSet(String name, int flags)
  140. {
  141. if (null != m_attrs)
  142. {
  143. Integer _flags = (Integer) m_attrs.get(name);
  144. if (null != _flags)
  145. {
  146. return (_flags.intValue() & flags) != 0;
  147. }
  148. }
  149. return false;
  150. }
  151. }