1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.serialize;
  58. import org.apache.xml.utils.StringToIntTable;
  59. /**
  60. * <meta name="usage" content="internal"/>
  61. * This class is in support of SerializerToHTML, and acts as a sort
  62. * of element representative for HTML elements.
  63. */
  64. class ElemDesc
  65. {
  66. /** Bit flags to tell about this element type. */
  67. int m_flags;
  68. /**
  69. * Table of attribute names to integers, which contain bit flags telling about
  70. * the attributes.
  71. */
  72. StringToIntTable m_attrs = null;
  73. /** Bit position if this element type is empty. */
  74. static final int EMPTY = (1 << 1);
  75. /** Bit position if this element type is a flow. */
  76. static final int FLOW = (1 << 2);
  77. /** Bit position if this element type is a block. */
  78. static final int BLOCK = (1 << 3);
  79. /** Bit position if this element type is a block form. */
  80. static final int BLOCKFORM = (1 << 4);
  81. /** Bit position if this element type is a block form field set (?? -sb). */
  82. static final int BLOCKFORMFIELDSET = (1 << 5);
  83. /** Bit position if this element type is CDATA. */
  84. static final int CDATA = (1 << 6);
  85. /** Bit position if this element type is PCDATA. */
  86. static final int PCDATA = (1 << 7);
  87. /** Bit position if this element type is should be raw characters. */
  88. static final int RAW = (1 << 8);
  89. /** Bit position if this element type should be inlined. */
  90. static final int INLINE = (1 << 9);
  91. /** Bit position if this element type is INLINEA (?? -sb). */
  92. static final int INLINEA = (1 << 10);
  93. /** Bit position if this element type is an inline label. */
  94. static final int INLINELABEL = (1 << 11);
  95. /** Bit position if this element type is a font style. */
  96. static final int FONTSTYLE = (1 << 12);
  97. /** Bit position if this element type is a phrase. */
  98. static final int PHRASE = (1 << 13);
  99. /** Bit position if this element type is a form control. */
  100. static final int FORMCTRL = (1 << 14);
  101. /** Bit position if this element type is ???. */
  102. static final int SPECIAL = (1 << 15);
  103. /** Bit position if this element type is ???. */
  104. static final int ASPECIAL = (1 << 16);
  105. /** Bit position if this element type is an odd header element. */
  106. static final int HEADMISC = (1 << 17);
  107. /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
  108. static final int HEAD = (1 << 18);
  109. /** Bit position if this element type is a list. */
  110. static final int LIST = (1 << 19);
  111. /** Bit position if this element type is a preformatted type. */
  112. static final int PREFORMATTED = (1 << 20);
  113. /** Bit position if this element type is whitespace sensitive. */
  114. static final int WHITESPACESENSITIVE = (1 << 21);
  115. /** Bit position if this element type is a header element (i.e. HEAD). */
  116. static final int HEADELEM = (1 << 22);
  117. /** Bit position if this attribute type is a URL. */
  118. static final int ATTRURL = (1 << 1);
  119. /** Bit position if this attribute type is an empty type. */
  120. static final int ATTREMPTY = (1 << 2);
  121. /**
  122. * Construct an ElemDesc from a set of bit flags.
  123. *
  124. *
  125. * @param flags Bit flags that describe the basic properties of this element type.
  126. */
  127. ElemDesc(int flags)
  128. {
  129. m_flags = flags;
  130. }
  131. /**
  132. * Tell if this element type has the basic bit properties that are passed
  133. * as an argument.
  134. *
  135. * @param flags Bit flags that describe the basic properties of interest.
  136. *
  137. * @return true if any of the flag bits are true.
  138. */
  139. boolean is(int flags)
  140. {
  141. // int which = (m_flags & flags);
  142. return (m_flags & flags) != 0;
  143. }
  144. /**
  145. * Set an attribute name and it's bit properties.
  146. *
  147. *
  148. * @param name non-null name of attribute, in upper case.
  149. * @param flags flag bits.
  150. */
  151. void setAttr(String name, int flags)
  152. {
  153. if (null == m_attrs)
  154. m_attrs = new StringToIntTable();
  155. m_attrs.put(name, flags);
  156. }
  157. /**
  158. * Tell if any of the bits of interest are set for a named attribute type.
  159. *
  160. * @param name non-null reference to attribute name, in any case.
  161. * @param flags flag mask.
  162. *
  163. * @return true if any of the flags are set for the named attribute.
  164. */
  165. boolean isAttrFlagSet(String name, int flags)
  166. {
  167. return (null != m_attrs) ? ((m_attrs.getIgnoreCase(name) & flags) != 0) : false;
  168. }
  169. }